Repository navigation
Validate enforced sessions and document migration #7364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
+1,393
−66
Open
Changes from all commits
Commits
Show all changes
124 commits
Select commit
Hold shift + click to select a range
94c6038
Add signed browser sessions and session-bound client tokens
masenf a987ce7
Document session primitive regression tests
masenf b592c65
Scope signed sessions to their issuing app and fix portable secret tests
masenf 44c4b4e
Keep frontend cleanup locking coverage with persistent session secrets
masenf d8a70b1
Authorize browser state through session-aware HTTP and WebSocket tran…
masenf 1eb1a60
Adapt connect hydration tests to session-aware fixtures
masenf 05fa726
Use the validated root context for streamed event fallback
masenf 9120624
Scope custom sockets and renew authenticated browser sessions
masenf ebed735
Preserve the public database session helper when loading App
masenf c21c1a9
Persist in-band browser sessions without delaying hydration
masenf 8308fa6
Preserve session cookies and hydration auth through transport warmup
masenf 9833bb2
Coordinate cold sessions before warming browser transports
masenf 579c45e
Renew idle sessions and recover cookie readiness without losing queue…
masenf 9e9b3b6
Keep HTTP readiness pending through cookie replacement reconnects
masenf 2dc17d8
Exercise enforced sessions across servers and browsers and document m…
masenf 32324b7
Exercise session recovery and preserve production restart settings
masenf ebba877
Keep the Granian session test out of the global BaseState registry
masenf d5e211b
Document HTTP readiness during cookie replacement reconnects
masenf f03175f
Read the session secret key from REFLEX_SECRET_KEY only
FarhanAliRaza 056313c
Merge session-token-primitives into session-transport
FarhanAliRaza 63e635b
Merge session-transport into session-frontend
FarhanAliRaza 6c84657
Merge session-frontend into session-integration
FarhanAliRaza 38fe963
Document REFLEX_SECRET_KEY and safe key changes
FarhanAliRaza 0f1b8c6
Merge main into session-token-primitives
FarhanAliRaza d5bf4c0
Raise the reflex-base floor for reflex_base.session
FarhanAliRaza 27e4900
Merge session-token-primitives into session-transport
FarhanAliRaza b4d364a
Assert complete session messages and isolate config defaults
FarhanAliRaza 1b1ed03
Merge remote-tracking branch 'upstream/main' into pr-7361
FarhanAliRaza 45d2bca
Reject a short REFLEX_SECRET_KEY when reflex run starts
FarhanAliRaza 426396a
Merge branch 'pr-7361' into pr-7362
FarhanAliRaza 24c92b7
Fix session exchange for unstored cookies, same-host pages and shared…
FarhanAliRaza 7a2791a
Merge session-transport into session-frontend and fix session lifecyc…
FarhanAliRaza 08c88ca
Merge branch 'pr-7363' into pr-7364
FarhanAliRaza 8f8c50d
Document session renewal, trusted origins and plain HTTP hosts
FarhanAliRaza 3be8196
Type the session exchange error and adapt the frontend package tests
FarhanAliRaza 310aaa4
Merge branch 'pr-7363' into pr-7364
FarhanAliRaza 8eacdf1
Enforce session ownership by default
FarhanAliRaza f7c467c
Merge branch 'pr-7361' into pr-7362
FarhanAliRaza f250df6
Merge branch 'pr-7362' into pr-7363
FarhanAliRaza 42269ed
Merge branch 'pr-7363' into pr-7364
FarhanAliRaza e5ce4c5
Keep unit tests and benchmarks on a compatibility session mode
FarhanAliRaza dc7b4e4
Merge branch 'pr-7362' into pr-7363
FarhanAliRaza ea17694
Merge branch 'pr-7363' into pr-7364
FarhanAliRaza 364e3aa
Merge branch 'pr-7361' into pr-7362
FarhanAliRaza b1791be
Merge branch 'pr-7362' into pr-7363
FarhanAliRaza 6715188
Merge branch 'pr-7363' into pr-7364
FarhanAliRaza d5fe340
Merge remote-tracking branch 'upstream/main' into pr-7361
FarhanAliRaza 1da52ce
Give the session check, the token rule and the socket credential one …
FarhanAliRaza eb7dc36
Merge branch 'pr-7362' into pr-7363
FarhanAliRaza 844c0f8
Track the session exchange with its abort controller only
FarhanAliRaza 31cd10a
Merge branch 'pr-7363' into pr-7364
FarhanAliRaza 903e831
Document the one-minute exchange credential
FarhanAliRaza 6660d41
End a browser session at a maximum age
FarhanAliRaza 8ebf492
Merge branch 'pr-7363' into pr-7364
FarhanAliRaza 2fa93dc
Merge branch 'pr-7362' into pr-7363
FarhanAliRaza 29b1493
Document the maximum session age
FarhanAliRaza 3d3cf0a
Reject a blank REFLEX_SECRET_KEY at startup
FarhanAliRaza 5f27de5
Merge branch 'pr-7361' into pr-7362
FarhanAliRaza 20066d0
Address review findings on the session transport
FarhanAliRaza cc21438
Merge branch 'pr-7362' into pr-7363
FarhanAliRaza 0442b43
Address review findings on the frontend session lifecycle
FarhanAliRaza b2c666a
Merge session-frontend and address review findings on the guide and t…
FarhanAliRaza c366510
Generate a key for a blank REFLEX_SECRET_KEY and share it with workers
FarhanAliRaza c729a2a
Merge branch 'pr-7361' into pr-7362
FarhanAliRaza e5c53a3
Merge branch 'pr-7362' into pr-7363
FarhanAliRaza 62cf3b2
Merge branch 'pr-7363' into pr-7364
FarhanAliRaza 79c431f
Keep warn as the session mode default in the primitives
FarhanAliRaza dcba6b6
Merge branch 'pr-7361' into pr-7362
FarhanAliRaza 8c111a0
Restore the enforce value of the session mode setting
FarhanAliRaza 8721945
Merge branch 'pr-7361' into pr-7362
FarhanAliRaza 6636a2d
Renew cookie-backed sockets at the session endpoint only
FarhanAliRaza ecdf167
Merge branch 'pr-7362' into pr-7363
FarhanAliRaza d17b38d
Adapt browser tests to the scoped token key and stop holding uploads …
FarhanAliRaza 2709fda
Let the storage browser test ignore the session cookie and refresh hint
FarhanAliRaza 8a2f827
Merge session-frontend and enforce session ownership by default
FarhanAliRaza f934c25
Merge branch 'pr-7363' into pr-7364
FarhanAliRaza 0102822
Document session renewal at the endpoint and the session route for pr…
FarhanAliRaza 5539139
Connect a socket without an ambient event context
FarhanAliRaza b93c236
Adapt two browser tests to the enforced default and the localhost har…
FarhanAliRaza f2cb365
Merge branch 'pr-7362' into pr-7363
FarhanAliRaza 0ee0c76
Merge branch 'pr-7363' into pr-7364
FarhanAliRaza 3e7ce1a
Show the user an upload that the server rejects
FarhanAliRaza 199bd76
Merge branch 'pr-7363' into pr-7364
FarhanAliRaza 1c7aa71
Word the rejected-upload error for the user in production
FarhanAliRaza 78a3800
Merge branch 'pr-7363' into pr-7364
FarhanAliRaza e525408
Document the message for an upload without a valid session
FarhanAliRaza ab09ed7
Compare the port of a same-origin session request by value
FarhanAliRaza 9b4b055
Merge branch 'pr-7362' into pr-7363
FarhanAliRaza 9cbdb0c
Merge branch 'pr-7363' into pr-7364
FarhanAliRaza cef90d9
Proxy the session route in the Caddyfile examples and qualify two gui…
FarhanAliRaza 3d574be
Keep a denied or lasting-failure exchange from restarting holds
FarhanAliRaza 44e1343
Merge branch 'pr-7363' into pr-7364
FarhanAliRaza 77d4caa
Send both cookie forms in local HTTP development
FarhanAliRaza a1a89ae
Merge branch 'pr-7363' into pr-7364
FarhanAliRaza 84836e3
Merge branch 'pr-7362' into pr-7363
FarhanAliRaza e2f2528
Document the two cookie forms of local HTTP development
FarhanAliRaza ae217d3
Select the secure session cookie by name in the browser tests
FarhanAliRaza 948b4b0
Send one session cookie in local HTTP development
FarhanAliRaza 24f8b4e
Merge branch 'pr-7363' into pr-7364
FarhanAliRaza 14e0ebf
Merge branch 'pr-7362' into pr-7363
FarhanAliRaza d1ca4f5
Revert "Select the secure session cookie by name in the browser tests"
FarhanAliRaza 3911e50
Revert "Document the two cookie forms of local HTTP development"
FarhanAliRaza eae4c38
Parse the session token mode once per environment value
FarhanAliRaza d7c860d
Merge branch 'pr-7362' into pr-7363
FarhanAliRaza 3cda7b4
Merge branch 'pr-7363' into pr-7364
FarhanAliRaza 8d6795d
Remove the per-tab session flag from the upload hold
FarhanAliRaza 5135e0f
Merge branch 'pr-7363' into pr-7364
FarhanAliRaza c333842
Run the benchmarks without session ownership checks
FarhanAliRaza 7f68049
Merge branch 'pr-7363' into pr-7364
FarhanAliRaza 53f3b59
Merge branch 'pr-7362' into pr-7363
FarhanAliRaza 4648e45
Give the restarted backend a new token manager in the restart test
FarhanAliRaza f34272a
Merge remote-tracking branch 'upstream/main' into pr-7362
FarhanAliRaza 14f1b38
Merge branch 'pr-7362' into pr-7363
FarhanAliRaza 855f835
Merge branch 'pr-7363' into pr-7364
FarhanAliRaza 5154533
Merge remote-tracking branch 'upstream/main' into pr-7364
FarhanAliRaza 96ed981
Set a secret key for the backend restart test
FarhanAliRaza 5a15f86
Document the secret key and proxy route for an upgrade, and keep enforce
FarhanAliRaza 005d5a7
Restructure the browser sessions guide for the reader
FarhanAliRaza 13c5731
Cut the browser sessions guide to what a reader acts on
FarhanAliRaza e6d1cc3
Test every session outcome in the browser under enforce
FarhanAliRaza bc2fb8d
Pick the upload toast by its title in the session tests
FarhanAliRaza f60672d
Set the internal skip-compile variable in the prod restart test
FarhanAliRaza e5ba25c
Say that a backend outside reflex run needs REFLEX_SECRET_KEY for its…
FarhanAliRaza 7d859b8
Document the arguments of the session test helpers
FarhanAliRaza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,199 @@ | ||
| --- | ||
| title: Browser Sessions | ||
| --- | ||
|
|
||
| # Browser Sessions | ||
|
|
||
| Reflex binds each tab's state to a signed browser session. Two values identify | ||
| a tab: | ||
|
|
||
| - The **session cookie** is an HTTP-only cookie that the backend signs. Page | ||
| scripts cannot read it. | ||
| - The **client token** (`client_token`) identifies one tab of that session. It | ||
| alone does not give access to the tab's state. | ||
|
|
||
| A session establishes ownership of state, not a user identity or login. | ||
| Authentication and authorization still belong in your app or AuthPlugin. | ||
|
|
||
| ## Modes | ||
|
|
||
| ```md alert warning | ||
| # Keep `enforce` in production. | ||
|
|
||
| Only `enforce` stops a client that knows a client token from reading and | ||
| changing that tab's state. `warn` and `off` turn that protection off. Use one | ||
| only to keep a broken deployment running while you fix the code that fails | ||
| under `enforce`, then remove it. | ||
| ``` | ||
|
|
||
| | Mode | Behavior | | ||
| | --- | --- | | ||
| | `enforce` (default) | State access and uploads need the session that owns the client token. A tab that presents a client token its session does not own gets a new one and fresh state. | | ||
| | `warn` | Escape hatch. Allows state access that the session does not own and logs a warning that names the call site. | | ||
| | `off` | Escape hatch. Disables ownership checks. | | ||
|
|
||
| ## Settings | ||
|
|
||
| | Setting | Default | What it controls | | ||
| | --- | --- | --- | | ||
| | `REFLEX_SECRET_KEY` (environment) | A temporary key for each `reflex run` | The keys that sign session cookies. See [Signing keys](#signing-keys). | | ||
| | `REFLEX_SESSION_TOKEN_MODE` (environment) | `enforce` | See [Modes](#modes). Set it on every backend worker and replica. | | ||
| | `session_token_ttl` | Seven days | How long one session cookie is valid. The browser renews it while the tab is open. | | ||
| | `session_token_max_age` | Seven days | The maximum age of a session. Renewal cannot extend a session past it. | | ||
| | `session_token_refresh_interval` | Half of `session_token_ttl` | When the browser renews the cookie. | | ||
|
|
||
| The `session_token_*` settings are `rx.Config` options, in seconds. Set | ||
| `session_token_ttl` below `session_token_max_age` to end idle sessions sooner | ||
| while active ones last up to the maximum age. | ||
|
|
||
| Under `enforce`, a session that reaches its maximum age ends: at the next | ||
| renewal the tab gets a new session, a new client token, and fresh state. | ||
| Uploads before that renewal return 403, and the page shows "Your session has | ||
| expired. Reload the page and try again." | ||
|
|
||
| ## Upgrading | ||
|
|
||
| Before you deploy the upgrade: | ||
|
|
||
| - Set `REFLEX_SECRET_KEY` on every backend (see [Signing keys](#signing-keys)). | ||
| Without it, every restart resets the state of all tabs, and replicas reject | ||
| each other's sessions. | ||
| - Route `/_reflex/session` to the backend in your reverse proxy, as you route | ||
| `/_event` and `/_upload`. Without it, the browser never stores the session | ||
| cookie, so each reload starts with fresh state. | ||
|
|
||
| After the upgrade: | ||
|
|
||
| - Tabs that were open during the upgrade get a new client token and lose their | ||
| state once. | ||
| - Server code that changes the state of another client, such as a broadcast | ||
| or a webhook that calls `app.modify_state`, raises | ||
| `SessionAuthorizationError`. Pass `session_token=SessionToken.SYSTEM` (see | ||
| [Server-side state access](#server-side-state-access)). This includes | ||
| `app.modify_state` with the token of an `rx.SharedState`. | ||
| - A client that is not a browser must use the client token that the backend | ||
| sends (see [Clients that are not browsers](#clients-that-are-not-browsers)). | ||
|
|
||
| Test the upgrade under `enforce` and fix your code before you deploy. If a | ||
| deployment breaks on code that you cannot fix at once, `warn` keeps it running | ||
| and logs each call site that needs a fix. Return to `enforce` as soon as you | ||
| can. | ||
|
|
||
| ## Signing keys | ||
|
|
||
| ```md alert warning | ||
| # Set one `REFLEX_SECRET_KEY` on every backend. | ||
|
|
||
| Give every replica and every deployment the same key. A server with a | ||
| different key rejects the sessions that the other servers issued. | ||
| ``` | ||
|
|
||
| Set `REFLEX_SECRET_KEY` to a random value of at least 32 bytes. Store it in | ||
| your deployment's secret manager or environment. Never put it in | ||
| `rxconfig.py`, and keep any `.env` file that holds it out of version control. | ||
| To generate a key: | ||
|
|
||
| ```bash | ||
| python -c "import secrets; print(secrets.token_hex(32))" | ||
| ``` | ||
|
|
||
| Without `REFLEX_SECRET_KEY`, `reflex run` generates a temporary key and logs a | ||
| warning. All sessions reset when `reflex run` restarts. A backend started | ||
| another way, such as by an ASGI server with several workers, generates a key | ||
| in each worker, and the workers reject each other's sessions. | ||
|
|
||
| ### Changing the key | ||
|
|
||
| ```md alert warning | ||
| # Keep the old key when you add a new one. | ||
|
|
||
| If you replace the old key with the new key, every session resets at once. | ||
| ``` | ||
|
|
||
| 1. Put the new key first and the old key after it, separated by a comma: | ||
| `REFLEX_SECRET_KEY=<new key>,<old key>`. Restart every backend. | ||
| 2. Wait at least `session_token_max_age`. Active sessions move to the new key | ||
| as their cookies renew. | ||
| 3. Remove the old key: `REFLEX_SECRET_KEY=<new key>`, and restart every | ||
| backend. | ||
|
|
||
| If the old key leaked, set only the new key at once. Every session resets, and | ||
| cookies signed with the leaked key stop working. | ||
|
|
||
| ## Origins, cookies, and embedding | ||
|
|
||
| - Set `api_url` to the public backend URL, including when TLS terminates at a | ||
| reverse proxy. | ||
| - Apps on the same host must have different `app_name` values, because | ||
| cookies are not scoped by port. | ||
| - The frontend gets its session cookie only from an origin that the backend | ||
| trusts: the backend's own origin, `deploy_url`, `api_url`, explicit | ||
| `cors_allowed_origins`, and the local development origins. | ||
| `cors_allowed_origins=["*"]` does not count. List the host origins of an | ||
| EmbedPlugin explicitly. | ||
| - Browsers store the cookie only over HTTPS or on `localhost`. A production | ||
| app served over plain HTTP on another host has no session cookie, so under | ||
| `enforce` every new connection starts with fresh state. In development on | ||
| another host, set `api_url` to the address that the browser uses. | ||
| - Cross-site iframes keep their session in browsers that support partitioned | ||
| cookies. The session belongs to the top-level site. | ||
|
|
||
| The session cookie is removed from request headers before they reach app code. | ||
| Use `rx.Cookie` for cookies that browser JavaScript must read. | ||
|
|
||
| ## Server-side state access | ||
|
|
||
| `EventContext.session_token` holds the validated `SessionToken` of the event, | ||
| with a non-secret `id`, `issued_at`, `expires_at`, and | ||
| `authorizes(client_token)`. It does not mean that the client is logged in. | ||
|
|
||
| `app.modify_state`, event enqueueing, and chained events use the session of | ||
| the current event or request. Under `enforce`, a handler cannot change the | ||
| state of another session, or link an `rx.SharedState` to a client token that | ||
| another session owns. | ||
|
|
||
| Lifespan tasks run with `SessionToken.SYSTEM`. For trusted server-side | ||
| fan-out, pass it explicitly: | ||
|
|
||
| ```python | ||
| from reflex_base.session import SessionToken | ||
|
|
||
| async with app.modify_state( | ||
| rx.BaseStateToken(ident=client_token, cls=MyState), | ||
| session_token=SessionToken.SYSTEM, | ||
| ) as root_state: | ||
| state = await root_state.get_state(MyState) | ||
| state.message = "Server maintenance starts soon" | ||
| ``` | ||
|
|
||
| Never use `SYSTEM` for a client token that a request supplies. A custom | ||
| endpoint that calls the state manager directly must do its own authorization. | ||
| Rate-limit `/_reflex/session` in your reverse proxy or `api_transformer`. | ||
|
|
||
| ## Clients that are not browsers | ||
|
|
||
| To create a session, send a JSON `POST` with an empty object to | ||
| `/_reflex/session` (under `backend_path`, if you set one). The response sets | ||
| the session cookie and returns `client_token`, `expires_in`, and `refresh_in`. | ||
| Send that cookie and client token on later requests. To keep an existing | ||
| client token, send it in the `Reflex-Client-Token` header. | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| **Every reload starts with fresh state.** The browser has no session cookie. | ||
| Check that your proxy forwards `/_reflex/session`, that the app is served over | ||
| HTTPS, and that the frontend origin is trusted (see | ||
| [Origins, cookies, and embedding](#origins-cookies-and-embedding)). | ||
|
|
||
| **All tabs lose their state after a restart or deploy.** `REFLEX_SECRET_KEY` | ||
| is not set, or the backends do not share it. | ||
|
|
||
| **The browser console says the backend does not trust the origin.** Add that | ||
| origin to `deploy_url` or `cors_allowed_origins`. | ||
|
|
||
| **Uploads return 403.** The session expired or the browser has no session | ||
| cookie. Reload the page; if that does not help, see the first item. | ||
|
|
||
| **Server code raises `SessionAuthorizationError`.** It changes the state of | ||
| another session. Pass `session_token=SessionToken.SYSTEM` if the code is | ||
| trusted. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| """Shared fixtures for the docs app tests.""" | ||
|
|
||
| from collections.abc import Generator | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def _session_token_compatibility_mode() -> Generator[None, None, None]: | ||
| """Run the tests in the session mode that allows tokens without a session. | ||
|
|
||
| The example tests address state with a plain token and no browser session, | ||
| which the default enforce mode rejects. | ||
|
|
||
| Yields: | ||
| Control while the mode is set. | ||
| """ | ||
| with pytest.MonkeyPatch.context() as patch: | ||
| patch.setenv("REFLEX_SESSION_TOKEN_MODE", "warn") | ||
| yield |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| Add browser sessions using HttpOnly cookies and a `POST /_reflex/session` endpoint that issues a client token bound to the requesting session. Sessions scope HTTP and custom WebSocket state access; authenticated sockets can renew their cookie credentials without losing client state. | ||
| Add browser sessions using HttpOnly cookies and a `POST /_reflex/session` endpoint that issues a client token bound to the requesting session. Sessions scope HTTP and custom WebSocket state access; authenticated sockets can renew their cookie credentials without losing client state. See the [browser sessions guide](https://reflex.dev/docs/api-routes/sessions/) for configuration and migration. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| AppHarness now points the development frontend at `localhost` for the backend API, so browser cookies remain same-site during tests. |
1 change: 1 addition & 0 deletions
1
packages/reflex-base/news/+session-context-authorization.breaking.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Session ownership is enforced by default. State access needs the browser session that owns the client token: `app.modify_state` and event enqueueing raise `SessionAuthorizationError` for a token that the session does not own, and unauthorized uploads return HTTP 403. Trusted server-side code passes `session_token=SessionToken.SYSTEM`. A tab that presents an unowned token gets a new token and fresh state. Keep the default: `REFLEX_SESSION_TOKEN_MODE=warn` or `off` turns this protection off and is only an escape hatch for a deployment that breaks before its code is fixed. Before you deploy, set `REFLEX_SECRET_KEY` on every backend and route `/_reflex/session` to the backend in your reverse proxy: without them, state resets on each restart or reload. See the [browser sessions guide](https://reflex.dev/docs/api-routes/sessions/). | ||
|
FarhanAliRaza marked this conversation as resolved.
Resolved
|
||
1 change: 0 additions & 1 deletion
1
packages/reflex-base/news/+session-context-authorization.deprecation.md
This file was deleted.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| Establish browser sessions over the WebSocket while hydration begins, then persist them through HTTP-only cookies with automatic refresh. New routing-token and freshness keys are scoped to each backend URL. Idle tabs renew their session cookies automatically; transient cookie-exchange failures retry without blocking WebSocket events, and queued uploads remain cancellable. | ||
| Establish browser sessions over the WebSocket while hydration begins, then persist them through HTTP-only cookies with automatic refresh. New routing-token and freshness keys are scoped to each backend URL. Idle tabs renew their session cookies automatically; transient cookie-exchange failures retry without blocking WebSocket events, and queued uploads remain cancellable. See the [browser sessions guide](https://reflex.dev/docs/api-routes/sessions/) for configuration and migration. |
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
1 change: 1 addition & 0 deletions
1
packages/reflex-components-core/news/+session-upload-authorization.breaking.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| File uploads carry the browser session cookie, and an upload for a client token that the session does not own returns HTTP 403. Keep the default `enforce` mode: `REFLEX_SESSION_TOKEN_MODE=warn` or `off` turns the rejection off and is only an escape hatch. See the [browser session guide](https://reflex.dev/docs/api-routes/sessions/) for configuration and migration. |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.