Repository navigation
fix(security): harden account password-change and session-invalidation handling - #42934
Conversation
CurrentUserRestApi.update_me accepted a new password with no proof of the existing one, and pre_update's plaintext password briefly overwrote the hash it had just computed before UserDAO.update persisted it, since both lived in the same dict passed through as DAO attributes. CurrentUserPutSchema now carries a current_password field, required whenever password is present; pre_update verifies it against the stored hash (skipped only for accounts with no password set yet), pops both password and current_password out of the attributes dict once it has used them, and stamps the session-invalidation epoch so a password change also ends any other outstanding session for the account. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…ct atomically SupersetSecurityManager.reset_password (used by both the self-service and admin-initiated reset flows) now stamps the session-invalidation epoch for the target user after the password is reset, so outstanding sessions for the account stop working. SupersetUserApi gains a terminate_sessions action (DELETE /api/v1/security/users/<pk>/sessions, gated the same way as the existing put action) so an admin can end a specific user's sessions directly, without disabling the account. SupersetUserApi.post/put also used to commit the FAB user write, then sync the corresponding Subject row in a second, separate commit -- so a failure in that second commit left an orphaned user with no matching Subject row. The sync now happens in pre_add/pre_update, which FAB calls before the commit that datamodel.add/edit issues, so both writes ride the same transaction and roll back together on failure. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Code Review Agent Run #79b214Actionable Suggestions - 0Additional Suggestions - 1
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #42934 +/- ##
==========================================
- Coverage 66.65% 66.57% -0.08%
==========================================
Files 2866 2869 +3
Lines 162911 163408 +497
Branches 37530 37614 +84
==========================================
+ Hits 108584 108797 +213
- Misses 52202 52471 +269
- Partials 2125 2140 +15
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…h monotonic check_password_hash was reached with item.password == None for passwordless accounts when a non-empty current_password was supplied, raising an unhandled error instead of the intended validation path. The session-invalidation upsert also did a blind overwrite that a slower transaction with an older timestamp could apply after a newer one committed, regressing the epoch; the update is now guarded so it only ever advances the stored value. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Code Review Agent Run #5203d4Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
sha174n
left a comment
There was a problem hiding this comment.
Nice, focused hardening. The plaintext-drop in pre_update and the Subject-sync move into pre_add/pre_update both read cleanly, and the monotonicity guard on the epoch stamp does the right thing under out-of-order writers. A few notes:
-
SupersetUserApi.pre_update hashes an incoming password (via super().pre_update) but does not stamp the invalidation epoch, so a password change made through PUT /api/v1/security/users/ leaves the target's existing sessions active, unlike the self-service PUT /api/v1/me/ path and the two reset views. Since the summary calls out admin-initiated changes as covered, it would be worth stamping here too when data.get("password") is set, mirroring CurrentUserRestApi.pre_update.
-
In CurrentUserRestApi.pre_update, a falsy password (for example an empty string) skips the hashing block but the key stays in the dict handed to UserDAO.update, which setattrs it onto the model. With complexity validation off by default the schema lets an empty value through, so popping or ignoring a falsy password there would tidy that up.
-
Minor: with the new guard, _stamp_existing() returns 0 both when no row exists and when the stored epoch is already newer, so the already-newer case falls through to the INSERT and relies on the unique-constraint catch to no-op. Correct, but it does a doomed insert on every already-fresh stamp; distinguishing the two cases first would avoid it.
Controls otherwise look good: the proof check short-circuits on item.password so there is no error on first-password setup, the /me/ no-password exemption is scoped to the caller's own account, and terminate_sessions is gated on the same permission as editing the user and leaves active unchanged.
… password key - SupersetUserApi.pre_update now invalidates the target user's other sessions when an admin changes their password via PUT /api/v1/security/users/<pk>, matching the self-service /me/ path and the two password-reset views. - CurrentUserRestApi.pre_update now drops a falsy "password" key from data instead of leaving it for UserDAO.update's setattr loop, which would otherwise blank the stored hash if password-complexity validation is disabled. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Thanks @sha174n, appreciate the close read. Fixed 1 and 2: On 3, I'm inclined to leave it as is. Most users don't have a |
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Code Review Agent Run #88d60eActionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
4d47925 to
7f3e6c3
Compare
There was a problem hiding this comment.
Code Review Agent Run #e841f8
Actionable Suggestions - 1
-
superset/security/session_invalidation.py - 1
- Missing tests for new public API · Line 201-215
Review Details
-
Files reviewed - 7 · Commit Range:
c9e2287..7f3e6c3- superset/security/manager.py
- superset/security/session_invalidation.py
- superset/views/users/api.py
- superset/views/users/schemas.py
- tests/unit_tests/security/test_password_change_session_invalidation.py
- tests/unit_tests/security/test_superset_user_api_subject_sync.py
- tests/unit_tests/views/test_current_user_api.py
-
Files skipped - 0
-
Tools
- MyPy (Static Code Analysis) - ✔︎ Successful
- Astral Ruff (Static Code Analysis) - ✔︎ Successful
- Whispers (Secret Scanner) - ✔︎ Successful
- Detect-secrets (Secret Scanner) - ✔︎ Successful
Bito Usage Guide
Commands
Type the following command in the pull request comment and save the comment.
-
/review- Manually triggers a full AI review. -
/pause- Pauses automatic reviews on this pull request. -
/resume- Resumes automatic reviews. -
/resolve- Marks all Bito-posted review comments as resolved. -
/abort- Cancels all in-progress reviews.
Refer to the documentation for additional commands.
Configuration
This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].
Documentation & Help
|
Rechecked the latest push — the admin-path epoch stamp ( One non-blocking behavior note: |
sha174n
left a comment
There was a problem hiding this comment.
Approving — the requested admin-path session invalidation and falsy-password handling are in and well-tested. Left one non-blocking self-relogin note above.
…rd resets into the SPA The Flask-AppBuilder server-rendered ResetPasswordView and ResetMyPasswordView (/resetpassword/form, /resetmypassword/form) survived the SPA migration and were still reachable in 6.0 (#37700). Rather than gating them behind a config flag (#37773), remove them for good and make the SPA cover every flow they served: - register_views() intercepts add_view_no_menu for the duration of FAB's own registration so the two views never reach the URL map; the "Reset Password" / "Reset my password" launchers on the FAB user pages are hidden and answer 404 instead of raising BuildError; and sync_role_definitions stops assigning the stale ResetPasswordView, ResetMyPasswordView and UserDBModelView launcher permissions that an upgraded metadata database still carries. - The Users list edit modal gains optional "New password" / "Confirm new password" fields wired to PUT /api/v1/security/users/<id>, the admin path that never required a current password. PUT /api/v1/me/ keeps requiring current_password for self-service changes. - The profile page's "Reset my password" modal now sends current_password, which /api/v1/me/ has required since #42934, so the SPA self-service flow works again. - The forced-password-change hook (ENABLE_FORCE_PASSWORD_CHANGE) redirects to /user_info/ instead of the removed view, exempting the profile page, the current-user API and the CSRF endpoint so the page is usable, and a successful self-service change through /api/v1/me/ clears password_must_change in the same unit of work as the new hash. Fixes #37700 Supersedes #37773 Co-authored-by: jayvenn21 <[email protected]> Co-Authored-By: Evan Rusackas <[email protected]> Co-Authored-By: Claude Fable 5.1 <[email protected]>
…rd resets into the SPA The Flask-AppBuilder server-rendered ResetPasswordView and ResetMyPasswordView (/resetpassword/form, /resetmypassword/form) survived the SPA migration and were still reachable in 6.0 (#37700). Rather than gating them behind a config flag (#37773), remove them for good and make the SPA cover every flow they served: - register_views() intercepts add_view_no_menu for the duration of FAB's own registration so the two views never reach the URL map; the "Reset Password" / "Reset my password" launchers on the FAB user pages are hidden and answer 404 instead of raising BuildError; and sync_role_definitions stops assigning the stale ResetPasswordView, ResetMyPasswordView and UserDBModelView launcher permissions that an upgraded metadata database still carries. - The Users list edit modal gains optional "New password" / "Confirm new password" fields wired to PUT /api/v1/security/users/<id>, the admin path that never required a current password. PUT /api/v1/me/ keeps requiring current_password for self-service changes. - The profile page's "Reset my password" modal now sends current_password, which /api/v1/me/ has required since #42934, so the SPA self-service flow works again. - The forced-password-change hook (ENABLE_FORCE_PASSWORD_CHANGE) redirects to /user_info/ instead of the removed view, exempting the profile page, the current-user API and the CSRF endpoint so the page is usable, and a successful self-service change through /api/v1/me/ clears password_must_change in the same unit of work as the new hash. Fixes #37700 Supersedes #37773 Co-authored-by: jayvenn21 <[email protected]> Co-Authored-By: Evan Rusackas <[email protected]> Co-Authored-By: Claude Fable 5.1 <[email protected]>
…(partial backport of #44626) On 7.0, PUT /api/v1/me/ requires current_password whenever a password is set (#42934), but the SPA "Reset my password" modal never sends it, so self-service password changes always fail with 400 -- a regression from 6.1. This backports only the self-service part of #44626 (d2fb52a): - the modal gains a "Current password" field and sends it when filled; - CurrentUserPutSchema no longer requires current_password at schema level; CurrentUserRestApi.pre_update already requires and verifies it for every account that has a stored password, while one without (e.g. provisioned by an external auth backend) can set its first password; - a successful self-service change clears a pending forced password change; clear_password_must_change no longer commits on its own, so it rides the /me unit of work, and reset_password commits after it. Not backported: removing the legacy FAB ResetPassword/ResetMyPassword views and their permissions, redirecting forced changes to the SPA, and the admin user modal rework.
SUMMARY
A few related fixes to account password-change and session handling, bundled together since they touch overlapping code paths:
CurrentUserRestApi.update_menow requires acurrent_passwordfield (verified against the account's existing password) whenever a password change is requested, rather than accepting a new password with no proof of the old one. Skipped only for accounts that have no password set yet.DELETE /api/v1/security/users/<pk>/sessions) to terminate a specific user's sessions without disabling their account — there wasn't previously a direct way to do this short of deactivating the user.SupersetUserApi.post/putused to commit the FAB user write, then sync the user'sSubjectrow in a second, separate commit — so a failure in that second commit could leave an orphaned user with no matchingSubjectrow. The sync now happens inpre_add/pre_update, which FAB calls before the commit its owndatamodel.add/editissues, so both writes ride the same transaction and roll back together on failure.TESTING INSTRUCTIONS
Manual: as any user,
PUT /api/v1/me/with apasswordand nocurrent_passwordshould now be rejected; with the correctcurrent_passwordit should succeed and any other active session for that account should be invalidated. As an admin,DELETE /api/v1/security/users/<id>/sessionsshould end that user's sessions without changing theiractivestatus.ADDITIONAL INFORMATION