Skip to content

feat(events): send a GET call's State token in a header, not the URL - #868

Merged
JuroOravec merged 7 commits into
mainfrom
events/get-state-token-header
Nov 24, 2026
Merged

JuroOravec merged 7 commits into
mainfrom
events/get-state-token-header

Conversation

@JuroOravec

Copy link
Copy Markdown
Member

(Opus 5.5)

Closes #761

Citry's browser code now sends the State token of a GET event call in an X-Citry-State-Token request header instead of the _citry_state_token query parameter, so server and proxy access logs no longer record it by default. The citry-events/1 JSON format does not change.

How it works

  • Browser (citry-events-vue.ts): a GET call to a handler whose descriptor has usesState sends the token in the header. If the answer is a single invalid_state error that does not list X-Citry-State-Token in Vary (a server from before 1.3.0), or one whose Vary the 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.
  • Server (codecs.py, routes.py): on a GET to a handler that declares state, the query codec reads the header; the query parameter still works.
The call sends The server uses
Header only, or header and an empty query field The header
Query field only The query field
The same token in both That token
Different tokens, or the header and a repeated query field Neither: 400 protocol_mismatch, before the handler runs
  • Every GET answer, including refusals sent before dispatch, lists X-Citry-State-Token in Vary beside X-Citry-Page-Nonce. GET refusals before dispatch now also carry no-store, like dispatched GET answers.
  • When a GET call sends the header and the handler sets its own Cache-Control, the server keeps only the directives a browser cache follows behind private (or no-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 ignore Vary.
  • STATE_TOKEN_HEADER (Python, canonical copy in packages/protocol/events/v1/python, synced into citry/_protocol) and CARRIER_HEADERS (protocol JS package) name the header.

Unchanged: POST calls and the no-JavaScript form path (tokens ride the body); the renewal answer (state action in the body); same-origin calls need no preflight, and cross-origin GET calls were already preflighted because of the X-Citry-* headers.

Design and contract versions

The JSON envelope does not change, so this needs no citry-events/2. Precedent: X-Citry-Page-Nonce was 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 gets invalid_state for 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 answers invalid_state with the header in Vary, 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 400 refuses 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's send can now run twice for one call; documented in reference/browser-apis.md and 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:

Route Verdict
Server and proxy access logs Safe for Citry's browser code; a client that sends the query parameter, and the one retry against an older server, still put it in the URL (documented in security.md)
Logging or tracing tools that record request headers Documented: leave the header out
Referer, browser history Not applicable: fetch URLs never become either
Shared caches and CDNs Safe: no-store by default; a handler's own policy is limited to the browser when the header is sent; Vary lists the header
Header versus query confusion Safe: different values answer 400 before dispatch, the message echoes neither value, a repeated header fails token verification
Cross-origin event URL Unchanged: already preflighted; a CORS setup that lists allowed headers must add the new one (changelog)

Fixed during the review: early refusals had no Vary; the retry first fired on any invalid_state, now only when the server does not read the header; a handler's public policy behind a CDN that ignores Vary could share one visitor's answer; quoted and qualified Cache-Control values, CDN-only headers, and a quadratic regex in the first cache-policy parser; Vary: *; stale line references in trust_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

  • Server: TestGetHandlers in test_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_header in test_events_host_parity.py runs on Django and FastAPI (ASGI), and test_wsgi_reads_the_state_token_header_on_a_get_call on WSGI.
  • Browser: 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 exports CARRIER_HEADERS.
  • e2e: test_a_get_call_that_reads_state_sends_its_token_in_a_header (Chromium).

Checks run locally

  • citry Python tests: 15,522 passed (not e2e); Events e2e file: 74 passed.
  • citry-client pnpm run check: 398 passed; protocol JS package check: 18 passed; validate.py for the protocol package.
  • ruff, ruff format, mypy and mypy --platform linux on citry; scripts/validate.py; scripts/sync_protocol_python.py --check; python -m docs_site build-check --strict (0 errors, 0 warnings).

🤖 Generated with Claude Code

JuroOravec and others added 7 commits November 24, 2026 19:34
…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
@JuroOravec
JuroOravec merged commit 31841a7 into main Nov 24, 2026
33 checks passed
@JuroOravec
JuroOravec deleted the events/get-state-token-header branch November 24, 2026 22:44
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Send the State token for GET Events calls in a header, not the query string

1 participant