You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Host integration APIs from citry-django#16: has_server_events(), CSRF names in config, page nonce for host requests #818
citry-django (joeyjurjens/citry-django#16) works around three gaps that hosts embedding Citry's Vue islands in another framework hit. This issue records what Citry adds instead, and why.
1. CitryRender.has_server_events()
A host must make its framework send a CSRF cookie only for pages whose islands use server events, because the cookie (and Django's Vary: Cookie) makes a page uncacheable by shared caches. Today the only way to tell is to read the serialized Vue configuration JSON (occurrences[].eventContext), which is not a public format.
Decision: add an Experimental CitryRender.has_server_events(), next to needs_browser_runtime(), that answers from Citry's own records before serialization.
2. CSRF cookie and header names in the configuration block
When a host's CSRF cookie or header names differ from Citry's defaults, it has to write a script that calls Citry.configure({csrf: ...}) and wait for the runtime. The runtime already reads configuration.csrf from each app's configuration block.
Decision: Experimental Events settings for the CSRF cookie name and header name (and whether the token is read from a cookie at all), which Citry writes into the configuration block, so no extra script is needed.
3. The page's CSP nonce for fragments that a host's own requests load
Under a nonce-based CSP, the runtime refuses a fragment whose data block does not carry the page's nonce. A host that loads fragments with its own requests (htmx, fetch()) cannot know which page, and so which nonce, a request came from, especially with several tabs open.
Decision: Citry provides the page's nonce to the server per request. The runtime exposes it (for example Citry.pageNonce()) and offers a documented request header, and the fragment strategy uses the nonce from that header (checked for shape) when the app passes no csp_nonce, marking such responses so shared caches do not reuse them.
Not chosen: letting the runtime stamp the page's nonce onto any fragment it accepts. The nonce check is what stops HTML injected into the page from passing as a Citry fragment and running its scripts. If the runtime supplied the nonce itself, every fragment would pass and that protection would be gone. The server must keep writing the nonce.
Related: #810 (the fragment loader does not load the i18n plugin).
Status: parts 1 to 3 landed in #821 (needs_csrf_token() and has_server_events()) and #822 (CSRF names in the configuration block, Citry.pageNonce() and the X-Citry-Page-Nonce header), and ship in citry 1.2.0.
Possible follow-up, not planned yet: needs_csrf_token() covers the two requests Citry's own browser code sends with the CSRF token (Events calls and the i18n messages request of a locale switch). A third-party browser plugin may also send the token, and the method cannot see that; the docs say so. Covering it would need a public extension hook through which a plugin declares that it makes CSRF-protected requests. That fits the rethink of how extension hooks declare their effects in #804.
Activity
feat(render): add Experimental CitryRender.needs_csrf_token()
feat(render): add Experimental CitryRender.needs_csrf_token() and has…
feat(events): CSRF names in the configuration block and the page nonc…
JuroOravec commentedon Nov 21, 2026
(Opus 5.5)
Status: parts 1 to 3 landed in #821 (
needs_csrf_token()andhas_server_events()) and #822 (CSRF names in the configuration block,Citry.pageNonce()and theX-Citry-Page-Nonceheader), and ship in citry 1.2.0.Possible follow-up, not planned yet:
needs_csrf_token()covers the two requests Citry's own browser code sends with the CSRF token (Events calls and the i18n messages request of a locale switch). A third-party browser plugin may also send the token, and the method cannot see that; the docs say so. Covering it would need a public extension hook through which a plugin declares that it makes CSRF-protected requests. That fits the rethink of how extension hooks declare their effects in #804.release: citry 1.2.0 (host integration APIs from #818) (#829)