Skip to content
Snippets Groups Projects
Commit b7060628 authored by Jacob Vosmaer (GitLab)'s avatar Jacob Vosmaer (GitLab)
Browse files

Create one big regular expresion for Rack::Attack

parent 52e903e9
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -9,18 +9,18 @@ paths_to_be_protected = [
"#{Rails.application.config.relative_url_root}/api/#{API::API.version}/session",
"#{Rails.application.config.relative_url_root}/users",
"#{Rails.application.config.relative_url_root}/users/confirmation",
"#{Rails.application.config.relative_url_root}/unsubscribes/*"
"#{Rails.application.config.relative_url_root}/unsubscribes/"
 
]
 
paths_to_be_protected.map! { |path| Regexp.new(path) }
# Create one big regular expression that matches strings starting with any of
# the paths_to_be_protected.
paths_regex = Regexp.union(paths_to_be_protected.map { |path| /\A#{Regexp.escape(path)}/ })
 
unless Rails.env.test?
Rack::Attack.throttle('protected paths', limit: 10, period: 60.seconds) do |req|
if req.post?
paths_paths_to_be_protected.each do |protected_path|
req.ip if req.path =~ protected_path
end
if req.post? && req.path =~ paths_regex
req.ip
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment