Skip to content

fix(security): harden account password-change and session-invalidation handling - #42934

Merged
sha174n merged 6 commits into
masterfrom
fix-account-session-hardening
Aug 18, 2026
Merged

sha174n merged 6 commits into
masterfrom
fix-account-session-hardening

Conversation

@rusackas

@rusackas rusackas commented Aug 9, 2026

Copy link
Copy Markdown
Member

SUMMARY

A few related fixes to account password-change and session handling, bundled together since they touch overlapping code paths:

  • CurrentUserRestApi.update_me now requires a current_password field (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.
  • Fixed a bug in the same handler where the plaintext password value could overwrite the just-computed hash before the record was persisted, since both lived in the same attributes dict passed to the DAO's update call.
  • Password changes and resets (self-service and admin-initiated) now stamp the existing session-invalidation epoch for the account, so other active sessions stop working after a password change instead of remaining valid indefinitely.
  • Added an explicit admin action (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/put used to commit the FAB user write, then sync the user's Subject row in a second, separate commit — so a failure in that second commit could leave an orphaned user with no matching Subject row. The sync now happens in pre_add/pre_update, which FAB calls before the commit its own datamodel.add/edit issues, so both writes ride the same transaction and roll back together on failure.

TESTING INSTRUCTIONS

pytest tests/unit_tests/views/test_current_user_api.py
pytest tests/unit_tests/security/test_password_change_session_invalidation.py
pytest tests/unit_tests/security/test_superset_user_api_subject_sync.py

Manual: as any user, PUT /api/v1/me/ with a password and no current_password should now be rejected; with the correct current_password it should succeed and any other active session for that account should be invalidated. As an admin, DELETE /api/v1/security/users/<id>/sessions should end that user's sessions without changing their active status.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

rusackas and others added 3 commits August 9, 2026 08:04
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]>
@bito-code-review

bito-code-review Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #79b214

Actionable Suggestions - 0
Additional Suggestions - 1
  • superset/security/session_invalidation.py - 1
    • Missing Unit Tests for New Function · Line 190-204
      The new function has no dedicated tests despite being called from multiple entry points (`reset_password` at line 515, `terminate_sessions` at line 1615, user API at line 82). Add tests following the patterns in `test_session_invalidation.py` (lines 173-214) to verify it correctly forwards to `invalidate_user_sessions` with `db.session.connection()`.
Review Details
  • Files reviewed - 7 · Commit Range: 3d6a3ee..e44d5d4
    • 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

AI Code Review powered by Bito Logo

@github-actions github-actions Bot added api Related to the REST API preset-io labels Aug 9, 2026
@dosubot dosubot Bot added authentication Related to authentication change:backend Requires changing the backend labels Aug 9, 2026
@codecov

codecov Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 45.45455% with 30 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.57%. Comparing base (e177773) to head (7f3e6c3).
⚠️ Report is 88 commits behind head on master.

Files with missing lines Patch % Lines
superset/security/manager.py 42.42% 19 Missing ⚠️
superset/views/users/api.py 30.00% 6 Missing and 1 partial ⚠️
superset/security/session_invalidation.py 50.00% 2 Missing ⚠️
superset/views/users/schemas.py 75.00% 1 Missing and 1 partial ⚠️
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     
Flag Coverage Δ
hive 38.13% <32.72%> (-0.05%) ⬇️
mysql 57.81% <45.45%> (-0.10%) ⬇️
postgres 57.84% <45.45%> (-0.10%) ⬇️
presto 40.07% <32.72%> (-0.06%) ⬇️
python 59.23% <45.45%> (-0.11%) ⬇️
sqlite 57.48% <45.45%> (-0.10%) ⬇️
unit 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread superset/views/users/api.py Resolved
…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]>
@rusackas rusackas added the merge-if-green If approved and tests are green, please go ahead and merge it for me label Aug 9, 2026
@bito-code-review

bito-code-review Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #5203d4

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: e44d5d4..48c7504
    • superset/security/session_invalidation.py
    • superset/views/users/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

AI Code Review powered by Bito Logo

@sha174n sha174n left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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:

  1. 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.

  2. 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.

  3. 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]>
@rusackas

Copy link
Copy Markdown
Member Author

Thanks @sha174n, appreciate the close read. Fixed 1 and 2: SupersetUserApi.pre_update now stamps the epoch when data.get("password") is set, and a falsy password gets popped before it reaches UserDAO.update's setattr loop.

On 3, I'm inclined to leave it as is. Most users don't have a user_attribute row until this (or another lazy attribute) creates one, so a pre-check SELECT would add a round trip to the common first-stamp case just to save one in the rarer already-fresh race. Feels like a wash.

@netlify

netlify Bot commented Aug 11, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 4d47925
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a7dfe529d06ba00089460ae
😎 Deploy Preview https://deploy-preview-42934--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@bito-code-review

bito-code-review Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #88d60e

Actionable Suggestions - 0
Review Details
  • Files reviewed - 4 · Commit Range: 48c7504..f4cebc2
    • superset/security/manager.py
    • superset/views/users/api.py
    • tests/unit_tests/security/test_password_change_session_invalidation.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

AI Code Review powered by Bito Logo

@rusackas
rusackas force-pushed the fix-account-session-hardening branch from 4d47925 to 7f3e6c3 Compare August 18, 2026 04:16

@bito-code-review bito-code-review Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review Agent Run #e841f8

Actionable Suggestions - 1
  • superset/security/session_invalidation.py - 1
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

AI Code Review powered by Bito Logo

@sha174n

sha174n commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Rechecked the latest push — the admin-path epoch stamp (SupersetUserApi.pre_update) and the falsy-password drop in CurrentUserRestApi.pre_update both look good, and the current_password proof + no-password-yet exemption read cleanly. Nicely tested too.

One non-blocking behavior note: _login_at is only written at login and isn't refreshed after a self password change, so when a user changes their own password the epoch is stamped to now and the before_request hook then logs the actor out on the next request — not just their other sessions. That's fail-safe (it over-logs-out rather than under), so it's a UX call rather than a correctness issue; forcing re-login after a password change is a defensible posture. If you'd prefer to keep the acting session alive and only revoke the siblings, note that the epoch is ceil(now), so the current session's _login_at would need to be re-stamped to at least the epoch value — a plain utcnow() would still compare as invalidated. Fine to leave for a follow-up.

@sha174n sha174n left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving — the requested admin-path session invalidation and falsy-password handling are in and well-tested. Left one non-blocking self-relogin note above.

@sha174n
sha174n merged commit fd063d1 into master Aug 18, 2026
78 of 79 checks passed
@sha174n
sha174n deleted the fix-account-session-hardening branch August 18, 2026 16:40
rusackas added a commit that referenced this pull request Sep 28, 2026
…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]>
rusackas added a commit that referenced this pull request Sep 30, 2026
…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]>
villebro added a commit that referenced this pull request Oct 9, 2026
…(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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Related to the REST API authentication Related to authentication change:backend Requires changing the backend merge-if-green If approved and tests are green, please go ahead and merge it for me preset-io size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants