Repository navigation
feat(events): expire signed State after 24 hours by default, and answer stale_state for unknown token versions - #706
Merged
Conversation
A signed State token now expires 24 hours after Citry issues it when the component's State sets no _max_age, the same lifetime server-stored State already had. An expired token answers stale_state (409), and Citry's browser code offers a reload. A page that must stay open longer sets a longer _max_age; None keeps meaning "the default" in both storage modes. A State token whose version the server does not know, by its prefix or by the integer version in its payload, now answers stale_state instead of invalid_state, so a later 1.x release can move State tokens to a new version. The version is checked before anything else is read from the token. The Events spec, design doc, contract-version notes, security and State docs, and the changelog are updated to match. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…x_age Fold in the review findings: - A token that holds "x": null (minted by a release before 1.0.0) now expires 24 hours after its signed mint time, so a token copied before the upgrade does not stay valid until the secret changes. - State._max_age under one second raises ValueError when the class is defined: token times are whole seconds, so such a lifetime expired every token at once. - An unknown storage value answers invalid_state before the token prefix is looked at. - A render-cache entry renders again once its State token expires; a test covers it and the caching page says so. - Docs say when Citry issues a token, that the handler of a call with an expired token does not run, and that a new token version must change the prefix; the spec step stays format-neutral. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Verify now checks the expiry field of a server-stored entry too, so the 24-hour lifetime holds even when a cache backend ignores the time-to-live. Wording fixes from the follow-up review. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 15, 2026
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.
Part of the 1.0.0 work (#624, decision 3 and the later State token version decision).
What changes
Signed State expires after 24 hours by default. When a component's
Statesets no_max_age, its signed State token now expires 24 hours after Citry issues it, the same lifetime server-stored State already had. An expired token answersstale_state(409), and Citry's browser code asks the visitor once per page whether to reload, which brings a fresh token. This is the one breaking change recorded for 1.0.0, approved by the maintainer, and the changelog lists it under "Upgrading from 0.9.x".A token from an unknown token version answers
stale_state, notinvalid_state. The server checks the version first and reads nothing else from such a token:ce, a letter, a number (such ascev2.) that is neithercev1norces1;vother than 1, checked before the shape check, in the signed path whether or not the signature matched, and for server-stored entries too.A version that is not an integer, and every other unreadable token, stays
invalid_state(403). This makes the rule "an internal format may move to a new version in a 1.x minor release" true for State tokens: during a deploy, a page carrying a newer token gets a reload offer instead of an error.How a page opts out
There is no "never expires" value.
_max_age = Nonekeeps meaning "use the default" in both storage modes, as it already did for server storage, so it means the same thing everywhere. A page that must stay open longer sets a longertimedelta, for example_max_age = timedelta(days=7). A "never" value would have meantNonedoes different things per storage mode (server storage must never keep entries forever), and it would bring back the unbounded replay that the default exists to stop. The Versioning page already describes this rule.A token from 0.9.x holds
"x": null. Verification reads it as 24 hours after its signed mint timet, so a token copied before the upgrade does not stay valid until the secret changes._max_ageunder one second now raisesValueErrorat class definition: token times are whole seconds, so such a value expired every token at once (andtimedelta(0)must not look like "off"). Server-stored entries now also have their expiry field checked on verify, so the lifetime holds on a backend that ignores the cache time-to-live. A render-cache entry that holds an expired token renders again.Versioning check
stale_statechange alters one check inpackages/protocol/events/v1/spec.md. It lands before 1.0.0, which freezes v1. No field, value or route changes, and the spec's Versioning section now says the token format is not defined there and may change in 1.x.ce, letter, number prefix shape;docs/codebase.mdsays so.Files
packages/py/citry/citry/ext/events/tokens.py: default lifetime, version checks, docstrings.packages/py/citry/citry/ext/events/state.py,component.py: docstrings and the subclass warning text.test_events_tokens.py(newTestDefaultLifetime,TestUnknownTokenVersion; older tests that expectedinvalid_statefor a version-2 payload now expectstale_state, which is the new contract),test_events_dispatch.py,test_events.py.docs/design/events.md,docs/codebase.md(Contract versions),docs_site/content/security.md,events/state.md,advanced/subclassing.md,reference/browser-apis.md,CHANGELOG.md.Checks
packages/py/citry/tests(excluding e2e), run with the worktree onPYTHONPATH: 13589 passed, 9 skipped, 1 xfailed.ruff checkandruff format --checkonpackages/py/citry: clean.mypy packages/py/citry/citry, and again with--platform linux: clean.scripts/validate.py: all validators pass.scripts/check.py, because its fast profile includes the cargo phases and this lane was told not to build Rust. CI runs the full gate.Review
An independent reviewer did a technical review, a security review (Mechanism 7) and a Mechanism 8 review, then re-checked each fix commit. The saved
docs-cold-readeragent read the changed pages.Security (Mechanism 7). Places touched: State tokens, Events error responses, and the reload prompt. The reviewer classified every route the token takes:
v: the constant-time HMAC compare runs first, and the payload is parsed only to choose the error code. The shape check, State restore and class check are never reached, and a test hooks the shape check to prove it: safe.timedelta.maxis something only the author can set.No hole was found in this change or in a released version.
Mechanism 8. The reviewer read the advisory survey. This change closes its "State never expires unless
_max_ageis set" item and adds no instance of the island, secret-timing, deserialize, cache-key or cache-xuser bug classes.Fixed during the review:
"x": nullwere unbounded; they now expire 24 hours after their mint time._max_ageunder one second was accepted; it now raisesValueError.Left for others:
_vue/client.js(and the generated runtime) says "This page and the server are running different versions of the app". Expiry is now the most common cause ofstale_state. The text lives in the generated runtime bundle that the C6 lane is changing, so this PR leaves it alone and the coordinator will hand it to C6.🤖 Generated with Claude Code