Skip to content

Validate enforced sessions and document migration - #7364

Open
masenf wants to merge 115 commits into
mainfrom
codex/session-integration
Open

masenf wants to merge 115 commits into
mainfrom
codex/session-integration

Conversation

@masenf

@masenf masenf commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

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.State and 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:

  • Full unit suite: 12,147 passed, 26 skipped; 80.15% coverage (72% required).
  • Final Chromium matrix: 70 passed across dev/prod/backend paths and embedding, including idle renewal, failed exchange recovery, cancellation, and six production/development restart configurations.
  • Isolated real Redis transport/context/upload suite: 390 passed.
  • Real Granian plus database import-order regressions: 15 passed.
  • All 13 frontend runtime/lifecycle wrappers pass, including cookie-replacement readiness and teardown regressions.
  • Ruff check/format and pyright reflex tests pass. Minimum-dependency checks pass for reflex, reflex-base, and reflex-components-core. Stub generation makes no tracked changes.
  • Full local pre-commit has six existing macOS-only Pyright errors in unchanged reflex-bench/reflex-workflow CPU-affinity code. All other hooks pass; CI pre-commit passes on Linux.
  • The advisory playground-0.8.23 job 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 no Secure cookie (plain HTTP), the shared-state link check, and that all ports of the backend host share the cookie.

The guide documents enforce as the default mode, how to change it with REFLEX_SESSION_TOKEN_MODE, and what an upgrading app can see.

Breaking: this pull request changes the REFLEX_SESSION_TOKEN_MODE default to enforce. State access for a client token that the session does not own raises SessionAuthorizationError, uploads for such a token return 403, and a tab that presents such a token gets a new token and fresh state. warn allows it with a warning and off disables the check. Unit tests and the docs example tests run in warn, and the in-process benchmarks in off, through fixtures with their own MonkeyPatch context, because they address state with plain tokens. The self-hosting page lists /_reflex/session with the routes that a reverse proxy must forward.

Related to ENG-12920, ENG-12921, ENG-9088.

@masenf
masenf added this pull request to stack #7365 September 30, 2026 00:41
@masenf masenf changed the title Exercise enforced sessions across servers and browsers and document migration Validate enforced sessions and document migration Sep 30, 2026
@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[High impact] The PR appears safe to merge, with no new actionable issues found.

Summary

This PR makes session ownership enforced by default, adds real-server and browser coverage, migrates benchmark clients to issued credentials, and documents rollout and proxy setup.

  • Reflex apps enforce browser session ownership by default.
  • Benchmark clients reconnect with server-issued session credentials.
  • App test servers keep session setup stable across runs.

Reviews (28) · Last reviewed commit: "Merge remote-tracking branch 'upstream/m..." · Reviewed by Greptile

@masenf
masenf force-pushed the codex/session-integration branch from 80666f1 to 62db86e Compare October 5, 2026 21:24
@masenf masenf added the documentation Improvements or additions to documentation label Oct 6, 2026
@linear-code

linear-code Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

ENG-12921

ENG-9088

ENG-12920

@masenf
masenf force-pushed the codex/session-integration branch from 62db86e to c561071 Compare October 8, 2026 17:55
@masenf
masenf force-pushed the codex/session-integration branch from c561071 to db8a6ab Compare October 8, 2026 18:24
@masenf
masenf force-pushed the codex/session-integration branch 2 times, most recently from 86fdb35 to 5932c7d Compare October 8, 2026 19:03
@masenf
masenf force-pushed the codex/session-integration branch from 5932c7d to 6b07618 Compare October 14, 2026 09:35
…de sentences

The self-hosting page says that the example Caddyfiles forward the
backend routes, but their matcher had no /_reflex/session, so the session
exchange reached the static file server. The guide now says that the
upload 403 applies under enforce, and that only a socket without a valid
cookie receives a credential.
- The backend's refresh notice no longer restarts an exchange that the
  backend denied for this page's origin. The guard moved from the
  scheduler into the request itself.
- After three failed attempts, a later retry does not hold HTTP calls
  again while its request is open.
WebKit does not store a Secure cookie from plain HTTP, also on a loopback
host, so local development in Safari had no session: fresh state on each
reload and rejected uploads. Local development over plain HTTP now sends
the plain SameSite=Lax cookie next to the secure partitioned one, and
each browser keeps the form that it accepts. The middleware reads the
plain cookie only there, and prefers the secure one. HTTPS and production
are unchanged.
Local development over plain HTTP now also stores the plain cookie, so
the tests that counted session cookies found two.

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 3 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread docs/api-routes/sessions.md Resolved
Comment thread docs/api-routes/sessions.md Resolved
The secure partitioned cookie works in a normal tab and in a cross-site
iframe, and WebKit accepts Secure cookies from loopback hosts since
310542@main. The plain fallback cookie is removed.
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
Base automatically changed from codex/session-frontend to main November 25, 2026 16:50
# Conflicts:
#	news/+browser-session-transport.feature.md
#	packages/reflex-base/news/+session-cookie-bootstrap.feature.md

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation on deck PRs lined up to review / merge next roadmap https://github.com/reflex-dev/reflex/issues/2727 security

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants