-
Notifications
You must be signed in to change notification settings - Fork 8
security: auth bypasses, constant-time comparisons, MFA password re-auth, OAuth revocation #1519
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
Open
dgilperez
wants to merge
10
commits into
we-promise:main
Choose a base branch
from
dgilperez:security/pr3-auth-bypasses
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+288
−23
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
eaaa962
security(api): reject revoked OAuth access tokens
dgilperez 70cafa8
fix(security): use constant-time comparison for API keys (FIX-14)
dgilperez 4bdb6d2
fix(security): use constant-time comparison for MFA backup codes (FIX…
dgilperez 21d2f8f
fix(security): reject deactivated users on API login (FIX-02)
dgilperez 4050623
fix(security): block API signup when registration is closed (FIX-03)
dgilperez 610533b
fix(security): reject deactivated users on token refresh (FIX-04)
dgilperez 2c3a5ea
fix(security): honor AuthConfig.local_login_enabled? on API login (F-01)
dgilperez 17b36fc
fix(security): require password re-auth for MFA enable/disable (F-11)
dgilperez ce6f4f9
fix(security): address CodeRabbit review
dgilperez e9404a4
fix(security): block SSO-only users from MFA flow server-side
dgilperez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -818,4 +818,74 @@ class Api::V1::AuthControllerTest < ActionDispatch::IntegrationTest | |
| assert_equal "AI is not available for your account", response_data["error"] | ||
| assert_not user.reload.ai_enabled | ||
| end | ||
|
|
||
| # Security tests — ported from origin/security/pentest-2026-03-02 | ||
|
|
||
| test "signup is blocked when registration is closed on self-hosted" do | ||
| Rails.application.config.app_mode.stubs(:self_hosted?).returns(true) | ||
| Setting.stubs(:onboarding_state).returns("closed") | ||
|
|
||
| post "/api/v1/auth/signup", params: { | ||
| user: { email: "[email protected]", password: "SecurePass123!", first_name: "New", last_name: "User" }, | ||
| device: @device_info | ||
| } | ||
|
|
||
| assert_response :forbidden | ||
| assert_equal "Registration is currently closed", JSON.parse(response.body)["error"] | ||
| end | ||
|
|
||
| test "login is blocked when local login disabled via AuthConfig" do | ||
| AuthConfig.stubs(:local_login_enabled?).returns(false) | ||
|
|
||
| post "/api/v1/auth/login", params: { | ||
| email: users(:family_admin).email, | ||
| password: user_password_test, | ||
| device: @device_info | ||
| } | ||
|
|
||
| assert_response :forbidden | ||
| assert_equal "Local login is disabled. Please use SSO.", JSON.parse(response.body)["error"] | ||
| end | ||
|
|
||
| test "refresh token is rejected for deactivated user and new token is revoked" do | ||
| user = users(:family_member) | ||
| device = user.mobile_devices.create!(@device_info) | ||
|
|
||
| initial_token = Doorkeeper::AccessToken.create!( | ||
| application: @shared_app, | ||
| resource_owner_id: user.id, | ||
| mobile_device_id: device.id, | ||
| expires_in: 30.days.to_i, | ||
| scopes: "read_write", | ||
| use_refresh_token: true | ||
| ) | ||
|
|
||
| user.update!(active: false) | ||
|
|
||
| post "/api/v1/auth/refresh", params: { | ||
| refresh_token: initial_token.refresh_token, | ||
| device: @device_info | ||
| } | ||
|
|
||
| assert_response :unauthorized | ||
| assert_equal "Account has been deactivated", JSON.parse(response.body)["error"] | ||
|
|
||
| # All tokens for this user must be revoked (including any newly issued one) | ||
| assert Doorkeeper::AccessToken.where(resource_owner_id: user.id).all?(&:revoked?), | ||
| "Expected all tokens to be revoked for deactivated user" | ||
| end | ||
|
|
||
| test "login is rejected for deactivated user" do | ||
| user = users(:family_member) | ||
| user.update!(active: false) | ||
|
|
||
| post "/api/v1/auth/login", params: { | ||
| email: user.email, | ||
| password: user_password_test, | ||
| device: @device_info | ||
| } | ||
|
|
||
| assert_response :unauthorized | ||
| assert_equal "Account has been deactivated", JSON.parse(response.body)["error"] | ||
| end | ||
| end | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: we-promise/sure
Length of output: 6401
🏁 Script executed:
Repository: we-promise/sure
Length of output: 1195
🏁 Script executed:
Repository: we-promise/sure
Length of output: 972
Add parallel keys to all supported locale files for the securities section.
The two new keys
disable_mfa_password_labelanddisable_mfa_password_placeholderundersecurities.showinconfig/locales/views/settings/en.ymlmust be added to the corresponding sections in all other locale files (ca, de, es, fr, nb, nl, pl, pt-BR, ro, tr, zh-CN, zh-TW) to maintain consistency. The securities section is already translated in these locales, so missing these keys will cause the password confirmation fields to display in English when viewed in other languages.🤖 Prompt for AI Agents