Repository navigation
Conversation
This was referenced Sep 30, 2026
Contributor
[Critical impact] This PR appears safe to merge; no actionable findings remain. SummaryThis PR makes session ownership enforced by default, adds server and browser coverage, and documents deployment and migration.
Reviews (34) · Last reviewed commit: "Document the arguments of the session te..." · Reviewed by Greptile |
masenf
force-pushed
the
codex/session-integration
branch
from
October 5, 2026 21:24
80666f1 to
62db86e
Compare
masenf
force-pushed
the
codex/session-integration
branch
from
October 8, 2026 17:55
62db86e to
c561071
Compare
masenf
force-pushed
the
codex/session-integration
branch
from
October 8, 2026 18:24
c561071 to
db8a6ab
Compare
masenf
force-pushed
the
codex/session-integration
branch
2 times, most recently
from
October 8, 2026 19:03
86fdb35 to
5932c7d
Compare
Introduce a stdlib HS256 session codec, environment-only signing keys with rotation, and persistent local secrets excluded from exports. Preserve the local secret during web reinitialization. Validation: 421 affected tests passed, plus unknown-key diagnostic coverage; Ruff and targeted pyright passed. Refs: ENG-12910
masenf
force-pushed
the
codex/session-integration
branch
from
October 14, 2026 09:35
5932c7d to
6b07618
Compare
This reverts commit ae217d3.
This reverts commit e2f2528.
An event context without an authorized session read and parsed REFLEX_SESSION_TOKEN_MODE on each creation (1.9 us). The parsed mode is now cached by the raw environment value (0.36 us), so a change to the environment still takes effect.
HTTP calls wait whenever the socket delivers a credential, on a first connection and on a reconnection alike. The flag that exempted later credentials was never cleared on disconnect, so an upload after a reconnection with an expired cookie could start before the new cookie.
The benchmarks connect a namespace that has no server and address state with a plain token. A connection now issues a session over the socket, so test_on_event_router_data failed at setup. The fixture moves here from the integration PR.
The harness restarts the backend in the same process on a new event loop. The redis token manager holds an asyncio.Event that is bound to the stopped loop, so each connection after the restart failed on the redis shards. A real restart is a new process with a new manager.
# Conflicts: # packages/reflex-base/src/reflex_base/config.py # packages/reflex-base/src/reflex_base/session.py # tests/units/reflex_base/test_session.py
# Conflicts: # news/+browser-session-transport.feature.md # packages/reflex-base/news/+session-cookie-bootstrap.feature.md
1 task done
The session survived the restart only because the generated key lives in the test process. A real `reflex run` restart without REFLEX_SECRET_KEY gets a new key and resets every session. Set a key, as a deployment does.
An upgraded deployment without REFLEX_SECRET_KEY resets every session on restart, and replicas reject each other's sessions. A reverse proxy that does not forward /_reflex/session leaves the browser without a cookie, so each reload starts with fresh state. The upgrade guide, the breaking change notes, the self-hosting guide and the container examples now say to set the key and route the path before deploying. warn and off turn the ownership protection off. The guide and the notes no longer suggest warn as a migration step: they ask every app to keep enforce and describe warn and off as escape hatches for a broken deployment. The deprecation note that called warn the default is removed; the breaking change note covers the new default.
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 30 files
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
Put the rule to keep enforce and the rule to share one secret key in warning alerts, as other Reflex pages mark critical rules. Collect the environment variables and rx.Config options in a settings table with their defaults. Use one term for each value: session cookie, client token, and exchange credential. Move the request-level detail of the exchange and the renewal into a "How browser sessions work" section at the end, and give clients that are not browsers their own section. No behaviour is described differently.
Remove how the exchange credential, renewal timers, Web Locks and storage keys work, the cookie attribute strings, and notes that belong in release notes. Turn the remaining behaviour into a troubleshooting list keyed by symptom. The guide goes from about 2,150 to 1,150 words.
The integration tests covered sessions that work. Add tests for the sessions that end, are rejected, or cannot be set up: - test_session_lifecycle: a fresh tab gets its cookie and keeps its state across a reload and a renewal. Another browser that presents its client token gets a new token and fresh state. Without its cookie the tab cannot upload, and a reload starts a new session with fresh state. At the maximum age the tab gets a new session and fresh state, and uploads work. - test_session_server_code_needs_the_owning_session: a handler cannot change another session's state, and SessionToken.SYSTEM can. - test_session_legacy_token_gets_fresh_state: a token from before sessions does not claim the state stored under it. - test_session_exchange_failure: a lasting failure holds uploads for three attempts, a 403 is not retried, and in both cases events keep working while uploads are rejected. BackendPathApp gets a handler that changes the counter of another client token, with its own session or as SYSTEM.
While the cookie exchange keeps failing, the page also shows a connection toast, so the toast locator matched two elements and failed in strict mode.
REFLEX_SKIP_COMPILE is internal, so its environment name is __REFLEX_SKIP_COMPILE. The test set the public name, which changed nothing. It now sets the real name and checks that compile suppression starts off. Also update the rollout-mode test docstring to the enforce default.
… workers Without the key, each worker process that is not started by reflex run generates its own key, so the workers of one backend reject each other's sessions.
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Exercise session ownership in real servers and browsers, migrate synthetic clients to server-issued credentials, and document deployment and rollout.
The backend-path app runs under enforcement across development/production and zero/one/two-level prefixes. It covers immediate hydration during held cookie exchange, shared/duplicate tabs, uploads, failed exchange recovery with retained or cancelled uploads, idle short-TTL renewal, backend restarts, and cross-site iframe persistence. EmbedPlugin coverage also runs under enforcement. Production restarts preserve their worker and compile-suppression settings.
A real Granian test verifies state events while cookie exchange is held and state continuity on reconnect. It uses
rx.Stateand asserts it leaves no direct BaseState subclass behind for later integration apps. Benchmark reconnects reuse cookies and bound tokens, with issuance outside measured event latency.The guide covers app-bound credentials, persistent/rotating signing keys, POSIX permissions and Windows ACLs, origin configuration, partitioned cookies, embedding, migration modes, SYSTEM/anonymous authority, idle renewal, retry/cancellation, and readiness during cookie replacement. Existing reverse-proxy/api_transformer facilities handle rate limiting.
Review order: #7361 → #7362 → #7363 → #7364. Merged with current main; #7360 is already merged. Companion: reflex-dev/reflex-enterprise#240.
Validation:
pyright reflex testspass. Minimum-dependency checks pass for reflex, reflex-base, and reflex-components-core. Stub generation makes no tracked changes.playground-0.8.23job fails on that older release's missing greenlet dependency. Current-head playground and size checks pass. Large CI matrices are still running after the final pushes; cancelled duplicate runs also temporarily report failed gate checks.All substantive feedback is addressed. Review-thread replies explain the intentional connection-lifetime authority policy and declined hypothetical/style-only requests. Final adversarial review found no additional code blockers.
The guide now also covers: cookie renewal only at
POST /_reflex/session, trust for a page on the backend host, the 403 exchange result, hosts where the browser stores noSecurecookie (plain HTTP), the shared-state link check, and that all ports of the backend host share the cookie.The guide documents
enforceas the default mode, how to change it withREFLEX_SESSION_TOKEN_MODE, and what an upgrading app can see.Breaking: this pull request changes the
REFLEX_SESSION_TOKEN_MODEdefault toenforce. State access for a client token that the session does not own raisesSessionAuthorizationError, uploads for such a token return 403, and a tab that presents such a token gets a new token and fresh state.warnallows it with a warning andoffdisables the check. Unit tests and the docs example tests run inwarn, and the in-process benchmarks inoff, through fixtures with their ownMonkeyPatchcontext, because they address state with plain tokens. The self-hosting page lists/_reflex/sessionwith the routes that a reverse proxy must forward.Related to ENG-12920, ENG-12921, ENG-9088.