Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/initializers/rack_attack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def headers
# increments the count), so requests below the limit are not blocked until
# they hit the limit. At that point, `filter` will return true and block.
user = req.params.fetch('user', {})
email = user['email'].to_s
email = user['email'].to_s.downcase.strip
email_fingerprint = Pii::Fingerprinter.fingerprint(email) if email.present?
email_and_ip = "#{email_fingerprint}-#{req.remote_ip}"
maxretry = Figaro.env.logins_per_email_and_ip_limit.to_i
Expand Down
6 changes: 3 additions & 3 deletions spec/requests/rack_attack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,15 @@
end
end

context 'when the number of logins per email and ip is higher than the limit per period' do
context 'when number of logins per stripped/downcased email + ip is higher than limit per period' do
it 'throttles with a custom response' do
analytics = instance_double(Analytics)
allow(Analytics).to receive(:new).and_return(analytics)
allow(analytics).to receive(:track_event)

(logins_per_email_and_ip_limit + 1).times do
(logins_per_email_and_ip_limit + 1).times do |index|
post '/', params: {
user: { email: 'test@example.com' },
user: { email: index % 2 == 0 ? 'test@example.com' : ' test@EXAMPLE.com ' },
}, headers: { REMOTE_ADDR: '1.2.3.4' }
end

Expand Down