OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Move rate limiting from saas to core
Oliver Güntherc17441482979
diff --git a/config/constants/settings/definition.rb b/config/constants/settings/definition.rbindex a15f4bd4848..68fa08a5f55 100644--- a/config/constants/settings/definition.rb+++ b/config/constants/settings/definition.rb@@ -737,6 +737,10 @@ module Settingsformat: :string,default: nil},+ rate_limiting: {+ default: {},+ description: 'Configure rate limiting for various endpoint rules. See configuration documentation for details.'+ },registration_footer: {default: {'en' => ''diff --git a/config/environments/test.rb b/config/environments/test.rbindex 3f3b52f54ac..c503373bfcb 100644--- a/config/environments/test.rb+++ b/config/environments/test.rb@@ -89,6 +89,9 @@ OpenProject::Application.configure doconfig.cache_store = :file_store, Rails.root.join("tmp", "cache", "paralleltests#{ENV.fetch('TEST_ENV_NUMBER', nil)}")+ # Use in-memory store for testing+ Rack::Attack.cache.store = ActiveSupport::Cache::MemoryStore.new+if ENV['TEST_ENV_NUMBER']assets_cache_path = Rails.root.join("tmp/cache/assets/paralleltests#{ENV['TEST_ENV_NUMBER']}")config.assets.cache = Sprockets::Cache::FileStore.new(assets_cache_path)diff --git a/config/initializers/rack-attack.rb b/config/initializers/rack-attack.rbindex 8fcc7f910dc..0e45713d201 100644--- a/config/initializers/rack-attack.rb+++ b/config/initializers/rack-attack.rb@@ -39,22 +39,8 @@ if OpenProject::Configuration.blacklisted_routes.any?endend-Rack::Attack.throttled_responder = lambda do |request|- match_data = request.env['rack.attack.match_data']- now = match_data[:epoch_time]- retry_after = match_data[:period] - (now % match_data[:period])-- headers = {- 'RateLimit-Limit' => match_data[:limit].to_s,- 'RateLimit-Remaining' => '0',- 'RateLimit-Reset' => (now + (match_data[:period] - (now % match_data[:period]))).to_s- }-- [429, headers, ["Your request has been throttled. Try again at #{retry_after.seconds.from_now}.\n"]]-end--Rack::Attack.throttle("limit-lost-password", limit: 3, period: 1.hour.to_i) do |req|- if req.post? && req.path.end_with?('/account/lost_password')- req.env.dig "rack.request.form_hash", "mail"- end+Rails.application.reloader.to_prepare do+ # In test mode, enable rules and rack-attack using "with_rack_attack:" metadata+ Rack::Attack.enabled = !Rails.env.test?+ OpenProject::RateLimiting.set_defaults!enddiff --git a/docs/installation-and-operations/configuration/README.md b/docs/installation-and-operations/configuration/README.mdindex 1781faf39ae..0b1ac2bfba4 100644--- a/docs/installation-and-operations/configuration/README.md+++ b/docs/installation-and-operations/configuration/README.md@@ -291,7 +291,7 @@ When a filter is defined, synchronization happens directly during seeding for en-### Setting session options+## Setting session options**Delete old sessions for the same user when logging in**@@ -313,13 +313,13 @@ To disable, set the configuration option:OPENPROJECT_DROP__OLD__SESSIONS__ON__LOGOUT="false"```-### Attachments storage+## Attachments storageYou can modify the folder where attachments are stored locally. Use the `attachments_storage_path` configuration variable for that. But ensure that you move the existing paths. To find out the current path on a packaged installation, use `openproject config:get OPENPROJECT_ATTACHMENTS__STORAGE__PATH`.To update the path, use `openproject config:set OPENPROJECT_ATTACHMENTS__STORAGE__PATH="/path/to/new/folder"`. Ensure that this is writable by the `openproject` user. Afterwards issue a restart by `sudo openproject configure`-#### attachment storage type+### attachment storage typeAttachments can be stored using e.g. Amazon S3, In order to set these values through ENV variables, add to the file :@@ -336,7 +336,7 @@ OPENPROJECT_FOG_DIRECTORY="uploads"-### Auth source sso+## Auth source ssoCan be used to automatically login a user defined through a custom header sent by a load balancer or reverse proxy in front of OpenProject, for instance in a Kerberos Single Sign-On (SSO) setup via apache.The header with the given name has to be passed to OpenProject containing the logged in user and the defined global secret as in `$login:$secret`.@@ -362,9 +362,9 @@ auth_source_sso:-### Backups+## Backups-#### backup enabled+### Enable backupsIf enabled, admins (or users with the necessary permission) can download backups of the OpenProject installationvia OpenProject's web interface or via the API.@@ -375,7 +375,7 @@ via OpenProject's web interface or via the API.OPENPROJECT_BACKUP__ENABLED="false"```-#### backup attachment size max sum mb+### Backup attachment size max sum mbPer default the maximum overall size of all attachments must not exceed 1GB for them to be included in the backup. If they are larger only the database dump will be included.@@ -385,7 +385,7 @@ Per default the maximum overall size of all attachments must not exceed 1GB forOPENPROJECT_BACKUP__ATTACHMENT__SIZE__MAX__SUM__MB="8192"```-#### additional configurations for backup+### Additional configurations for backup```yamlOPENPROJECT_BACKUP__DAILY__LIMIT="3"@@ -395,7 +395,7 @@ OPENPROJECT_BACKUP__INITIAL__WAITING__PERIOD="86400"-### BCrypt configuration+## BCrypt configurationOpenProject uses BCrypt to derive and store user passwords securely. BCrypt uses a so-called Cost Factor to derive the computational effort required to derive a password from input.@@ -409,11 +409,11 @@ OPENPROJECT_OVERRIDE__BCRYPT__COST__FACTOR="16"-### Database configuration and SSL+## Database configuration and SSLPlease see [this separate guide](./database/) on how to set a custom database connection string and optionally, require SSL/TTLS verification.-### disable password login+## disable password loginIf you enable this option you have to configure at least one omniauth authenticationprovider to take care of authentication instead of the password login.@@ -429,7 +429,7 @@ OPENPROJECT_DISABLE__PASSWORD__LOGIN="true"-### omniauth direct login provider+## omniauth direct login providerPer default the user may choose the usual password login as well as <u>several</u> omniauth providers on the login page and in the login drop down menu. With this configuration option you can set a specific omniauth provider to be used for direct login. Meaning that the login provider selection is skipped and the configured provider is used directly (non-interactive) instead.@@ -446,7 +446,7 @@ This route is only available when the direct login provider is set.OPENPROJECT_OMNIAUTH__DIRECT__LOGIN__PROVIDER="google"```-### prevent omniauth remapping of existing users+## prevent omniauth remapping of existing usersPer default external authentication providers through OmniAuth (such as SAML or OpenID connect providers) are allowed to take over existingaccounts if the mapped login is already taken. This is usually desirable, if you have e.g., accounts created through LDAP and want these@@ -461,8 +461,7 @@ to create a new account.OPENPROJECT_OAUTH__ALLOW__REMAPPING__OF__EXISTING__USERS="false"```--### Gravatar images+## Gravatar imagesOpenProject uses gravatar images with a `404` fallback by default to render an internal, initials-based avatar.You can override this behavior by setting `gravatar_fallback_image` to a different value to always render Gravatars@@ -491,7 +490,7 @@ rake attachments:copy_to[file]> **NOTE:** that you have to configure the respective storage (i.e. fog) beforehand as described in the previous section. In the case of fog you only have to configure everything under `fog`, however. Don't change `attachments_storage` to `fog` just yet. Instead leave it as `file`. This is because the current attachments storage is used as the source for the migration.-### direct uploads+## direct uploads> **NOTE**: This only works for AWS S3 or S3-compatible storages<sup>\*</sup>. When using fog with another provider this configuration will be `false`. The same goes for when no fog storage is configured, or when the `use_iam_profile` option is used in the fog credentials when using S3.@@ -526,7 +525,7 @@ The default is 21600 seconds, that is 6 hours, which is the maximum expiry timeOPENPROJECT_FOG__DOWNLOAD__URL__EXPIRES__IN="60"```-### force help link+## Force help linkYou can override the default help menu of OpenProject by specifying a `force_help_link` option tothe configuration. This value is used for the href of the help link, and the default dropdown is removed.@@ -537,7 +536,7 @@ the configuration. This value is used for the href of the help link, and the defOPENPROJECT_FORCE__HELP__LINK="https://it-support.example.com"```-### impressum link+## Impressum linkYou can set a impressum link (legal notice) for your OpenProject instance by setting `impressum_link` to an absolute URL.@@ -547,7 +546,7 @@ You can set a impressum link (legal notice) for your OpenProject instance by setOPENPROJECT_IMPRESSUM__LINK="https://impressum.example.com"```-### hidden menu items admin menu+## Hidden menu items admin menuYou can disable specific menu items in the menu sidebar for each main menu (such as Administration and Projects). The configuration can be done through environment variables. You have to define one variable for each menu that shall be hidden.@@ -565,7 +564,21 @@ The following example disables all menu items except 'Users', 'Groups' and 'CustOPENPROJECT_HIDDEN__MENU__ITEMS_ADMIN__MENU="roles types statuses workflows enumerations settings ldap_authentication colors project_types plugins info"```-### blacklisted routes+++## Rate limiting and blocklisting++### Rate limiting++OpenProject provides some rate limiting protections. The default configuration protects against repeated access to authentication credential resets (e.g., lost password functionality).++You can optionally enable additional rules on API rate limiting as follows:++`OPENPROJECT_RATE_LIMITING_API__V3=true`++Additional application-level rate limiting rules will be added in the future. Additionally to these application level rules, use your load balancer / proxying web server to apply individual rate limiting rules using modules such as `ngx_http_limit_req_module` or `mod_security`.++### Blocklisted routesYou can blacklist specific routes@@ -577,7 +590,7 @@ The following example forbid all routes for the second example at the 'hidden meOPENPROJECT_BLACKLISTED__ROUTES="admin/info admin/plugins project_types colors settings admin/enumerations workflows/* statuses types admin/roles"```-### disabled modules+## disabled modulesModules may be disabled through the configuration.Just give a list of the module names either as an array or as a string with values separated by spaces.@@ -588,7 +601,7 @@ Just give a list of the module names either as an array or as a string with valuOPENPROJECT_DISABLED__MODULES="backlogs meetings"```-### local checkout path+## local checkout path*default: "repositories"*@@ -598,7 +611,7 @@ Remote git repositories will be checked out here.note: to be verified, maybe option was removed, not in environement variables list```-### apiv3 enable basic auth+## apiv3 enable basic authYou can control basic auth access to the APIv3 with the following configuration option:@@ -608,7 +621,7 @@ You can control basic auth access to the APIv3 with the following configurationOPENPROJECT_APIV3__ENABLE__BASIC__AUTH="false"```-### global basic auth+## global basic auth*default: none*@@ -628,7 +641,7 @@ default:password: adminpw```-### security badge displayed+## Security Upgrade BadgeOpenProject provides a release indicator (security badge) that will inform administrators of an OpenProject installation on whether new releases or security updates are available for your platform. If enabled, this option will display a badge with your installation status at Administration > Information right next to the release version, and on the home screen. It is only displayed to administrators.@@ -642,7 +655,7 @@ To disable rendering the badge, uncheck the setting at Administration > SysteOPENPROJECT_SECURITY__BADGE__DISPLAYED="false"```-### Cache configuration options+## Cache configuration options* `rails_cache_store`: `memcache` for [memcached](https://www.memcached.org/), `redis` for [Redis cache](https://redis.io/), or `memory_store` (default: `file_store`)* When using `memcached`, the following configuration option is relevant:@@ -654,17 +667,17 @@ OPENPROJECT_SECURITY__BADGE__DISPLAYED="false"* `cache_expires_in`: Expiration time for memcache entries (default: `nil`, no expiry)* `cache_namespace`: Namespace for cache keys, useful when multiple applications use a single memcache server (default: `nil`)-### rails asset host+## rails asset host`rails_asset_host`: A custom host to use to serve static assets such as javascript, CSS, images, etc. (default: `nil`)-### onboarding video url+## onboarding video url`onboarding_video_url`: An URL for the video displayed on the onboarding modal. This is only shown when the user logs in for the first time.*default="[https://player.vimeo.com/video/163426858?autoplay=1](https://player.vimeo.com/video/163426858?autoplay=1)"*-### enterprise fail fast+## enterprise fail fastIf using an Enterprise token there are certain limits that apply. You can configure how these limits are enforced.@@ -691,7 +704,7 @@ enterprise:fail_fast: true```-### show community links+## Show or hide community linksIf you would like to hide the homescreen links to the OpenProject community, you can do this with the following configuration:@@ -701,7 +714,7 @@ If you would like to hide the homescreen links to the OpenProject community, youOPENPROJECT_SHOW__COMMUNITY__LINKS=false```-### web+## Web worker configurationConfiguration of the main ruby web server (currently puma). Sensible *defaults* are provided.@@ -715,9 +728,9 @@ OPENPROJECT_WEB_MAX__THREADS="16"> **NOTE:** Timeouts only are supported when using at least 2 workers.-### Two-factor authentication+## Two-factor authentication-#### 2fa enforced+### 2fa enforcedYou can set the available 2FA strategies and/or enforce or disable 2FA system-wide.diff --git a/lib/open_project/rate_limiting.rb b/lib/open_project/rate_limiting.rbnew file mode 100644index 00000000000..8850649c630--- /dev/null+++ b/lib/open_project/rate_limiting.rb@@ -0,0 +1,48 @@+module OpenProject+ module RateLimiting+ module_function++ def active_rules+ @active_rules ||= []+ end++ def default_rules+ @default_rules ||= [+ LostPassword,+ APIV3+ ]+ end++ def set_defaults!+ Rack::Attack.reset!+ Rack::Attack.clear_configuration+ Rack::Attack.throttled_responder = ->(request) { OpenProject::RateLimiting.throttled_response(request) }++ @active_rules = []+ default_rules.each do |rule|+ apply(rule)+ end+ end++ def apply(rule)+ unless rule < OpenProject::RateLimiting::Base+ raise ArgumentError.new("Rules need to subclass OpenProject::RateLimiting::Base")+ end++ active_rules << rule.new.apply! if rule.enabled?+ end++ ##+ # Try to find a matching rule to respond with+ # or use the default responder+ def throttled_response(request)+ rule = active_rules.find { |r| r.rule_name == request.env['rack.attack.matched'] }++ if rule+ rule.response(request)+ else+ OpenProject::RateLimiting::Base.response(request)+ end+ end+ end+enddiff --git a/lib/open_project/rate_limiting/api_v3.rb b/lib/open_project/rate_limiting/api_v3.rbnew file mode 100644index 00000000000..c184f97fd60--- /dev/null+++ b/lib/open_project/rate_limiting/api_v3.rb@@ -0,0 +1,29 @@+module OpenProject+ module RateLimiting+ class APIV3 < Base+ def self.enabled_by_default?+ false+ end++ def default_limit+ 6 # requests+ end++ def default_period+ 3 # seconds+ end++ protected++ def limit_condition(req)+ if req.post? && req.path.start_with?('/api/v3/') && req.path.end_with?('/form')+ session_id(req.env) || http_auth(req.env)+ end+ end++ def response_body(**)+ API::V3::Errors::ErrorRepresenter.new(ThrottledApiError.new).to_json+ end+ end+ end+enddiff --git a/lib/open_project/rate_limiting/base.rb b/lib/open_project/rate_limiting/base.rbnew file mode 100644index 00000000000..4dd292a1668--- /dev/null+++ b/lib/open_project/rate_limiting/base.rb@@ -0,0 +1,102 @@+module OpenProject+ module RateLimiting+ class Base+ class << self+ def rule_name+ name.demodulize.underscore+ end++ def enabled?+ if settings.key?(:enabled)+ ActiveRecord::Type::Boolean.new.cast(settings[:enabled])+ else+ enabled_by_default?+ end+ end++ def enabled_by_default?+ true+ end++ def settings+ value = OpenProject::Configuration.rate_limiting.with_indifferent_access.fetch(rule_name, {})+ value = { enabled: value } if [true, false].include?(value)+ value+ end+ end++ def apply!+ Rack::Attack.throttle(rule_name, limit:, period:) do |request|+ limit_condition(request)+ end++ self+ end++ delegate :settings, :rule_name, to: :class++ def response(request)+ match_data = request.env['rack.attack.match_data']+ now = match_data[:epoch_time]+ retry_after = match_data[:period] - (now % match_data[:period])++ headers = {+ 'RateLimit-Limit' => match_data[:limit].to_s,+ 'RateLimit-Remaining' => '0',+ 'RateLimit-Reset' => (now + (match_data[:period] - (now % match_data[:period]))).to_s+ }++ body = response_body(request:, now:, retry_after:)+ [429, headers, [body]]+ end++ def response_body(retry_after:, **)+ "Your request has been throttled. Try again at #{retry_after.seconds.from_now}.\n"+ end++ protected++ def limit+ settings[:limit].presence || default_limit+ end++ def period+ settings[:period].presence || default_period+ end++ def session_id(env)+ return if session_cookie_name.nil?++ String(env['HTTP_COOKIE']).scan(/#{session_cookie_name}=([^;]+)/).flatten.first+ end++ def remote_ip(env)+ env['X-Real-IP'].presence || env['Remote-Addr']+ end++ def http_auth(env)+ env["HTTP_AUTHORIZATION"].presence+ end++ def session_cookie_name+ @session_cookie_name ||= OpenProject::Configuration['session_cookie_name']+ end++ def default_enabled?+ false+ end++ def limit_condition(request)+ raise NotImplementedError+ end++ def default_limit+ raise NotImplementedError+ end++ def default_period+ raise NotImplementedError+ end+ end+ end+enddiff --git a/lib/open_project/rate_limiting/lost_password.rb b/lib/open_project/rate_limiting/lost_password.rbnew file mode 100644index 00000000000..59a5dbfd8ea--- /dev/null+++ b/lib/open_project/rate_limiting/lost_password.rb@@ -0,0 +1,31 @@+module OpenProject+ module RateLimiting+ class LostPassword < Base+ class << self+ def response_body(retry_after:, **)+ "Too many requests to reset your password. Try again at #{retry_after.seconds.from_now}.\n"+ end+ end++ def default_limit+ 3+ end++ def default_period+ 1.hour.to_i+ end++ protected++ def default_enabled?+ false+ end++ def limit_condition(req)+ if req.post? && req.path.end_with?('/account/lost_password')+ req.env.dig "rack.request.form_hash", "mail"+ end+ end+ end+ end+enddiff --git a/lib/open_project/rate_limiting/throttled_api_error.rb b/lib/open_project/rate_limiting/throttled_api_error.rbnew file mode 100644index 00000000000..4c8e4bc05d6--- /dev/null+++ b/lib/open_project/rate_limiting/throttled_api_error.rb@@ -0,0 +1,10 @@+module OpenProject::RateLimiting+ class ThrottledApiError < ::API::Errors::ErrorBase+ identifier 'Throttled'+ code 429++ def initialize(*)+ super 'You have reached the request limit for this resource.'+ end+ end+enddiff --git a/spec/requests/rate_limiting/api_v3_rate_limiting_spec.rb b/spec/requests/rate_limiting/api_v3_rate_limiting_spec.rbnew file mode 100644index 00000000000..acc8175ec75--- /dev/null+++ b/spec/requests/rate_limiting/api_v3_rate_limiting_spec.rb@@ -0,0 +1,75 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++require 'spec_helper'++RSpec.describe 'Rate limiting APIv3',+ :with_rack_attack do+ include Rack::Test::Methods+ include API::V3::Utilities::PathHelper++ current_user { create(:admin) }++ context 'when enabled', with_config: { rate_limiting: { api_v3: true } } do+ it 'blocks post request to any form' do+ # Need to reload rules again after config change+ OpenProject::RateLimiting.set_defaults!++ # First requests sets the cookie discriminator+ get '/'++ 6.times do+ post '/api/v3/work_packages/form',+ nil,+ 'CONTENT_TYPE' => 'application/json'++ expect(last_response.status).to eq 200+ end++ post '/api/v3/work_packages/form',+ nil,+ 'CONTENT_TYPE' => 'application/json'+ expect(last_response.status).to eq 429+ end+ end++ context 'when disabled', with_config: { rate_limiting: { api_v3: false } } do+ it 'does not block post request to any form' do+ # Need to reload rules again after config change+ OpenProject::RateLimiting.set_defaults!++ 9.times do+ post '/api/v3/work_packages/form',+ nil,+ 'CONTENT_TYPE' => 'application/json'++ expect(last_response.status).to eq 200+ end+ end+ end+enddiff --git a/spec/requests/rate_limiting/lost_password_rate_limiting_spec.rb b/spec/requests/rate_limiting/lost_password_rate_limiting_spec.rbnew file mode 100644index 00000000000..d8103c8dd3d--- /dev/null+++ b/spec/requests/rate_limiting/lost_password_rate_limiting_spec.rb@@ -0,0 +1,74 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++require 'spec_helper'++RSpec.describe 'Rate limiting lost_password',+ :with_rack_attack,+ type: :rails_request do++ before do+ allow_any_instance_of(ActionController::Base) # rubocop:disable RSpec/AnyInstance+ .to(receive(:protect_against_forgery?))+ .and_return(false)+ end++ it 'blocks the request on the fourth try to the same address' do+ 3.times do+ post account_lost_password_path,+ params: { mail: '[email protected]' },+ headers: { 'Content-Type': 'multipart/form-data' }+ expect(response).to be_successful+ end++ post account_lost_password_path,+ params: { mail: '[email protected]' },+ headers: { 'Content-Type': 'multipart/form-data' }+ expect(response).to have_http_status :too_many_requests+ expect(response.body).to include "Your request has been throttled"++ post account_lost_password_path,+ params: { mail: '[email protected]' },+ headers: { 'Content-Type': 'multipart/form-data' }+ expect(response).to be_successful+ end++ context 'when disabled', with_config: { rate_limiting: { lost_password: false } } do+ it 'does not block post request to any form' do+ # Need to reload rules again after config change+ OpenProject::RateLimiting.set_defaults!++ 4.times do+ post account_lost_password_path,+ params: { mail: '[email protected]' },+ headers: { 'Content-Type': 'multipart/form-data' }+ expect(response).to be_successful+ end+ end+ end+enddiff --git a/spec/support/shared/with_rack_attack.rb b/spec/support/shared/with_rack_attack.rbnew file mode 100644index 00000000000..32ff0560f3e--- /dev/null+++ b/spec/support/shared/with_rack_attack.rb@@ -0,0 +1,36 @@+# OpenProject is an open source project management software.+# Copyright (C) 2010-2022 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.++RSpec.configure do |config|+ config.around :example, :with_rack_attack do |example|+ Rack::Attack.enabled = true+ OpenProject::RateLimiting.set_defaults!++ example.run+ ensure+ Rack::Attack.enabled = false+ end+end