Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LG 15241 Bug fix for recaptcha failure not incrementing rate limit for sign in #11703

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

kevinsmaster5
Copy link
Contributor

@kevinsmaster5 kevinsmaster5 commented Jan 3, 2025

🎫 Ticket

Link to the relevant ticket:
LG-15241

🛠 Summary of changes

Swapped the order of rate_limit_password and return process_captcha_failed as was recommended in the bug ticket.

📜 Testing Plan

For testing in local development dial down the sign_in_user_id_per_ip_max_attempts config in application.yml to 5

  • In a private window go to http://localhost:3000
  • Enter correct credentials for an account
  • In "reCAPTCHA score", enter a failing score (e.g. 0.1)
  • Click "Sign in"
  • Repeat Steps 1-4 for 5 times total, closing and reopening a private browsing window every attempt

You should receive the lock out message.

👀 Screenshots

Screenshot 2025-01-06 at 9 28 11 AM (2)

Screenshot 2025-01-06 at 9 30 59 AM (2)

@@ -371,7 +371,7 @@
rate_limited: false,
valid_captcha_result: false,
captcha_validation_performed: true,
bad_password_count: 0,
bad_password_count: 1,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently this piggy-backs on the bad password rate limiter. I wonder if it should have its own.
Probably out of scope for this bug fix.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's a good thought. Another option would be to rename this and the associated session value to be less specific to incorrect password and more generalized to unsuccessful authentication.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you recommend including that change with this bug fix? Relabeling seems pretty minor and an reasonable fix.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel too strongly one way or the other. My initial instinct was that it'd be tricky because it involves renaming a session value and we'd have to worry about migrating existing session values when it goes live, but on second thought it could be okay to not migrate session values if the only consequence is that we'd reset the counters of everyone's session-based rate-limiting.

@kevinsmaster5 kevinsmaster5 marked this pull request as ready for review January 6, 2025 14:35
@@ -3,33 +3,33 @@
RSpec.feature 'Visitor signs in with bad passwords and gets locked out' do
include ActionView::Helpers::DateHelper
let(:user) { create(:user, :fully_registered) }
let(:bad_password) { 'badpassword' }
let(:window) { IdentityConfig.store.max_bad_passwords_window_in_seconds.seconds }
let(:sign_in_failure) { 'badpassword' }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the previous name was a bit more accurate to its purpose.

Suggested change
let(:sign_in_failure) { 'badpassword' }
let(:bad_password) { 'badpassword' }

Comment on lines 249 to 250
max_bad_passwords: 5
max_bad_passwords_window_in_seconds: 60
max_sign_in_failures: 5
max_sign_in_failures_window_in_seconds: 60
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll want to check that we're not configuring this in any deployed environments that'll need to be updated to use the new name, but I think we're using the defaults.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked and it's currently set in int and dev but not in staging or prod. I'll make sure to update those when this PR is merged.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like they're set to the defaults in those environments, so we should probably just remove that configuration override altogether.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed those configs

app-s3-secret: Here's a preview of your changes:
90d89
<   max_bad_passwords: 5
app-s3-secret: Here's a preview of your changes:
110d109
<   max_bad_passwords: '5'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test case that confirms that someone who racks up enough reCAPTCHA failures will hit the session limiter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good! added with cf6c6bd

@kevinsmaster5 kevinsmaster5 force-pushed the kmas-lg-15241-recaptcha-failure-does-not-increment-rate-limit branch from 17c94c1 to cf6c6bd Compare January 8, 2025 20:54
user = create(:user, :fully_registered)
freeze_time do
current_time = Time.zone.now
time_in_hours = distance_of_time_in_words(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: The default lockout period is 1 minute, so "in hours" doesn't seem to apply here. Technically it is configurable and could be hours, but maybe we're better off leaving the unit out altogether.

Suggested change
time_in_hours = distance_of_time_in_words(
rate_limit_time_left = distance_of_time_in_words(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed that to suggested
fee0505

@@ -385,6 +385,37 @@
expect(response).to redirect_to sign_in_security_check_failed_url
end
end

context 'recpatcha lock out' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Typo

Suggested change
context 'recpatcha lock out' do
context 'recaptcha lock out' do

context 'recpatcha lock out' do
let(:locked_at) { Time.zone.now }
let(:sign_in_failure_window) { IdentityConfig.store.max_sign_in_failures_window_in_seconds }
it 'prevents attempt and logs after exceeding maximum rate limit' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are we checking for the "and logs" referenced in this test case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy-pasta mistake. I have removed "and logs"

@kevinsmaster5
Copy link
Contributor Author

DNM - pending team standup discussion 1/13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants