Repository navigation
feat(events): send a GET call's State token in a header, not the URL - #868
Merged
Merged
Conversation
…n header Citry's browser code now sends the State token of a GET call to a handler that reads State in the X-Citry-State-Token request header, so it stays out of the URL that server and proxy access logs record. The server still reads the _citry_state_token query parameter, refuses a call whose header and query carry different tokens with 400 protocol_mismatch, and lists X-Citry-State-Token in Vary on GET answers. The citry-events/1 JSON format does not change. Closes #761 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d GET answers private Fold in the independent review of #761: - the browser sends a GET call once more with the token in the query when a header-only call answers invalid_state, so a page still works against a server from before 1.3.0 and with a transport that forwards only the URL; - a handler's own cache policy on a GET call that sent the token header becomes private, since the URL no longer separates tokens and some CDNs ignore Vary; - early refusals carry the same Vary marks; - spec, docs, changelog and trust boundaries rows updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…row cache policies fully Fold in the second review of #761: - the browser retries a header-only GET only when the invalid_state answer does not list X-Citry-State-Token in Vary (when it can read Vary), not after a cancel or timeout, and with a copy of the envelope; - a handler's cache policy on a GET that sent the header keeps only the directives a browser cache follows, reads quoted values correctly, and drops CDN-Cache-Control and Surrogate-Control; - refusals sent before dispatch carry no-store on GET; - docs, spec, changelog and trust boundary line references updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e proxy requirement Fold in the third review of #761: split Cache-Control with one pass, keep a field-qualified no-cache as the bare form, drop malformed directives and every CDN-only cache header, treat Vary: * as reading the token header, say that a proxy must forward X-Citry-State-Token, and refresh trust boundary line references. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n-header # Conflicts: # docs/design/trust_boundaries.md
…n-header # Conflicts: # docs/design/trust_boundaries.md
…n-header # Conflicts: # CHANGELOG.md
JuroOravec
added a commit
that referenced
this pull request
Nov 24, 2026
#871 (#878) Records the Mechanism 7 security reviews of six merged Events changes, in the form docs/security/reviews/README.md describes. Each record is built from the pull request description, the merged diff and its tests; where a description does not record something the template asks for, the record says so. Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
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.
(Opus 5.5)
Closes #761
Citry's browser code now sends the State token of a GET event call in an
X-Citry-State-Tokenrequest header instead of the_citry_state_tokenquery parameter, so server and proxy access logs no longer record it by default. Thecitry-events/1JSON format does not change.How it works
citry-events-vue.ts): a GET call to a handler whose descriptor hasusesStatesends the token in the header. If the answer is a singleinvalid_stateerror that does not listX-Citry-State-TokeninVary(a server from before 1.3.0), or one whoseVarythe browser cannot read (another origin, a custom transport), it sends the call once more with the token in the query and without the header. At most one retry, never after a cancel or timeout, and a custom transport gets a copy of the envelope.codecs.py,routes.py): on a GET to a handler that declaresstate, the query codec reads the header; the query parameter still works.400 protocol_mismatch, before the handler runsX-Citry-State-TokeninVarybesideX-Citry-Page-Nonce. GET refusals before dispatch now also carryno-store, like dispatched GET answers.Cache-Control, the server keeps only the directives a browser cache follows behindprivate(orno-store) and drops CDN-only headers (*CDN-Cache-Control,Surrogate-Control,Edge-Control,X-Accel-Expires). Before, the token in the URL kept one visitor's cached answer from another; some CDNs ignoreVary.STATE_TOKEN_HEADER(Python, canonical copy inpackages/protocol/events/v1/python, synced intocitry/_protocol) andCARRIER_HEADERS(protocol JS package) name the header.Unchanged: POST calls and the no-JavaScript form path (tokens ride the body); the renewal answer (
stateaction in the body); same-origin calls need no preflight, and cross-origin GET calls were already preflighted because of theX-Citry-*headers.Design and contract versions
The JSON envelope does not change, so this needs no
citry-events/2. Precedent:X-Citry-Page-Noncewas added to the v1 HTTP adapter section as an optional request header in 1.2.0 (#822). Rejected alternative:citry-events/2, a whole new protocol for an HTTP-adapter detail.Rolling deploys keep the promise in
about/versioning.md("new page to old server: accepted"): a 1.3.0 page calling a 1.2.x server getsinvalid_statefor the header-only call and the browser retries with the query token. Limit, documented in the spec: a proxy in front of a 1.3.0 server must forward the header; if it drops it, the server answersinvalid_statewith the header inVary, and the browser does not retry.Versioning
New behavior plus a security tightening, so a minor release, 1.3.0 (the changelog entries sit there). The
400refuses input earlier releases accepted (a header they ignored plus a different query token); no real client sent that, and the changelog marks it "Security:" under the security exception. Narrowing a handler's own cache policy on such a call changes caching only, and only when the header is sent. A custom transport'ssendcan now run twice for one call; documented inreference/browser-apis.mdand the changelog.Security (Mechanism 7)
Places touched: State tokens and Events request headers, Events responses (
Vary,Cache-Control). Three independent review rounds checked each route the token can take:security.md)no-storeby default; a handler's own policy is limited to the browser when the header is sent;Varylists the header400before dispatch, the message echoes neither value, a repeated header fails token verificationFixed during the review: early refusals had no
Vary; the retry first fired on anyinvalid_state, now only when the server does not read the header; a handler'spublicpolicy behind a CDN that ignoresVarycould share one visitor's answer; quoted and qualifiedCache-Controlvalues, CDN-only headers, and a quadratic regex in the first cache-policy parser;Vary: *; stale line references intrust_boundaries.md; several docs and spec passages.Mechanism 8: the reviewer checked the advisory survey's cache (HTTP and cross-user), cache-key, header spoofing and injection, CSRF, log injection, and token leakage kinds; after the fixes above, the change introduces none of them.
Tests
TestGetHandlersintest_events_routes.py(header read, same and different tokens, repeated query and header, empty header, malformed header, stateless handler, renewal through the header,Vary, cache-policy narrowing, CDN headers, a long hostile policy, 405 refusals);_stateful_get_token_headerintest_events_host_parity.pyruns on Django and FastAPI (ASGI), andtest_wsgi_reads_the_state_token_header_on_a_get_callon WSGI.vue-events.test.mjs(header instead of query, no token for a stateless GET, retry and no-retry cases, custom transport with and without headers); protocol JS package exportsCARRIER_HEADERS.test_a_get_call_that_reads_state_sends_its_token_in_a_header(Chromium).Checks run locally
citryPython tests: 15,522 passed (not e2e); Events e2e file: 74 passed.citry-clientpnpm run check: 398 passed; protocol JS package check: 18 passed;validate.pyfor the protocol package.--platform linuxoncitry;scripts/validate.py;scripts/sync_protocol_python.py --check;python -m docs_site build-check --strict(0 errors, 0 warnings).🤖 Generated with Claude Code