Skip to content

Host integration APIs from citry-django#16: has_server_events(), CSRF names in config, page nonce for host requests #818

Open

Description

@JuroOravec

(Opus 5.5)

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).

🤖 Generated with Claude Code

https://claude.ai/code/session_017pjjQc1w8PkP2VuK3qFsKw

Activity

  1. added
    next-sprint
    on Nov 21, 2026
  2. JuroOravec commented on Nov 21, 2026

    @JuroOravec
    MemberAuthor

    (Opus 5.5)

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    next-sprint

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions