# Stale sessions after permission changes

Permission, role or password updates that write the DB but never invalidate existing sessions or cached roles

_Area: Web authentication and account takeover. Seen in 3 disclosed reports; latest 2026-10-22. Updated 2026-12-05._

## How it works
Authorization state (role, permissions, password) is copied into a session or token at login and read back from that copy on every request. When an update endpoint changes the DB but not the session, the old copy keeps granting the old rights. The broken assumption is that "the DB is the source of truth" — in practice the session is, until it expires. A second shape: a revocation call that reports success but targets the wrong column, so nothing is deleted [E1](https://bugbountylibrary.com/r/ghsa%3AGHSA-xw6w-gcfp-cf8m.md).

## Where it shows up
- Session populated at login only (`set_session`), with no `before_request` refresh from the DB [E2](https://bugbountylibrary.com/r/ghsa%3AGHSA-jq7h-wrvp-3rgx.md)[E3](https://bugbountylibrary.com/r/ghsa%3AGHSA-889w-m37p-88m5.md).
- `login_required` / auth decorators reading `role`/`perms` from the session rather than querying the user [E2](https://bugbountylibrary.com/r/ghsa%3AGHSA-jq7h-wrvp-3rgx.md).
- Admin endpoints that write permissions or passwords and then just `return` [E2](https://bugbountylibrary.com/r/ghsa%3AGHSA-jq7h-wrvp-3rgx.md)[E3](https://bugbountylibrary.com/r/ghsa%3AGHSA-889w-m37p-88m5.md).
- A generic RPC dispatcher (`/api/<func>`) that calls model methods directly, bypassing the WebUI route where the side-effects live [E3](https://bugbountylibrary.com/r/ghsa%3AGHSA-889w-m37p-88m5.md).
- Proxy models overriding `pk` to return a foreign identity (e.g. `user_id`) while the concrete model keys on another column [E1](https://bugbountylibrary.com/r/ghsa%3AGHSA-xw6w-gcfp-cf8m.md).
- Inherited `delete()`/`update()`/`refresh()` on such a proxy [E1](https://bugbountylibrary.com/r/ghsa%3AGHSA-xw6w-gcfp-cf8m.md).

## How to review
Find every route that mutates role, permissions or password, and confirm each one invalidates the affected user's sessions (or that auth reads live DB state). The invariant: after any privilege or credential change, no pre-existing session or token can still exercise the old rights. For revocation code, check the DELETE/UPDATE actually matches rows: confirm the pk used to build the query is the concrete model's real key column, and that the call raises or reports failure when zero rows match [E1](https://bugbountylibrary.com/r/ghsa%3AGHSA-xw6w-gcfp-cf8m.md). Enumerate routes from the served OpenAPI spec, not just the WebUI handlers [E2](https://bugbountylibrary.com/r/ghsa%3AGHSA-jq7h-wrvp-3rgx.md).

## How finders spotted it
- Noticed `TokenProxy` overrides `pk` to return `user_id` while `Token` keys on `key`; traced `Model.delete()`'s pk-based query and confirmed the mismatched DELETE with a query-capturing PoC plus a concrete-model control [E1](https://bugbountylibrary.com/r/ghsa%3AGHSA-xw6w-gcfp-cf8m.md).
- Saw a prior session-invalidation fix touched only three WebUI form handlers; traced `set_session` and the decorators reading role from session, then checked the API module where the same DB writes happen without invalidation, and confirmed the functions are exported over `/api` and listed in the OpenAPI spec [E2](https://bugbountylibrary.com/r/ghsa%3AGHSA-jq7h-wrvp-3rgx.md).
- Grepped `set_user_permission`, found only one call site paired with `clear_all_user_sessions`, and noticed the RPC dispatcher bypasses that route; traced session population (login only, no refresh) and confirmed with an in-process test client [E3](https://bugbountylibrary.com/r/ghsa%3AGHSA-889w-m37p-88m5.md).

## Variants seen
- Proxy-model pk override making revocation a silent no-op [E1](https://bugbountylibrary.com/r/ghsa%3AGHSA-xw6w-gcfp-cf8m.md).
- REST API permission/password change leaving the Flask session intact [E2](https://bugbountylibrary.com/r/ghsa%3AGHSA-jq7h-wrvp-3rgx.md).
- RPC dispatcher bypassing the WebUI route that performed invalidation [E3](https://bugbountylibrary.com/r/ghsa%3AGHSA-889w-m37p-88m5.md).

## Why fixes fail
A session-invalidation fix landed in one blueprint's handlers only; the same DB mutations reachable via `/api/<func>` were left unpatched [E2](https://bugbountylibrary.com/r/ghsa%3AGHSA-jq7h-wrvp-3rgx.md)[E3](https://bugbountylibrary.com/r/ghsa%3AGHSA-889w-m37p-88m5.md).

## Impact and severity
Demoted or rotated users keep admin rights for up to ~31 days [E2](https://bugbountylibrary.com/r/ghsa%3AGHSA-jq7h-wrvp-3rgx.md)[E3](https://bugbountylibrary.com/r/ghsa%3AGHSA-889w-m37p-88m5.md). Stale admin session retained a config-write sink (`reconnect.script`) enabling command execution when chained with another weakness [E2](https://bugbountylibrary.com/r/ghsa%3AGHSA-jq7h-wrvp-3rgx.md). Silent revocation failure leaves tokens valid indefinitely [E1](https://bugbountylibrary.com/r/ghsa%3AGHSA-xw6w-gcfp-cf8m.md).

## Seen in real software
Open-source packages and projects, and products, where this pattern was found. If the target runs one, compare the version it runs with the fix.
- **djangorestframework (pip)** >= 3.12.0, < 3.18.2, fixed in 3.18.2: Django REST framework: TokenProxy.delete() reports success and revokes nothing (CVE-2026-114137). Report: https://bugbountylibrary.com/r/ghsa%3AGHSA-xw6w-gcfp-cf8m.md. Fix: https://github.com/encode/django-rest-framework/commit/af3fabfd517307fbc5d500fba1ab8f6e25f220b0
- **pyload-ng (pip)** <= 0.5.0b3.dev101, no fix yet: pyLoad: Privilege revocation and password change through the REST API do not invalidate the user's session. Report: https://bugbountylibrary.com/r/ghsa%3AGHSA-jq7h-wrvp-3rgx.md. Fix: https://github.com/pyload/pyload/commit/3e726ba271a6b1015e3a0ea6dc7e46a8f71a62ad
- **pyload-ng (pip)** >= 0.5.0b3.dev98, <= 0.5.0b3.dev101, no fix yet: pyLoad: Api.set_user_permission never invalidates the target's session. Report: https://bugbountylibrary.com/r/ghsa%3AGHSA-889w-m37p-88m5.md. Fix: https://github.com/pyload/pyload/commit/3e726ba271a6b1015e3a0ea6dc7e46a8f71a62ad

## Evidence
- E1: https://bugbountylibrary.com/r/ghsa%3AGHSA-xw6w-gcfp-cf8m.md
- E2: https://bugbountylibrary.com/r/ghsa%3AGHSA-jq7h-wrvp-3rgx.md
- E3: https://bugbountylibrary.com/r/ghsa%3AGHSA-889w-m37p-88m5.md
