0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-04 10:39:43 +08:00
discourse/lib/auth
Alan Guo Xiang Tan 6b348f8f6a
SECURITY: Bind shared session key to auth token and enforce user gates (#41610)
This PR binds the shared session key to the session's `UserAuthToken` so
it can no longer be replayed after the session is revoked.

When the `long_polling_base_url` site setting points to an external
origin, the auth cookie is not sent with message_bus requests, so each
authenticated page render mints a shared session key: a random token
that Discourse stores in Redis pointing at the user's id, embeds in the
page, and the client replays on the `X-Shared-Session-Key` header. That
Redis entry is given a 7-day TTL. On each request the key was resolved
to its user id and returned before the suspended/active check ran, so a
captured key kept authenticating for the full 7 days of its TTL. Logout,
suspension, password change, and token revocation never touched the
Redis entry, so none of them stopped it.

Key changes:

* Store the key as `shared_session_user_auth_token_id:<key> ->
token.id`, building the Redis key name in one place
(`Auth::DefaultCurrentUserProvider.shared_session_redis_key`). Legacy
`shared_session_key_*` entries are never read, so every pre-deploy key
fails closed with no migration; clients re-mint on their next page load.
* Resolve the user through the bound token, applying the same
suspended/active and `maximum_session_age` checks as cookie auth, so the
key revokes and expires with the session instead of outliving it on the
Redis TTL.
* Mint against the token's effective user so admin impersonation keeps
live updates; the key stays the admin's and reverts to them when
impersonation ends.
* Rely on token destruction for revocation on every path rather than
deleting the Redis entry, since a gone token already makes its key fail
closed on lookup; orphaned entries expire on the 7-day TTL.
2026-07-14 13:25:05 +08:00
..
auth_provider.rb DEV: Add capability to pass an icon setting into auth provider registration (#34584) 2025-08-28 09:14:36 -05:00
authenticator.rb FEATURE: add link to "associated accounts" providers (#33275) 2025-06-20 10:22:29 +02:00
current_user_provider.rb FIX: only clear current device push subscription on logout (#39266) 2026-04-15 11:39:42 -03:00
default_current_user_provider.rb SECURITY: Bind shared session key to auth token and enforce user gates (#41610) 2026-07-14 13:25:05 +08:00
discord_authenticator.rb FEATURE: add link to "associated accounts" providers (#33275) 2025-06-20 10:22:29 +02:00
discourse_id_authenticator.rb FIX: enforce full_name_requirement on Discourse ID signups (#39831) 2026-05-07 15:17:47 -07:00
facebook_authenticator.rb FEATURE: add link to "associated accounts" providers (#33275) 2025-06-20 10:22:29 +02:00
github_authenticator.rb FEATURE: add link to "associated accounts" providers (#33275) 2025-06-20 10:22:29 +02:00
google_oauth2_authenticator.rb FEATURE: add link to "associated accounts" providers (#33275) 2025-06-20 10:22:29 +02:00
linkedin_oidc_authenticator.rb FEATURE: add link to "associated accounts" providers (#33275) 2025-06-20 10:22:29 +02:00
managed_authenticator.rb DEV: fix a large amount of typos (#37428) 2026-02-02 16:31:58 +11:00
oauth_faraday_formatter.rb
result.rb FEATURE: Support syncing User Field values from OAuth2 and OIDC (#40036) 2026-05-14 18:14:25 +01:00
twitter_authenticator.rb FIX: Twitter login problem check not reporting accurately (#35593) 2025-10-24 09:42:58 -04:00