-
Notifications
You must be signed in to change notification settings - Fork 28
security: session & cookie hardening (fixation, TTL, MFA rate limit, impersonation auth) #1518
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
base: main
Are you sure you want to change the base?
Changes from 7 commits
46d28e1
a3a678c
c56af54
9b810b6
457970a
32a0534
d8c6520
2e7b76c
ad61c1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,8 +29,30 @@ def verify | |
| def verify_code | ||
| @user = User.find_by(id: session[:mfa_user_id]) | ||
|
|
||
| # Rate limit: max 5 attempts, then force re-login (PT-003) | ||
| session[:mfa_attempts] = (session[:mfa_attempts] || 0) + 1 | ||
| if session[:mfa_attempts] > 5 | ||
| session.delete(:mfa_user_id) | ||
| session.delete(:mfa_attempts) | ||
| session.delete(:mfa_started_at) | ||
| redirect_to new_session_path, alert: t(".too_many_attempts", default: "Too many attempts. Please sign in again.") | ||
| return | ||
| end | ||
|
|
||
| # TTL: MFA flow expires after 5 minutes (PT-003) | ||
| if session[:mfa_started_at].present? && Time.current - Time.parse(session[:mfa_started_at].to_s) > 5.minutes | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The timeout check only executes when Useful? React with 👍 / 👎. |
||
| session.delete(:mfa_user_id) | ||
| session.delete(:mfa_attempts) | ||
| session.delete(:mfa_started_at) | ||
| redirect_to new_session_path, alert: t(".session_expired", default: "MFA session expired. Please sign in again.") | ||
| return | ||
| end | ||
|
|
||
| if @user&.verify_otp?(params[:code]) | ||
| session.delete(:mfa_user_id) | ||
| session.delete(:mfa_attempts) | ||
| session.delete(:mfa_started_at) | ||
| reset_session # Prevent session fixation (PT-003) | ||
| @session = create_session_for(@user) | ||
| flash[:notice] = t("invitations.accept_choice.joined_household") if accept_pending_invitation_for(@user) | ||
| redirect_to root_path | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,9 +63,12 @@ def create | |
| if user.otp_required? | ||
| log_super_admin_override_login(user) | ||
| session[:mfa_user_id] = user.id | ||
| session[:mfa_started_at] = Time.current.iso8601 | ||
| session[:mfa_attempts] = 0 | ||
| redirect_to verify_mfa_path | ||
| else | ||
| log_super_admin_override_login(user) | ||
| reset_session # Prevent session fixation (FIX-01) | ||
| @session = create_session_for(user) | ||
| flash[:notice] = t("invitations.accept_choice.joined_household") if accept_pending_invitation_for(user) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎. |
||
| redirect_to root_path | ||
|
|
@@ -183,6 +186,7 @@ def openid_connect | |
| session[:mfa_user_id] = user.id | ||
| redirect_to verify_mfa_path | ||
| else | ||
| reset_session # Prevent session fixation (FIX-01) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎. |
||
| @session = create_session_for(user) | ||
| flash[:notice] = t("invitations.accept_choice.joined_household") if accept_pending_invitation_for(user) | ||
| redirect_to root_path | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.