Skip to content

fix: tighten cache replay, stylesheet writes, class names, attribute text - #759

Merged
JuroOravec merged 3 commits into
mainfrom
fix/render-cache-hardening
Nov 18, 2026
Merged

JuroOravec merged 3 commits into
mainfrom
fix/render-cache-hardening

Conversation

@JuroOravec

Copy link
Copy Markdown
Member

What changed

Seven small fixes in the render cache, the stylesheet store, class names
and attribute text. All are Python-only (packages/py/citry).

  1. Render cache replay. A payload extension's text replacement is put
    into stored HTML on replay. Citry now checks every binding ID in the
    old and new values, not only the ends of the marker, and the values
    must be exactly those IDs joined by single spaces. The built-in i18n
    extension already writes this shape. Anything else makes Citry render
    the component again instead of replaying it.
  2. css_data() stylesheet with a configured cache. The stylesheet
    route serves only what the cache holds. When the cache dropped the
    entry after the render (a TTL, a size limit, or a replayed render that
    never wrote it), the page linked a URL that answered 404. Citry now
    writes each linked stylesheet again when it writes the page.
  3. Replayed <textarea>. A cached component that writes a value into
    a <textarea> came back with an empty textarea on replay. The
    serializer now gets the replayed leaf's stored parts, which still mark
    the dynamic text.
  4. Pure-body memo key. The memo for pure = True components is keyed
    by the body object rather than its id(), so a later body at a reused
    address cannot match an earlier entry.
  5. c-class and c-style keys. A Django lazy translation now works
    as a class name (string, list item or dict key), and a Markup class
    or style dict key is decoded once, so &amp; is not escaped twice.
  6. Carriage return in attribute values. escape_attribute_value now
    writes a carriage return as &#13;, because the browser reads a raw
    one as a line feed. The two leaf-program attribute writers (the row
    formatter and the generated row writer) now call the same function.
  7. security_csp on a Vue page. When the server HTML a Vue host
    would carry fails the CSP check, Citry sends the host empty. The
    page's own CSP check then sees only the empty host, so nothing said
    why. Citry now warns with what the check found, in "warn" and
    "strict" mode alike. The render is not refused.

docs/design/trust_boundaries.md rows updated: the
escape_attribute_value bullet, the c-<name> value row, the
class/c-class row, the security_csp row, the cache/<class>.<hash>
route row, and the payload render cache hook row. Line references into
the files this PR shifts are updated. docs_site/content/vue/server-rendering.md
mentions the new warning.

Left out

  • The HTML that the Rust Vue server renderer writes for a hydrated page
    still keeps a raw carriage return in an attribute value. It needs a
    citry-core change.
  • Some queued items need a maintainer decision first, and are not in this PR.
  • Item 2 adds one cache read per linked css_data() stylesheet each time
    a page is written.

Checks

  • pytest packages/py/citry/tests (without e2e): 14,781 passed, 9
    skipped, 1 xfailed. 2 failures and 2 collection errors also happen on
    main in the same environment: an unpinned tzdata release, an
    unpinned pydantic release, and two files that import citry_ui, which
    was not installed.
  • Each new test fails without its fix (checked by reverting each hunk).
  • ruff check and ruff format --check (locked 0.14.13) on touched
    files: clean. mypy (locked 1.20.2) on touched source files, also with
    --platform linux: clean.

Versioning

  • Patch release. Nothing a user passes in is refused, and no stored or
    wire format changes.
  • Item 1 makes replay fall back to a fresh render for a staged text
    replacement that 1.0.1 replayed. stage_render_cache() is
    experimental, its return type is not exported, and the render still
    succeeds.
  • Item 6 changes output bytes for attribute values with a carriage
    return, toward the value the app passed.
  • Item 7 adds a warning.

Review

An independent reviewer checked the change, with a security brief
covering text and markup, CSS, Citry's own markers, the responses Citry
serves, and the opt-in output checks. It found no security problem and
agreed this fits a patch release. Applied from its findings: the same
double-escape fix for Markup style keys, updated line references in
trust_boundaries.md, and a tighter textarea test assertion. A separate
prose pass reworded the changelog entries, the warning text (it now says
what to do), comments and docstrings.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KUhrHXH1mNfRCnPcsQt7ED

JuroOravec and others added 2 commits November 18, 2026 10:24
…text

- On a render cache replay, check every binding ID in a text replacement
  that a payload extension stages, not only the ends of the marker.
- Write a css_data() stylesheet into a configured cache again when the
  page is written, if the cache dropped it after the render.
- Replay a cached component with a textarea and a dynamic value with its
  text.
- Key the memo of pure component bodies by the body object, not its
  id(), so a reused id() cannot match another body.
- Accept Django lazy translations as c-class names, and decode a Markup
  class or style dict key once.
- Write a carriage return in an attribute value as &#13; in every Python
  attribute writer.
- Warn with the findings when security_csp makes Citry send a Vue host
  empty.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KUhrHXH1mNfRCnPcsQt7ED
Resolve the conflicts in CHANGELOG.md (main's Unreleased entries and this
branch's entries now share one Fixes list) and in
docs/design/trust_boundaries.md. Main's refreshed rows are kept; this
branch adds its stage_render_cache() binding-id check and the
security_csp warning for an empty Vue host. Line numbers that this
branch's code changes moved (replay.py, serialization.py, attrs.py) are
checked against the merged code.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KUhrHXH1mNfRCnPcsQt7ED
Resolves the conflicts in CHANGELOG.md and docs/design/trust_boundaries.md.
The changelog keeps the entries from both sides. In the trust table, the
message id row and the app id row take main's text about the own-key
lookups, and the app id and $c-tr rows keep this branch's line numbers.
Line numbers this branch cites in client.js and django.py move with the
code main changed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KUhrHXH1mNfRCnPcsQt7ED
@JuroOravec
JuroOravec merged commit b4d027c into main Nov 18, 2026
0 of 12 checks passed
@JuroOravec
JuroOravec deleted the fix/render-cache-hardening branch November 18, 2026 11:27
JuroOravec added a commit that referenced this pull request Nov 18, 2026
)

* docs(security): add review records for #754, #755, #756, #757 and #759

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KUhrHXH1mNfRCnPcsQt7ED

* docs(security): apply review findings to the 1.0.2 hardening records

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KUhrHXH1mNfRCnPcsQt7ED

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

1 participant