diff --git a/docs/design/trust_boundaries.md b/docs/design/trust_boundaries.md
index 3555cf921..707cfb96f 100644
--- a/docs/design/trust_boundaries.md
+++ b/docs/design/trust_boundaries.md
@@ -1,9 +1,13 @@
# Who may supply each input that reaches the page
-**Status (2026-11-25): line numbers checked against `main` after the
-citry 1.3.0 release.** Every row names the function that does the
-work; when that function changes, the row changes in the same pull request
-(see [Keeping this doc accurate](#keeping-this-doc-accurate)).
+**Status (2026-11-25): references checked against `main` after the
+citry 1.3.0 release.** Every row cites the function that does the work
+by its name, not its line, and a validator fails the gate when a cited
+file, Python function or class, or docs heading is missing. For
+JavaScript, TypeScript, Rust, and Pest it checks only that each name is
+defined somewhere in the file. When that function changes, the row
+changes in the same pull request (see
+[Keeping this doc accurate](#keeping-this-doc-accurate)).
Citry turns Python values, template source, and HTTP requests into HTML,
CSS, and JavaScript. For each value that ends up in the page, an app
@@ -46,11 +50,13 @@ Each row answers four questions.
2. **What the browser does with it**: shows it as text, parses it as
markup, applies it as CSS, runs it, navigates to it, or uses it as a key.
3. **What Citry does, and where**: the one function that escapes, checks,
- or passes the value through, as `file:line`, and the render paths that
+ or passes the value through, as `path:Symbol` (such as
+ `citry/attrs.py:validate_html_attr_name`), and the render paths that
reach it.
4. **What the docs say**: the public page or docstring that states the
- rule. "Missing" means the code makes the input author only or app code
- but no public page says so yet.
+ rule, with a page section cited as `path#anchor` (such as
+ `docs/security.md#authorize-every-event`). "Missing" means the code
+ makes the input author only or app code but no public page says so yet.
Paths are repo-relative, with these short forms:
@@ -68,12 +74,12 @@ says which paths it covers. These are the paths:
- **Capture.** Every ordinary render first records its output as a list of
parts: text values, trusted HTML, and element start tags with their
- attributes (`citry/component_render.py:1069-1076`, `citry/_vue/capture.py`).
+ attributes (`citry/component_render.py:render_impl`, `citry/_vue/capture.py`).
The next two paths, static HTML and Vue, each turn that list into the
page, so a check made while recording applies to both.
- **Static HTML.** A page or subtree without Vue. `citry/serialize.py`
- writes text values with `escape_to_str` (`citry/serialize.py:1423`) and
- trusted HTML as it is (`:1426`).
+ writes text values with `escape_to_str` (`citry/serialize.py:_append_frame_parts`) and
+ trusted HTML as it is (`citry/serialize.py:_append_frame_parts`).
- **Vue.** A component with `js`, Vue syntax, or Events bindings. No Python
value becomes Vue template source: the template gets a reference such as
`$citryPrepared.citryText3`, and the value travels as JSON in the page's
@@ -87,21 +93,21 @@ says which paths it covers. These are the paths:
repeat the attribute-name checks of capture.
- **Node path.** The older node classes in `citry/nodes/__init__.py`.
Only a component render sets the context variable that selects capture
- (`citry/_vue/capture.py:51`), so a template renders on the node path in
+ (`citry/_vue/capture.py:_PREPARED_RENDER`), so a template renders on the node path in
these cases:
- It embeds spans of another template language, such as Django template
syntax, through the experimental `on_template_foreign_spans` hook
- (`citry/component_render.py`, `_get_compiled_template`). This happens
+ (`citry/component_render.py:_get_compiled_template`). This happens
on every render of that template. Inside a Vue app its output becomes
static blocks (see the row for HTML from a template with foreign
spans).
- A fill slot renders outside a component render: `str(slot)` (or
`Markup(slot)`) on a slot kept after the render
- (`citry/slots.py:337-352`), or a slot rendered in a worker thread that
+ (`citry/slots.py:Slot.__str__`), or a slot rendered in a worker thread that
does not copy context variables. Then a component class that has not
rendered yet compiles on the node path, and a nested template always
does, even when its class has rendered
- (`citry/nodes/__init__.py:1105-1122`), so an attribute on an element
+ (`citry/nodes/__init__.py:TemplateHtmlAttr._compiled_body`), so an attribute on an element
inside markup passed as a component input uses the node path every
time. After `Component.reset_template()` or a code reload, a class
compiles again as if it had not rendered. A slot rendered in a thread
@@ -112,7 +118,7 @@ says which paths it covers. These are the paths:
On the node path, `ElementAttrsNode._format` writes every attribute
value, and `ElementKeyNode` writes the `#c-key` attribute
- (`data-citry-key`) on its own (`citry/nodes/__init__.py:1571`).
+ (`data-citry-key`) on its own (`citry/nodes/__init__.py:ElementKeyNode.render`).
- **Events `Render`.** An event handler that returns
`Render(element=...)` re-renders through the same capture and writers.
- **Cached render.** `citry/ext/cache/replay.py` replays a stored capture
@@ -122,20 +128,20 @@ says which paths it covers. These are the paths:
The shared escaping functions live in `citry/util/html.py`:
-- `escape` (`:84`) and `escape_to_str` (`:100`) escape HTML text
+- `escape` (`citry/util/html.py:escape`) and `escape_to_str` (`citry/util/html.py:escape_to_str`) escape HTML text
(`& < > ' "` and ESC). A value with `__html__` passes through unchanged.
-- `exact_str` (`:125`) copies a `str` subclass into a plain `str`. `str()`
+- `exact_str` (`citry/util/html.py:exact_str`) copies a `str` subclass into a plain `str`. `str()`
of a `Markup` value is already plain, but a Django `SafeString` returns
itself and keeps its `__html__`, so text that must be escaped, such as
the `#c-key` value that `ElementKeyNode` writes, goes through
`exact_str(str(value))` before `escape`.
-- `escape_attribute_value` (`:576`) escapes a double-quoted attribute value.
+- `escape_attribute_value` (`citry/util/html.py:escape_attribute_value`) escapes a double-quoted attribute value.
A value with `__html__` is first decoded to the text a browser reads
- (`decode_attribute_entities`, `:555`) and then escaped, so a `Markup`
+ (`decode_attribute_entities`, `citry/util/html.py:decode_attribute_entities`) and then escaped, so a `Markup`
value cannot end the attribute. The decoded text is always a plain `str`,
so a Django `SafeString` is escaped too. A carriage return is written as
`
`, because the browser reads a raw one as a line feed.
-- `script_json` (`:614`) writes JSON for a ``, where Chromium and WebKit read `` content as markup while the page's own parse keeps it as text, so `reject_noscript_in_opaque_html` (`citry/_vue/opaque_html.py:93`) refuses a `Markup` value that holds a `` element on the Vue paths and in an Events `Render`, and `preflightDefinitions` refuses it again in the browser (`citry/_vue/client.js:1465`, parsed by `opaqueHtmlHoldsNoscript` at `:1078`). The same server check runs on each `Markup` value inside the contents of a `#c-ignore` or `v-pre` element; that block is one record written in the template, so the browser does not check it again. | `docs/syntax/expressions.md:166-205` ("trusts the whole value") |
-| `{{ expr }}` result: a component, `CitryElement`, `CitryRender`, or `Slot` | App code | Markup | A component renders with its own rules; a `CitryRender` is inlined as already-trusted HTML (`citry/citry_render.py:1444-1445`); a `Slot` follows section 4. | `docs/syntax/expressions.md:142-144` |
-| `{{ expr }}` inside a ``, but it can leave a JavaScript string or add CSS rules. Under a data-chosen `svg` the browser decodes the escaped value inside ``, but it can leave a JavaScript string or add CSS rules. Under a data-chosen `svg` the browser decodes the escaped value inside `` without checking its scheme. | `docs/advanced/dependency-files.md` ("Add a library URL") |
-| `Dependencies` entry with `__html__` (a ready-made tag) | App code | Markup | Inserted raw (`citry/ext/dependencies/emission.py:1311`); refused in fragments, on Vue pages, and with a nonce or Citry SRI. | `docs/advanced/dependency-files.md:266-275` |
-| `Script(url=, content=, attrs=)`, `Style(...)` in `Dependencies`, `Component.on_dependencies()`, or the `on_dependencies` hook | App code | Runs / CSS | `content` checked by `_check_validity`; `attrs` names by `validate_html_attr_name`, values escaped. A `url` that is a `str` subclass, such as Django's `SafeString`, is stored as a plain `str` when it is set (`Dependency.__setattr__`, `citry/ext/dependencies/types.py:150`): its text, or for a value with `__html__` that text with its character references decoded, as every attribute writer reads it (`_plain_url_text`, `:96`). So the escaping, the `javascript:` URL check that `security_javascript` runs (`_sanitize_structured_attributes`, `citry/_javascript_policy.py:511`), and the serialization check that the written `src` or `href` matches `url` all read the text the page gets; the safe mark is not trusted. With `security_javascript` off there is no scheme check; an `on*` key in `attrs` is allowed. | `docs/advanced/dependency-files.md` ("Customize the tag") and the `Script` / `Style` docstrings |
-| `serialize(csp_nonce=)`, Events `_csp_nonce` | App code (syntax-checked, so a bad value cannot break out) | Lets scripts run under the CSP | `_validate_csp_nonce` (`citry/serialize.py:1225`, CSP base64 only), then added to every structured tag after the dependency hooks (`citry/_serialization_security.py:497`), the fragment loader, and the Vue data. Tags written in a template never get it. | `docs/security.md:1677-1986` |
-| `X-Citry-Page-Nonce` request header, read by `page_nonce_from_headers()` and by an Events `Render` when the app sets no `_csp_nonce` | Request data (any client can send any value) | Becomes the CSP nonce of the answer to that same request | `page_nonce_from_headers` (`citry/_page_nonce.py:48`) returns `None` unless the value is CSP base64 of at most 256 characters, so it cannot break out of an attribute. A forged value only reaches the forger's own answer, where the forger's page refuses the fragment. A cross-origin page cannot set the header without a CORS preflight. A shared cache is the one way an answer reaches another visitor, so every Events answer lists `X-Citry-Page-Nonce` in `Vary`, and an answer to a call that sent the header also gets `Cache-Control: no-store` (`_with_page_nonce_marks`, `citry/ext/events/routes.py:950`; the fallback is `_page_csp_nonce`, `citry/ext/events/dispatcher.py:408`). The docs tell hosts and custom transports to do the same. The browser runtime never puts the nonce on a fragment itself; `Citry.pageNonce()` (`citry/_vue/client.js:6190`) only reads it, and only for code already running. | `docs/security.md`, "Nonces in fragments" |
+| `js_data()` values | Request data OK | JSON data | `_json_plain` (`citry/_vue/json_data.py:_json_plain`: exact JSON types, `Secret` refused), then `script_json` (`citry/util/html.py:script_json`). Same on Vue pages, Events `Render`, and cached renders. What the component's own Vue template then does with the value (`v-html`) is section 7. | `docs/vue/component-options.md#seed-browser-data-from-python` |
+| `js_data()` top-level keys | Request data OK, within limits | Instance property names | `_check_js_data_keys` (`citry/component_render.py:_check_js_data_keys`) refuses `$` and `_` prefixes (so `__proto__`) and `citryId`. | `docs/vue/component-options.md#seed-browser-data-from-python` |
+| `css_data()` keys | Request data OK | Custom property names | `validate_css_var_name` (`citry/util/css.py:validate_css_var_name`). | `docs/advanced/js-and-css-dependencies.md#send-values-to-css` |
+| `css_data()` values | Request data OK for staying in one declaration. App code for a `url(...)` value | CSS; `url()` loads a resource | `serialize_css_var_value` (`citry/util/css.py:serialize_css_var_value`) refuses anything that could leave the declaration and writes every character outside printable ASCII as a CSS escape. Called for inline `` without checking its scheme. | `docs/advanced/dependency-files.md#add-a-library-url` |
+| `Dependencies` entry with `__html__` (a ready-made tag) | App code | Markup | Inserted raw (`citry/ext/dependencies/emission.py:_prerendered`); refused in fragments, on Vue pages, and with a nonce or Citry SRI. | `docs/advanced/dependency-files.md#a-ready-made-tag` |
+| `Script(url=, content=, attrs=)`, `Style(...)` in `Dependencies`, `Component.on_dependencies()`, or the `on_dependencies` hook | App code | Runs / CSS | `content` checked by `_check_validity`; `attrs` names by `validate_html_attr_name`, values escaped. A `url` that is a `str` subclass, such as Django's `SafeString`, is stored as a plain `str` when it is set (`Dependency.__setattr__`, `citry/ext/dependencies/types.py:Dependency.__setattr__`): its text, or for a value with `__html__` that text with its character references decoded, as every attribute writer reads it (`_plain_url_text`, `citry/ext/dependencies/types.py:_plain_url_text`). So the escaping, the `javascript:` URL check that `security_javascript` runs (`_sanitize_structured_attributes`, `citry/_javascript_policy.py:_sanitize_structured_attributes`), and the serialization check that the written `src` or `href` matches `url` all read the text the page gets; the safe mark is not trusted. With `security_javascript` off there is no scheme check; an `on*` key in `attrs` is allowed. | `docs/advanced/dependency-files.md#customize-the-tag` and the `Script` / `Style` docstrings |
+| `serialize(csp_nonce=)`, Events `_csp_nonce` | App code (syntax-checked, so a bad value cannot break out) | Lets scripts run under the CSP | `_validate_csp_nonce` (`citry/serialize.py:_validate_csp_nonce`, CSP base64 only), then added to every structured tag after the dependency hooks (`citry/_serialization_security.py:_apply_nonce`), the fragment loader, and the Vue data. Tags written in a template never get it. | `docs/security.md#apply-a-request-csp-nonce-centrally` |
+| `X-Citry-Page-Nonce` request header, read by `page_nonce_from_headers()` and by an Events `Render` when the app sets no `_csp_nonce` | Request data (any client can send any value) | Becomes the CSP nonce of the answer to that same request | `page_nonce_from_headers` (`citry/_page_nonce.py:page_nonce_from_headers`) returns `None` unless the value is CSP base64 of at most 256 characters, so it cannot break out of an attribute. A forged value only reaches the forger's own answer, where the forger's page refuses the fragment. A cross-origin page cannot set the header without a CORS preflight. A shared cache is the one way an answer reaches another visitor, so every Events answer lists `X-Citry-Page-Nonce` in `Vary`, and an answer to a call that sent the header also gets `Cache-Control: no-store` (`_with_page_nonce_marks`, `citry/ext/events/routes.py:_with_page_nonce_marks`; the fallback is `_page_csp_nonce`, `citry/ext/events/dispatcher.py:_page_csp_nonce`). The docs tell hosts and custom transports to do the same. The browser runtime never puts the nonce on a fragment itself; `Citry.pageNonce()` (`citry/_vue/client.js:pageNonce`) only reads it, and only for code already running. | `docs/security.md#html-fragments` |
## 7. Vue and translated text
@@ -257,14 +263,14 @@ The rows below are about what the template author writes around them.
| Input | Who may supply it | Browser | What Citry does, and where | Docs |
|---|---|---|---|---|
-| Any Vue directive or binding written in the template (`v-if`, `@click`, `:x`, `v-model`) | Author only | Compiled and run as JavaScript | Compiled from template source (`crates/citry_core_py/src/vue.rs:13`). Python data cannot reach a directive: values are JSON references, Vue-code names from data are refused (2.2), and bindings on component tags must be plain authored text (`citry/nodes/__init__.py:2165-2177`). | `docs/vue/csp.md:80-83` |
-| Value bound with `v-html`, `:innerHTML`, `:outerHTML`, or a `.prop` modifier | App code (never request data unless the app sanitized it) | Markup | Passed to Vue unchanged; the HTML the server writes does not contain the value, so the output checks never see it (`vc/server_render.rs:3509-3510`, `:4151`). | `docs/vue/slots.md:147-154`; added by this change: `docs/syntax/vue.md` |
-| Value bound with `:srcdoc`, `:href`, `:src`, `:action`, `:formaction` | App code (check the scheme on the server) | Page / navigates / loads | Passed through; the server renderer writes it as escaped text, so the output checks read only the HTML sent to the browser, not a value Vue sets later. | `docs/vue/slots.md:147-154`; added by this change: `docs/syntax/vue.md` |
-| Value bound with a lowercase `:onclick` (not `@click`) | Author only; never data | Runs | Vue writes a string as an inline handler; the server renderer leaves every `on*` name to the browser (`vc/server_render.rs:1576`). | `docs/syntax/vue.md` |
+| Any Vue directive or binding written in the template (`v-if`, `@click`, `:x`, `v-model`) | Author only | Compiled and run as JavaScript | Compiled from template source (`crates/citry_core_py/src/vue.rs:compile_vue`). Python data cannot reach a directive: values are JSON references, Vue-code names from data are refused (2.2), and bindings on component tags must be plain authored text (`citry/nodes/__init__.py:ComponentNode._resolve_inputs.apply_client_binding`). | `docs/vue/csp.md#c-bind-never-carries-vue-code` |
+| Value bound with `v-html`, `:innerHTML`, `:outerHTML`, or a `.prop` modifier | App code (never request data unless the app sanitized it) | Markup | Passed to Vue unchanged; the HTML the server writes does not contain the value, so the output checks never see it (`vc/server_render.rs:Writer::record_form_names`, `vc/server_render.rs:StaticWriter::element`). | `docs/vue/slots.md#scoped-slots`; added by this change: `docs/syntax/vue.md` |
+| Value bound with `:srcdoc`, `:href`, `:src`, `:action`, `:formaction` | App code (check the scheme on the server) | Page / navigates / loads | Passed through; the server renderer writes it as escaped text, so the output checks read only the HTML sent to the browser, not a value Vue sets later. | `docs/vue/slots.md#scoped-slots`; added by this change: `docs/syntax/vue.md` |
+| Value bound with a lowercase `:onclick` (not `@click`) | Author only; never data | Runs | Vue writes a string as an inline handler; the server renderer leaves every `on*` name to the browser (`vc/server_render.rs:dom_answer`). | `docs/syntax/vue.md` |
| Value bound with `:style` | App code | CSS | Vue applies a style object or string as it is, so a `url()` in it loads a resource. | `docs/syntax/vue.md` |
-| Value bound to `` | App code (map a request value through your own list) | A component, or a native element of that name | Passed to Vue unchecked; `is` picks the component (`vc/hydration.rs:1430`) and is not compared with the tags `` refuses. A string that Vue cannot resolve as a component makes Vue create a native element of that name: the bundled `resolveDynamicComponent` returns the string itself when no component matches (`citry/_vue/vue.js`). Read from the source, not tested in a browser. | `docs/syntax/vue.md` |
-| Object `v-bind="obj"` written by the author | Keys: app code. Values: as the key means | Sets attributes, DOM properties, listeners | Passed through; combining it with Python attributes on one element is refused (`citry/_vue/direct_capture.py:3473-3477`). | `docs/vue/slots.md:156-161` |
-| Strings in the Vue page data | Request data OK | JSON data | `script_json` (`citry/util/html.py:614`); Rust-written rows use the same escapes (`crates/citry_native_render/src/json.rs:14`). | Internal |
+| Value bound to `` | App code (map a request value through your own list) | A component, or a native element of that name | Passed to Vue unchecked; `is` picks the component (`vc/hydration.rs:component_attributes`) and is not compared with the tags `` refuses. A string that Vue cannot resolve as a component makes Vue create a native element of that name: the bundled `resolveDynamicComponent` returns the string itself when no component matches (`citry/_vue/vue.js`). Read from the source, not tested in a browser. | `docs/syntax/vue.md` |
+| Object `v-bind="obj"` written by the author | Keys: app code. Values: as the key means | Sets attributes, DOM properties, listeners | Passed through; combining it with Python attributes on one element is refused (`citry/_vue/direct_capture.py:assemble_typed_render.transform_component.transform_parts`). | `docs/vue/slots.md#scoped-slots` |
+| Strings in the Vue page data | Request data OK | JSON data | `script_json` (`citry/util/html.py:script_json`); Rust-written rows use the same escapes (`crates/citry_native_render/src/json.rs:write_json_str`). | Internal |
### 7.2 Translated text
@@ -273,19 +279,19 @@ translators. Placeholder values are typed data. On a Vue page with the i18n
extension configured, Vue does not take over the server's HTML: the server
writes the HTML, and Vue builds the page again in the browser, so the
browser-built path is the one that shows translated text (`_hydration_page_reason`,
-`citry/_vue/serialization.py:384`; `docs/vue/server-rendering.md:204-208`).
+`citry/_vue/serialization.py:_hydration_page_reason`; `docs/vue/server-rendering.md#pages-vue-replaces-instead-of-adopting`).
| Input | Who may supply it | Browser | What Citry does, and where | Docs |
|---|---|---|---|---|
-| Message text (`messages`, `messages_file`, catalog `.ftl` files) | Author only | Text | Compiled by `crates/citry_i18n`; bidi controls refused; escaped where shown. | `docs/i18n/messages.md:71-77`, `docs/i18n/catalogs.md:73-77` |
-| `tr()` result in a template | Message: author. Result: request data OK as text | Text | A plain `str` (`citry/ext/i18n/extension.py:2082`), so `{{ }}` and attribute escaping apply. A `tr()` result in a URL attribute is not scheme-checked (2.3). | `docs/i18n/index.md:65`; `docs/i18n/rich-messages.md:70-78`; `docs/i18n/rich-messages.md:94-102` |
+| Message text (`messages`, `messages_file`, catalog `.ftl` files) | Author only | Text | Compiled by `crates/citry_i18n`; bidi controls refused; escaped where shown. | `docs/i18n/messages.md#add-messages`, `docs/i18n/catalogs.md#add-translations` |
+| `tr()` result in a template | Message: author. Result: request data OK as text | Text | A plain `str` (`citry/ext/i18n/extension.py:I18nExtension.tr`), so `{{ }}` and attribute escaping apply. A `tr()` result in a URL attribute is not scheme-checked (2.3). | `docs/i18n/index.md#write-messages`; `docs/i18n/rich-messages.md#check-a-url-from-a-message`; `docs/i18n/rich-messages.md#text-stays-escaped` |
| `I18nService.tr()` / `resolve()` and `I18nExtension.tr()` / `resolve()` in Python | Message: author | Whatever the caller does | Return unescaped text; the caller escapes it if it builds HTML in Python. | docstrings in `citry/ext/i18n/extension.py` |
-| Placeholder values (`tr("id", name=value)`, ``, `fmt.*`) | Request data OK | Text | `_tag_value` (`citry/ext/i18n/extension.py:2592`) accepts only exact `str`, `int`, finite `Decimal`, aware `datetime` (so not `Markup`). A value that holds a bidi control character (such as U+202E or U+2068) or a paragraph break (`\n`, `\r`, U+2029 and others) is refused (`validate_tagged_arg`, `crates/citry_i18n/src/compiler.rs:3955`), and the browser runtime refuses the same text (`js/citry-i18n-runtime.ts:426`). | `docs/i18n/messages.md:76-77`; `docs/i18n/direction-and-bidi.md:151-155` |
-| `` text segments and fills | Segments: request data OK (escaped). Fills: author | Text / markup | `make_trans_component` (`citry/ext/i18n/components.py:266`) escapes each segment with `{{ }}` and places each fill as a slot. | `docs/i18n/rich-messages.md:80-92` |
-| `I18nExtension.resolve_rich()` segments | The caller escapes | Whatever the caller does | Returns raw segments (`citry/ext/i18n/extension.py:2179`). | Docstring `:2197` ("Nothing in them is escaped") |
-| Locale (`make_context(locale=)`, ``), `direction`, `time_zone` | Request data OK | `lang` / `dir` attributes; keys | `_canonical_allowed_locale` (`citry/ext/i18n/extension.py:2303`) allows only configured locales; `direction` is `ltr` or `rtl`; `load_time_zone` (`citry/ext/i18n/timezone.py:20`) reads only bundled tzdata. A cached render re-checks the locale and direction. | `docs/i18n/locale-context.md:78-81` |
-| `$c-tr` binding name and values expression | Author only | Picks a message and an allowed attribute; the expression runs | `parse_i18n_binding_name` (`citry/_i18n_directives.py:59`) allows eight text attributes; data cannot add a binding (`citry/ext/i18n/bindings.py:363`); a cached render accepts only expressions a live template wrote (`citry/ext/cache/replay.py:1047`). | `docs/i18n/browser.md:156-158`, `:396-401` |
-| Message ids, format profile names and parser names in the browser runtime | Message ids: author; page code may also pass data, as in "Load IDs from variables". Profile and parser names: app code | Keys | Looked up as own keys only (`ownValue` in `js/citry-i18n-core.ts`, used by `js/citry-i18n-runtime.ts`, `js/citry-i18n-core.ts` and `js/citry-i18n-vue.ts`), so `__proto__` or `constructor` fails like any unknown name. Nothing these lookups find is run as code or inserted as markup. | `docs/i18n/formatting.md:266-267` |
+| Placeholder values (`tr("id", name=value)`, ``, `fmt.*`) | Request data OK | Text | `_tag_value` (`citry/ext/i18n/extension.py:I18nExtension._tag_value`) accepts only exact `str`, `int`, finite `Decimal`, aware `datetime` (so not `Markup`). A value that holds a bidi control character (such as U+202E or U+2068) or a paragraph break (`\n`, `\r`, U+2029 and others) is refused (`validate_tagged_arg`, `crates/citry_i18n/src/compiler.rs:validate_tagged_arg`), and the browser runtime refuses the same text (`js/citry-i18n-runtime.ts:createI18nWireRuntime.argumentValue`). | `docs/i18n/messages.md#add-messages`; `docs/i18n/direction-and-bidi.md#line-breaks-in-values` |
+| `` text segments and fills | Segments: request data OK (escaped). Fills: author | Text / markup | `make_trans_component` (`citry/ext/i18n/components.py:make_trans_component`) escapes each segment with `{{ }}` and places each fill as a slot. | `docs/i18n/rich-messages.md#text-stays-escaped` |
+| `I18nExtension.resolve_rich()` segments | The caller escapes | Whatever the caller does | Returns raw segments (`citry/ext/i18n/extension.py:I18nExtension.resolve_rich`). | Docstring `citry/ext/i18n/extension.py:I18nExtension.resolve_rich` ("Nothing in them is escaped") |
+| Locale (`make_context(locale=)`, ``), `direction`, `time_zone` | Request data OK | `lang` / `dir` attributes; keys | `_canonical_allowed_locale` (`citry/ext/i18n/extension.py:I18nExtension._canonical_allowed_locale`) allows only configured locales; `direction` is `ltr` or `rtl`; `load_time_zone` (`citry/ext/i18n/timezone.py:load_time_zone`) reads only bundled tzdata. A cached render re-checks the locale and direction. | `docs/i18n/locale-context.md#create-a-context` |
+| `$c-tr` binding name and values expression | Author only | Picks a message and an allowed attribute; the expression runs | `parse_i18n_binding_name` (`citry/_i18n_directives.py:parse_i18n_binding_name`) allows eight text attributes; data cannot add a binding (`citry/ext/i18n/bindings.py:I18nBindingElementAttrsNode.render`); a cached render accepts only expressions a live template wrote (`citry/ext/cache/replay.py:_require_authored_values_expression`). | `docs/i18n/browser.md#translate-server-text`, `docs/i18n/browser.md#keep-the-server-text` |
+| Message ids, format profile names and parser names in the browser runtime | Message ids: author; page code may also pass data, as in "Load IDs from variables". Profile and parser names: app code | Keys | Looked up as own keys only (`js/citry-i18n-core.ts:ownValue`, used by `js/citry-i18n-runtime.ts`, `js/citry-i18n-core.ts` and `js/citry-i18n-vue.ts`), so `__proto__` or `constructor` fails like any unknown name. Nothing these lookups find is run as code or inserted as markup. | `docs/i18n/formatting.md#name-and-kind-errors` |
## 8. Events actions
@@ -294,16 +300,16 @@ OK are checked by Citry on the server and again in the browser.
| Input | Who may supply it | Browser | What Citry does, and where | Docs |
|---|---|---|---|---|
-| `Redirect(url=)` | Request data OK for the scheme and the header. App code for the destination: the app checks a URL from the request with `local_url_or()` or `is_local_url()` (`citry/ext/events/local_urls.py`), which accept only a relative URL or an `http`/`https` URL on a host the app lists, read as a browser reads it | Navigates | `Redirect.__post_init__` (`citry/ext/events/actions.py:436`) refuses controls and any scheme other than `http`/`https`, read the way the WHATWG URL parser reads it (`redirect_url_scheme`, `:375`, which calls the one scheme reader every server-side check shares: `url_scheme` in `crates/citry_html_transform/src/url_scheme.rs`, through `citry/_urls.py`). The resolver for the no-JavaScript form path reads the scheme through the same reader (`_resolve_redirect_url`, `citry/ext/events/routes.py:773`) and resolves a URL that depends on the page against a same-host `Referer`, as the browser runtime resolves it against the page: a URL with no scheme, or one such as `http:next` that has the page's own scheme and no `/` or `\` after the colon. The browser checks the scheme again (`navigateToRedirect`, `citry/_vue/client.js:172`) and throws on a refused one, so `Citry.events.applyActions` rejects and a sent call fails. Without JavaScript, `_encode_location` (`citry/ext/events/routes.py:923`) leaves only printable ASCII in the `Location` header. | `docs/events/actions.md:403`; `docs/security.md:366` |
-| `PushUrl(url=)`, `ReplaceUrl(url=)` | Request data OK (the browser refuses another origin). App code for which same-origin path is shown | Changes the address bar | Server checks only a non-empty string (`citry/ext/events/actions.py:477`, `:506`). The browser resolves against the page address (`citry/_vue/client.js:156`) and the History API refuses another origin. Never applied without JavaScript. | `docs/events/actions.md:453-476` |
-| `Render(element=, target=, swap=)` | `element`: section 1 rules. `target`, `swap`: request data OK | Markup | `Render.__post_init__` (`citry/ext/events/actions.py:172`) checks `target` with `validate_render_id` or `validate_mark_name` and `swap` against a fixed set; the browser checks again, for server results at `citry/_vue/client.js:4087-4093` and for `applyActions` at `:662-664`. | `docs/events/actions.md:27-128` |
-| `Dispatch(name=, detail=)` | `name`: app code (pick it from your own list; never copy it from a request). `detail`: request data OK as JSON | A `CustomEvent` that cannot be cancelled, fired at the component's first element; it bubbles | `Dispatch.__post_init__` (`citry/ext/events/actions.py`) refuses an empty name, a standard DOM event name such as `click` or `submit` (`DOM_EVENT_NAMES` in `citry/_html_attribute_values.py`), and a name starting with `citry:`, `vue:` or `vnode-`, ignoring ASCII letter case (`reserved_event_name_reason`). The browser refuses the same names before it fires the event, on every path (`refuseReservedEventName` in `citry/_vue/client.js`, called from `applyPublicActionsWithoutApp` and from the Events bridge's `dispatchEvent` and `dispatchEventGlobal`), from a copy of the list the generator writes. Request data that picks among the app's own custom names still picks which of the app's listeners run, so the name stays app code. `detail` is strict JSON. Decided in [#704](https://github.com/citry-dev/citry/issues/704). | `docs/events/actions.md` ("`Dispatch` browser events") and the `Dispatch` docstring |
-| `Data(value=)`, a returned `dict` | Request data OK | JSON | Strict JSON (`_encode_envelope`, `citry/ext/events/routes.py:579`). | `docs/events/actions.md:319-346` |
-| `Download(content=, filename=, content_type=)` | `content`, `filename`: request data OK. `content_type`: app code | Saved as a file | `Download.__post_init__` (`citry/ext/events/actions.py:571`) refuses paths, controls, and bidi characters in `filename`, and anything outside printable ASCII in `content_type`; `_download_content_disposition` (`:604`) writes an `attachment` header. | `docs/events/actions.md:478-508` |
-| `RouteResponse` from an `@event(bundle=False)` handler | App code | As its `content_type` says | Sent from the per-event route only (`citry/ext/events/dispatcher.py:1596`); the adapters add `nosniff` and a UTF-8 charset (`citry/util/routing.py:316`, `:332`) but do not check header values for line breaks. | `RouteResponse` docstring (`citry/util/routing.py`); `docs/events/actions.md` ("Send your own response") |
-| `on_event` hook return (Events extension) | Extension code | As the handler's result | A value other than `None` answers the call in place of the handler (`citry/ext/events/dispatcher.py:1404`) and goes through the same result encoding as a handler return. | Docstrings in `citry/ext/events/extension.py` |
-| `on_event_error` hook return (Events extension) | Extension code | Error JSON | Used only when it is a valid error result (`_normalize_error_hook_result`, `citry/ext/events/dispatcher.py:2149`); anything else is ignored. | Docstrings in `citry/ext/events/extension.py` |
-| `on_event_result` hook return (experimental) | Extension code | As the action kind | `_validate_hook_actions` (`citry/ext/events/dispatcher.py:1797`) checks the wire shape, not the `Redirect` scheme; the browser still checks the scheme, the no-JavaScript 303 does not. | Experimental |
+| `Redirect(url=)` | Request data OK for the scheme and the header. App code for the destination: the app checks a URL from the request with `citry/ext/events/local_urls.py:local_url_or` or `citry/ext/events/local_urls.py:is_local_url`, which accept only a relative URL or an `http`/`https` URL on a host the app lists, read as a browser reads it | Navigates | `Redirect.__post_init__` (`citry/ext/events/actions.py:Redirect.__post_init__`) refuses controls and any scheme other than `http`/`https`, read the way the WHATWG URL parser reads it (`redirect_url_scheme`, `citry/ext/events/actions.py:redirect_url_scheme`, which calls the one scheme reader every server-side check shares: `crates/citry_html_transform/src/url_scheme.rs:url_scheme`, through `citry/_urls.py:url_scheme`). The resolver for the no-JavaScript form path reads the scheme through the same reader (`_resolve_redirect_url`, `citry/ext/events/routes.py:_resolve_redirect_url`) and resolves a URL that depends on the page against a same-host `Referer`, as the browser runtime resolves it against the page: a URL with no scheme, or one such as `http:next` that has the page's own scheme and no `/` or `\` after the colon. The browser checks the scheme again (`navigateToRedirect`, `citry/_vue/client.js:navigateToRedirect`) and throws on a refused one, so `Citry.events.applyActions` rejects and a sent call fails. Without JavaScript, `_encode_location` (`citry/ext/events/routes.py:_encode_location`) leaves only printable ASCII in the `Location` header. | `docs/events/actions.md#redirect-to-a-page`; `docs/security.md#check-redirect-urls` |
+| `PushUrl(url=)`, `ReplaceUrl(url=)` | Request data OK (the browser refuses another origin). App code for which same-origin path is shown | Changes the address bar | Server checks only a non-empty string (`citry/ext/events/actions.py:PushUrl.__post_init__`, `citry/ext/events/actions.py:ReplaceUrl.__post_init__`). The browser resolves against the page address (`citry/_vue/client.js:resolveOnPage`) and the History API refuses another origin. Never applied without JavaScript. | `docs/events/actions.md#change-the-url` |
+| `Render(element=, target=, swap=)` | `element`: section 1 rules. `target`, `swap`: request data OK | Markup | `Render.__post_init__` (`citry/ext/events/actions.py:Render.__post_init__`) checks `target` with `validate_render_id` or `validate_mark_name` and `swap` against a fixed set; the browser checks again, for server results at `citry/_vue/client.js:startPreparedOwned.host.preflightResult` and for `applyActions` at `citry/_vue/client.js:assertPublicActionList`. | `docs/events/actions.md#re-render-the-component`, `docs/events/actions.md#keep-list-items-matched-to-their-records`, `docs/events/actions.md#swap-in-a-different-component`, `docs/events/actions.md#update-one-part-of-the-page` |
+| `Dispatch(name=, detail=)` | `name`: app code (pick it from your own list; never copy it from a request). `detail`: request data OK as JSON | A `CustomEvent` that cannot be cancelled, fired at the component's first element; it bubbles | `citry/ext/events/actions.py:Dispatch.__post_init__` refuses an empty name, a standard DOM event name such as `click` or `submit` (`citry/_html_attribute_values.py:DOM_EVENT_NAMES`), and a name starting with `citry:`, `vue:` or `vnode-`, ignoring ASCII letter case (`reserved_event_name_reason`). The browser refuses the same names before it fires the event, on every path (`citry/_vue/client.js:refuseReservedEventName`, called from `applyPublicActionsWithoutApp` and from the Events bridge's `dispatchEvent` and `dispatchEventGlobal`), from a copy of the list the generator writes. Request data that picks among the app's own custom names still picks which of the app's listeners run, so the name stays app code. `detail` is strict JSON. Decided in [#704](https://github.com/citry-dev/citry/issues/704). | `docs/events/actions.md#notify-browser-code-that-something-happened` and the `Dispatch` docstring |
+| `Data(value=)`, a returned `dict` | Request data OK | JSON | Strict JSON (`_encode_envelope`, `citry/ext/events/routes.py:_encode_envelope`). | `docs/events/actions.md#send-data-to-javascript` |
+| `Download(content=, filename=, content_type=)` | `content`, `filename`: request data OK. `content_type`: app code | Saved as a file | `Download.__post_init__` (`citry/ext/events/actions.py:Download.__post_init__`) refuses paths, controls, and bidi characters in `filename`, and anything outside printable ASCII in `content_type`; `_download_content_disposition` (`citry/ext/events/actions.py:_download_content_disposition`) writes an `attachment` header. | `docs/events/actions.md#download-a-file` |
+| `RouteResponse` from an `@event(bundle=False)` handler | App code | As its `content_type` says | Sent from the per-event route only (`citry/ext/events/dispatcher.py:EventsDispatcher._escape_route_response`); the adapters add `nosniff` and a UTF-8 charset (`citry/util/routing.py:_NOSNIFF_HEADER`, `citry/util/routing.py:sent_content_type`) but do not check header values for line breaks. | `RouteResponse` docstring (`citry/util/routing.py:RouteResponse`); `docs/events/actions.md#send-your-own-response` |
+| `on_event` hook return (Events extension) | Extension code | As the handler's result | A value other than `None` answers the call in place of the handler (`citry/ext/events/dispatcher.py:EventsDispatcher._prepare_call`) and goes through the same result encoding as a handler return. | Docstrings in `citry/ext/events/extension.py` |
+| `on_event_error` hook return (Events extension) | Extension code | Error JSON | Used only when it is a valid error result (`_normalize_error_hook_result`, `citry/ext/events/dispatcher.py:EventsDispatcher._normalize_error_hook_result`); anything else is ignored. | Docstrings in `citry/ext/events/extension.py` |
+| `on_event_result` hook return (experimental) | Extension code | As the action kind | `_validate_hook_actions` (`citry/ext/events/dispatcher.py:EventsDispatcher._validate_hook_actions`) checks the wire shape, not the `Redirect` scheme; the browser still checks the scheme, the no-JavaScript 303 does not. | Experimental |
## 9. Events requests
@@ -312,27 +318,27 @@ page by Citry itself; it is listed because it decides what a handler sees.
| Input | Who may supply it | What Citry does, and where | Docs |
|---|---|---|---|
-| Handler name and component class id | Request data OK | Citry looks both names up in a dictionary and never calls `getattr` (`_resolve_handler`, `citry/ext/events/routes.py:627`). Every public `def` on the `Events` class, and on any class it inherits from other than Citry's own `Events` and `ViewEvents` bases, becomes a handler that any request can call by name (`collect_event_handlers`, `citry/ext/events/handlers.py:738`; the skipped classes are `_FRAMEWORK_CLASSES`, `:105`, and a base class that Citry ships joins them through `framework_base`, `:708`, as `ViewEvents` does at `citry/ext/events/view_events.py:61`). A handler accepts only `POST` unless it lists other methods, and a request with another method gets 405 (`citry/ext/events/routes.py:389`). | `docs/events/routes.md:14-23`. The rule for inherited classes: Missing |
-| Event data, body size, form field count | Request data OK | `decode_request` (`citry/ext/events/codecs.py:336`), schema binding, size and field limits in `_prepare_dispatch` (`citry/ext/events/routes.py:352`). A `Decimal` whose size is 1e309 or more, or that has more than 308 decimal places, is refused (`request_decimal_in_range`, `citry/util/decimals.py:105`). Citry's own coercion checks it in `_coerce` (`citry/ext/events/schemas.py:1465`); the result of a Pydantic model or Pydantic dataclass is walked by `find_oversized_decimal` (`citry/util/decimals.py:139`) in `_without_oversized_decimals` (`citry/ext/events/schemas.py:747`), the finished arguments are walked once more when an earlier walk may have skipped an object that code changed later (`citry/ext/events/schemas.py:356`), and the items of an `Iterable[...]` field are checked in `_read_items_now` (`citry/ext/events/_pydantic_bounded.py:1238`). All answer the 422 `invalid_args` error. A Pydantic validator sees the value before this check runs, and the walk does not read into app classes, so an app type that wraps a `Decimal` is not checked. | `docs/security.md:750-811`, `:862-885` |
-| CSRF | Request data (any site can send one) | `build_csrf_check` (`citry/ext/events/csrf.py:201`). A `GET` call skips every check (`:221`). Every other method, `HEAD` and `OPTIONS` included, gets Citry's own header checks (`enforce_floor`, `:150`: the `X-Citry-Events` header on a JSON body, `Origin`, `Sec-Fetch-Site`) and then the handler's own `csrf` function, if it has one. That function must be a plain function: `validate_csrf_value` (`citry/ext/events/handlers.py:312`) refuses an `async def` or generator one at class definition, and a call whose function still returns a coroutine, another awaitable, a generator or an async generator answers `csrf_failed`. A `HEAD` request has no body, so the `X-Citry-Events` check does not apply to it, and on a plain-http site a `HEAD` request that another site's script sends can carry neither `Origin` nor `Sec-Fetch-Site`. Django's token check also skips `HEAD` and `OPTIONS`, as it skips `GET`, so a handler that accepts `HEAD`, including a `ViewEvents` `head` method, must not change anything. The `Origin` check compares the host and port with `Host`, and on a request the adapter reports as https (`RouteRequest.scheme`, from the ASGI scope, `wsgi.url_scheme`, or Django's `request.scheme`) it also refuses an `Origin` that is not `https:` (`citry/ext/events/csrf.py:193`), so an `http://` page on the same host cannot call an https app even from a client that sends no `Sec-Fetch-Site`. An http request does not compare schemes, so a proxy that ends TLS keeps working. An `Origin` that `urlsplit` cannot read is refused. Tests: `packages/py/citry/tests/test_events_origin_scheme.py`. | `docs/security.md:483-748`. The `HEAD` rule: Missing |
-| Event guards and `_context` (`_guard` and `_context` on `Events`, `@event(guard=...)`, `@event(component_guard=False)`, or `extensions_defaults["events"]`) | The functions and `component_guard`: app code only. The call they check: request data | `_compute_info` (`citry/ext/events/extension.py:843`) gives each handler the component-level guard (the component's `_guard`, else the engine default) and its own `@event(guard=...)`, and the dispatcher (`citry/ext/events/dispatcher.py:1410-1442`) runs `_context`, then the component-level guard, then the handler's guard, so a per-handler guard adds a check and never removes the component's. Per handler, only `@event(component_guard=False)`, which accepts only `True` or `False`, skips the component-level guard; a component's `_guard = None` turns the engine default off for all its handlers, and an `on_event` extension hook that answers a call skips every guard. A second `@event(...)` on a function that already has settings, directly, copied by `functools.wraps`, or further down its `__wrapped__` chain, raises at decoration (`refuse_stacked_event`, `citry/ext/events/handlers.py:146`), and a handler that does not carry the settings of a function down its `__wrapped__` chain is refused at class definition (`refuse_hidden_event_settings`, `:184`, called from `citry/ext/events/extension.py:811`), so neither stacking nor a decorator that keeps only `__wrapped__` can drop an inner `guard=`. `_compute_info` copies every `@event` setting (guards, methods, CSRF, timing, `latest_wins`, `bundle`, `detached`) onto the handler when the class is created, and nothing reads them from the function afterwards, so a later change to a shared function cannot change an existing class. A wrapper that keeps neither the inner function's attributes nor `__wrapped__` hides its settings, and that is app code Citry cannot check. A `ViewEvents` verb's HTTP method comes from the class (`verb_handler_methods`, `citry/ext/events/view_events.py:128`), and apart from `@event`, which stores its settings on the function it decorates, Citry writes nothing onto a handler function, so one function used in several classes gets each class's own methods. `validate_callable_value` (`citry/ext/events/handlers.py:495`) refuses an `async def` or generator function, a `functools.partial` of one, and an object whose `__call__` is one, at class definition (at decoration for `@event(guard=...)`), because the dispatcher calls these without awaiting them, so an async guard's check would never run. The dispatcher also refuses, as `handler_error`, a call whose guard returns a coroutine, another awaitable, a generator or an async generator, and a call whose `_context` returns a coroutine (a compiled Cython or mypyc one included). `_apply_guard_result` (`citry/ext/events/dispatcher.py:675`) refuses a call whose guard returns an `EventError` with that error, as if the guard had raised it, and a call whose guard returns any other exception (or an exception class) or any false value other than `None` (`False`, `0`, an empty list or QuerySet) with a 403 and the standard message, so a returned exception's text never reaches the browser; it clears the tracebacks of a returned exception and of every exception chained to it (`__cause__`, `__context__`, an exception group's members) so a shared one does not keep a call's frames. Citry tests a value for true or false once, which runs app code (`__bool__`, `__len__`, a QuerySet's query); when that raises an `EventError`, that error answers, and when it raises anything else, the call answers `handler_error` (500), like a guard that raises. A guard that returns a function or other callable (`return self.can_edit` without the `()`) fails the call with `handler_error` (500) and a log line naming the guard, because the check it names never ran. A guard that returns `None` or `True` lets the call through, and one that returns any other true value lets it through and logs a warning naming the guard. A plain wrapper that calls an async guard and drops its result is app code Citry cannot check. | `docs_site/content/security.md` ("Authorize every event") |
-| CSRF cookie and header names (`_csrf_cookie`, `_csrf_header` in `extensions_defaults["events"]`) | App code only | Choose which cookie the browser runtime reads and which header it sends the value in, to Citry's own routes on the page's origin | `_validate_engine_config_value` (`citry/ext/events/extension.py:97`) with `csrf_name_problem` (`citry/ext/events/csrf.py:112`): HTTP tokens only, no header Citry or the browser sets. Written into the configuration block as `csrfNames`; the runtime checks them again in `adoptServerCsrf` (`citry/_vue/client.js:489`), reads them with own-key lookups, takes them only from a block it trusts (a document block, a fragment with the page's nonce, or one page code loads), and keeps the first block's names. An explicit `Citry.configure({csrf})` wins for each name it sets. | `docs/security.md`, "CSRF cookie and header" |
-| State token | Request data (opaque, signed) | `verify_state_token` (`citry/ext/events/tokens.py:712`): HMAC-SHA256 with a derived key, constant-time comparison, class binding, expiry. After every restore, `oversized_state_decimals` (`citry/ext/events/tokens.py:1476`) checks each State field for a `Decimal` outside the event-data range, so a token signed by an earlier release that holds one is refused with 422 `invalid_args` before the handler runs (`citry/ext/events/dispatcher.py:1278`) and is never signed again. A cached render verifies and re-signs it (`citry/ext/events/cache.py:123-188`), and builds the render afresh when the restored State holds such a value (`citry/ext/events/cache.py:166`). A verified token past half its lifetime (`state_renewal_due`, `citry/ext/events/tokens.py:801`) gets a new token with a full lifetime in a `state` action even when State did not change (`_renewal_wanted` and `_renew_state`, `citry/ext/events/dispatcher.py:1969`, `:1985`). So whoever holds a valid token, a copy included, can keep it alive by calling at least once per half lifetime, even on a component whose handlers only read State. When a handler opts into GET (a handler uses POST unless it lists `methods=("GET",)` or `_methods`) and declares `state`, Citry's browser code sends its token in the `X-Citry-State-Token` header, not in the URL that access logs record; if a server from before 1.3.0 answers `invalid_state` (an answer whose `Vary` does not list the header, or any such answer the browser cannot read `Vary` on), the browser sends the call once more with the token in the query. The server still reads the `_citry_state_token` query parameter, and refuses a call whose header and query carry different tokens with 400 `protocol_mismatch` (`_merge_header_state_token`, `citry/ext/events/codecs.py:304`), so the URL cannot choose a token other than the header's. A token that a client of the app's own, or a page from before 1.3.0, sends in the query can still be read from logs and kept alive the same way. A GET answer lists `X-Citry-State-Token` in `Vary`, and a handler's own cache policy on a call that sent the header keeps only the directives a browser cache follows, behind `private`, with CDN-only cache headers dropped (`_with_cache_marks`, `citry/ext/events/routes.py:482`). | `docs/security.md:24-143`, `:862-885` |
-| `stateUpdates` (writes from `$state` and `:c-*`) | Request data OK | `apply_state_updates` (`citry/ext/events/tokens.py:1035`): only `_model` fields, typed. After a write to a Pydantic State, every field gets the same size check as event data in `_check_state_decimals` (`citry/ext/events/tokens.py:1498`) before the State changes, so a `Decimal` that Pydantic builds from a write, or that a validator or `__post_init__` derives from it, is refused, at the write or at the next call's restore, even when it compares equal to the old value. | `docs/events/state.md:271-276`, `docs/security.md:862-885` |
-| What a guard (`Events._guard`, `@event(guard=...)`, or the app-wide `_guard`) and `Events._context` read: `self.event.args`, `self.state`, `self.request` | The guard functions and `_context`: app code only. The values they read: request data, including State fields the browser may write | `_prepare_call` (`citry/ext/events/dispatcher.py:1110`) runs the `on_event` hook, then `_context`, then the component-level guard and the handler's guard (`:1427-1442`), after it verifies the State token and applies the `stateUpdates` writes and before it checks the args against the handler's `data` class. So `self.event.args` holds the args unchecked (only the host CSRF field names removed): a key may be missing or hold a value of another type. The guards get a shallow copy of the args, so a guard that adds or removes a top-level key does not change what the `data` class checks; a change inside a nested list or dict does. `self.state` already holds the browser's writes to the `_model` fields, every public field by default, so a guard that decides on such a field checks a value the caller chose. Citry does not keep a copy of State from before the writes; the app keeps the fields its guards rely on out of `_model`. A refused call answers with the refusing guard's error before the args are checked, so the answer does not describe the caller's args. A State write the server refuses still answers 422 before the guard runs. | `docs/security.md:247-264`; `docs/events/state.md:271-276` |
-| Sub-path (ASGI `root_path`, WSGI `SCRIPT_NAME`) | App deployment only; it becomes request data when a proxy passes on a client's `X-Forwarded-Prefix` | `normalize_sub_path` (`citry/_sub_path.py:37`) uses the site root for a value that is not a path starting with one `/`, and percent-encodes the rest, so it stays a path on the same site either way. | `docs/advanced/web-frameworks.md:421-441` |
-| `get_event_url(..., query=, fragment=)` | Query and fragment: request data OK | `format_url` (`citry/util/misc.py:175`) encodes them. | `get_event_url` docstring (`citry/ext/events/routes.py:144-145`), shown in the API reference |
+| Handler name and component class id | Request data OK | Citry looks both names up in a dictionary and never calls `getattr` (`_resolve_handler`, `citry/ext/events/routes.py:_resolve_handler`). Every public `def` on the `Events` class, and on any class it inherits from other than Citry's own `Events` and `ViewEvents` bases, becomes a handler that any request can call by name (`collect_event_handlers`, `citry/ext/events/handlers.py:collect_event_handlers`; the skipped classes are `_FRAMEWORK_CLASSES`, `citry/ext/events/handlers.py:_FRAMEWORK_CLASSES`, and a base class that Citry ships joins them through `framework_base`, `citry/ext/events/handlers.py:framework_base`, as `ViewEvents` does at `citry/ext/events/view_events.py:ViewEvents`). A handler accepts only `POST` unless it lists other methods, and a request with another method gets 405 (`citry/ext/events/routes.py:_prepare_dispatch`). | `docs/events/routes.md#protect-every-handler`. The rule for inherited classes: Missing |
+| Event data, body size, form field count | Request data OK | `decode_request` (`citry/ext/events/codecs.py:decode_request`), schema binding, size and field limits in `_prepare_dispatch` (`citry/ext/events/routes.py:_prepare_dispatch`). A `Decimal` whose size is 1e309 or more, or that has more than 308 decimal places, is refused (`request_decimal_in_range`, `citry/util/decimals.py:request_decimal_in_range`). Citry's own coercion checks it in `_coerce` (`citry/ext/events/schemas.py:_coerce`); the result of a Pydantic model or Pydantic dataclass is walked by `find_oversized_decimal` (`citry/util/decimals.py:find_oversized_decimal`) in `_without_oversized_decimals` (`citry/ext/events/schemas.py:_without_oversized_decimals`), the finished arguments are walked once more when an earlier walk may have skipped an object that code changed later (`citry/ext/events/schemas.py:_validate_payload`), and the items of an `Iterable[...]` field are checked in `_read_items_now` (`citry/ext/events/_pydantic_bounded.py:_read_items_now`). All answer the 422 `invalid_args` error. A Pydantic validator sees the value before this check runs, and the walk does not read into app classes, so an app type that wraps a `Decimal` is not checked. | `docs/security.md#limit-event-request-sizes`, `docs/security.md#check-event-data` |
+| CSRF | Request data (any site can send one) | `build_csrf_check` (`citry/ext/events/csrf.py:build_csrf_check`). A `GET` call skips every check (`citry/ext/events/csrf.py:build_csrf_check.check`). Every other method, `HEAD` and `OPTIONS` included, gets Citry's own header checks (`enforce_floor`, `citry/ext/events/csrf.py:enforce_floor`: the `X-Citry-Events` header on a JSON body, `Origin`, `Sec-Fetch-Site`) and then the handler's own `csrf` function, if it has one. That function must be a plain function: `validate_csrf_value` (`citry/ext/events/handlers.py:validate_csrf_value`) refuses an `async def` or generator one at class definition, and a call whose function still returns a coroutine, another awaitable, a generator or an async generator answers `csrf_failed`. A `HEAD` request has no body, so the `X-Citry-Events` check does not apply to it, and on a plain-http site a `HEAD` request that another site's script sends can carry neither `Origin` nor `Sec-Fetch-Site`. Django's token check also skips `HEAD` and `OPTIONS`, as it skips `GET`, so a handler that accepts `HEAD`, including a `ViewEvents` `head` method, must not change anything. The `Origin` check compares the host and port with `Host`, and on a request the adapter reports as https (`RouteRequest.scheme`, from the ASGI scope, `wsgi.url_scheme`, or Django's `request.scheme`) it also refuses an `Origin` that is not `https:` (`citry/ext/events/csrf.py:enforce_floor`), so an `http://` page on the same host cannot call an https app even from a client that sends no `Sec-Fetch-Site`. An http request does not compare schemes, so a proxy that ends TLS keeps working. An `Origin` that `urlsplit` cannot read is refused. Tests: `packages/py/citry/tests/test_events_origin_scheme.py`. | `docs/security.md#protect-event-posts-from-csrf`. The `HEAD` rule: Missing |
+| Event guards and `_context` (`_guard` and `_context` on `Events`, `@event(guard=...)`, `@event(component_guard=False)`, or `extensions_defaults["events"]`) | The functions and `component_guard`: app code only. The call they check: request data | `_compute_info` (`citry/ext/events/extension.py:EventsExtension._compute_info`) gives each handler the component-level guard (the component's `_guard`, else the engine default) and its own `@event(guard=...)`, and the dispatcher (`citry/ext/events/dispatcher.py:EventsDispatcher._prepare_call`) runs `_context`, then the component-level guard, then the handler's guard, so a per-handler guard adds a check and never removes the component's. Per handler, only `@event(component_guard=False)`, which accepts only `True` or `False`, skips the component-level guard; a component's `_guard = None` turns the engine default off for all its handlers, and an `on_event` extension hook that answers a call skips every guard. A second `@event(...)` on a function that already has settings, directly, copied by `functools.wraps`, or further down its `__wrapped__` chain, raises at decoration (`refuse_stacked_event`, `citry/ext/events/handlers.py:refuse_stacked_event`), and a handler that does not carry the settings of a function down its `__wrapped__` chain is refused at class definition (`refuse_hidden_event_settings`, `citry/ext/events/handlers.py:refuse_hidden_event_settings`, called from `citry/ext/events/extension.py:EventsExtension._compute_info`), so neither stacking nor a decorator that keeps only `__wrapped__` can drop an inner `guard=`. `_compute_info` copies every `@event` setting (guards, methods, CSRF, timing, `latest_wins`, `bundle`, `detached`) onto the handler when the class is created, and nothing reads them from the function afterwards, so a later change to a shared function cannot change an existing class. A wrapper that keeps neither the inner function's attributes nor `__wrapped__` hides its settings, and that is app code Citry cannot check. A `ViewEvents` verb's HTTP method comes from the class (`verb_handler_methods`, `citry/ext/events/view_events.py:verb_handler_methods`), and apart from `@event`, which stores its settings on the function it decorates, Citry writes nothing onto a handler function, so one function used in several classes gets each class's own methods. `validate_callable_value` (`citry/ext/events/handlers.py:validate_callable_value`) refuses an `async def` or generator function, a `functools.partial` of one, and an object whose `__call__` is one, at class definition (at decoration for `@event(guard=...)`), because the dispatcher calls these without awaiting them, so an async guard's check would never run. The dispatcher also refuses, as `handler_error`, a call whose guard returns a coroutine, another awaitable, a generator or an async generator, and a call whose `_context` returns a coroutine (a compiled Cython or mypyc one included). `_apply_guard_result` (`citry/ext/events/dispatcher.py:_apply_guard_result`) refuses a call whose guard returns an `EventError` with that error, as if the guard had raised it, and a call whose guard returns any other exception (or an exception class) or any false value other than `None` (`False`, `0`, an empty list or QuerySet) with a 403 and the standard message, so a returned exception's text never reaches the browser; it clears the tracebacks of a returned exception and of every exception chained to it (`__cause__`, `__context__`, an exception group's members) so a shared one does not keep a call's frames. Citry tests a value for true or false once, which runs app code (`__bool__`, `__len__`, a QuerySet's query); when that raises an `EventError`, that error answers, and when it raises anything else, the call answers `handler_error` (500), like a guard that raises. A guard that returns a function or other callable (`return self.can_edit` without the `()`) fails the call with `handler_error` (500) and a log line naming the guard, because the check it names never ran. A guard that returns `None` or `True` lets the call through, and one that returns any other true value lets it through and logs a warning naming the guard. A plain wrapper that calls an async guard and drops its result is app code Citry cannot check. | `docs/security.md#authorize-every-event` |
+| CSRF cookie and header names (`_csrf_cookie`, `_csrf_header` in `extensions_defaults["events"]`) | App code only | Choose which cookie the browser runtime reads and which header it sends the value in, to Citry's own routes on the page's origin | `_validate_engine_config_value` (`citry/ext/events/extension.py:_validate_engine_config_value`) with `csrf_name_problem` (`citry/ext/events/csrf.py:csrf_name_problem`): HTTP tokens only, no header Citry or the browser sets. Written into the configuration block as `csrfNames`; the runtime checks them again in `adoptServerCsrf` (`citry/_vue/client.js:adoptServerCsrf`), reads them with own-key lookups, takes them only from a block it trusts (a document block, a fragment with the page's nonce, or one page code loads), and keeps the first block's names. An explicit `Citry.configure({csrf})` wins for each name it sets. | `docs/security.md#csrf-names` |
+| State token | Request data (opaque, signed) | `verify_state_token` (`citry/ext/events/tokens.py:verify_state_token`): HMAC-SHA256 with a derived key, constant-time comparison, class binding, expiry. After every restore, `oversized_state_decimals` (`citry/ext/events/tokens.py:oversized_state_decimals`) checks each State field for a `Decimal` outside the event-data range, so a token signed by an earlier release that holds one is refused with 422 `invalid_args` before the handler runs (`citry/ext/events/dispatcher.py:EventsDispatcher._prepare_call`) and is never signed again. A cached render verifies and re-signs it (`citry/ext/events/cache.py:stage_events_cache`), and builds the render afresh when the restored State holds such a value (`citry/ext/events/cache.py:stage_events_cache`). A verified token past half its lifetime (`state_renewal_due`, `citry/ext/events/tokens.py:state_renewal_due`) gets a new token with a full lifetime in a `state` action even when State did not change (`_renewal_wanted` and `_renew_state`, `citry/ext/events/dispatcher.py:EventsDispatcher._renewal_wanted`, `citry/ext/events/dispatcher.py:EventsDispatcher._renew_state`). So whoever holds a valid token, a copy included, can keep it alive by calling at least once per half lifetime, even on a component whose handlers only read State. When a handler opts into GET (a handler uses POST unless it lists `methods=("GET",)` or `_methods`) and declares `state`, Citry's browser code sends its token in the `X-Citry-State-Token` header, not in the URL that access logs record; if a server from before 1.3.0 answers `invalid_state` (an answer whose `Vary` does not list the header, or any such answer the browser cannot read `Vary` on), the browser sends the call once more with the token in the query. The server still reads the `_citry_state_token` query parameter, and refuses a call whose header and query carry different tokens with 400 `protocol_mismatch` (`_merge_header_state_token`, `citry/ext/events/codecs.py:_merge_header_state_token`), so the URL cannot choose a token other than the header's. A token that a client of the app's own, or a page from before 1.3.0, sends in the query can still be read from logs and kept alive the same way. A GET answer lists `X-Citry-State-Token` in `Vary`, and a handler's own cache policy on a call that sent the header keeps only the directives a browser cache follows, behind `private`, with CDN-only cache headers dropped (`_with_cache_marks`, `citry/ext/events/routes.py:_with_cache_marks`). | `docs/security.md#treat-state-as-client-input`, `docs/security.md#check-event-data` |
+| `stateUpdates` (writes from `$state` and `:c-*`) | Request data OK | `apply_state_updates` (`citry/ext/events/tokens.py:apply_state_updates`): only `_model` fields, typed. After a write to a Pydantic State, every field gets the same size check as event data in `_check_state_decimals` (`citry/ext/events/tokens.py:_check_state_decimals`) before the State changes, so a `Decimal` that Pydantic builds from a write, or that a validator or `__post_init__` derives from it, is refused, at the write or at the next call's restore, even when it compares equal to the old value. | `docs/events/state.md#model`, `docs/security.md#check-event-data` |
+| What a guard (`Events._guard`, `@event(guard=...)`, or the app-wide `_guard`) and `Events._context` read: `self.event.args`, `self.state`, `self.request` | The guard functions and `_context`: app code only. The values they read: request data, including State fields the browser may write | `_prepare_call` (`citry/ext/events/dispatcher.py:EventsDispatcher._prepare_call`) runs the `on_event` hook, then `_context`, then the component-level guard and the handler's guard (`citry/ext/events/dispatcher.py:EventsDispatcher._prepare_call`), after it verifies the State token and applies the `stateUpdates` writes and before it checks the args against the handler's `data` class. So `self.event.args` holds the args unchecked (only the host CSRF field names removed): a key may be missing or hold a value of another type. The guards get a shallow copy of the args, so a guard that adds or removes a top-level key does not change what the `data` class checks; a change inside a nested list or dict does. `self.state` already holds the browser's writes to the `_model` fields, every public field by default, so a guard that decides on such a field checks a value the caller chose. Citry does not keep a copy of State from before the writes; the app keeps the fields its guards rely on out of `_model`. A refused call answers with the refusing guard's error before the args are checked, so the answer does not describe the caller's args. A State write the server refuses still answers 422 before the guard runs. | `docs/security.md#authorize-every-event`; `docs/events/state.md#model` |
+| Sub-path (ASGI `root_path`, WSGI `SCRIPT_NAME`) | App deployment only; it becomes request data when a proxy passes on a client's `X-Forwarded-Prefix` | `normalize_sub_path` (`citry/_sub_path.py:normalize_sub_path`) uses the site root for a value that is not a path starting with one `/`, and percent-encodes the rest, so it stays a path on the same site either way. | `docs/advanced/web-frameworks.md#serve-below-a-sub-path` |
+| `get_event_url(..., query=, fragment=)` | Query and fragment: request data OK | `format_url` (`citry/util/misc.py:format_url`) encodes them. | `get_event_url` docstring (`citry/ext/events/routes.py:get_event_url`), shown in the API reference |
## 10. Routes and responses
| Route or response | What it serves | Checks, and where | Docs |
|---|---|---|---|
-| Every adapter | Any response | Adds `X-Content-Type-Options: nosniff` unless the response sets that header itself, and `charset=utf-8` to a `text/*` string body (`citry/util/routing.py:316`, `:332`). A 405 for a method the route does not accept names the accepted methods in an `Allow` header (`route_allowed_methods`, `citry/util/routing.py:874`). | `docs/advanced/extensions.md:412-416` |
-| Events response body and errors | JSON, or `text/plain` without JavaScript | Strict JSON; error text that echoes request values is only sent as `text/plain` or JSON with `nosniff`. Exception text appears only when the `citry` logger is at `DEBUG` (`citry/ext/events/dispatcher.py:787`). A `GET` call answers with `Cache-Control: no-store` (`_respond`, `citry/ext/events/routes.py:478`); a `Download` always does (`citry/ext/events/dispatcher.py:1585`). | `docs/security.md:1652-1675` |
-| Runtime files (`citry..js`, `ext/events/definitions/.js`, `ext/events/assets/.css`, i18n runtime) | Citry's own files | Digest must be 64 hex characters; a shared-cache copy is served only if its hash matches (`citry/_hashed_runtime.py:54`, `:172`; `citry/_vue/events.py:419`). These, and their 404s, carry `Access-Control-Allow-Origin: *` (`citry/_owned_resource.py:19`); hashed files are sent as `immutable`. | `docs/security.md:2437-2476` |
-| `cache/..{js,css}`, `asset/` | Component files and the `css_data()` stylesheet | Class must be registered; type from a fixed table; a hash must be hex and a file name `<12 hex>.` whose extension holds only ASCII letters, digits and `._~+-`, up to 128 characters, checked before any lookup; content only from Citry's cache (`citry/ext/dependencies/routes.py:121`, `:173`). A `.js` hash that names no class version always misses, because Citry writes `js_data()` only into the page (`get_script`). A `css_data()` stylesheet is built again from its stored values, and its name must be one this engine's key gives those values (`_rebuild_css_data_stylesheet`), so a guessed value cannot be confirmed except with a configured cache and no secret (section 6). With a configured cache, the page writes each stylesheet it links into the cache again when it is serialized, if the cache no longer holds it (`publish_css_data_stylesheets`, `citry/ext/dependencies/emission.py:1422`). The `ext/events/assets/` copy of that stylesheet is served from a shared cache only when this route would serve the same bytes (`check_css_data_stylesheet_copy`). On both routes a refused name makes the same cache calls as a miss, and an entry that an earlier release left is deleted the first time it is refused (`get_script`, `check_css_data_stylesheet_copy`). Until an operator deletes those entries, the first request for one takes slightly longer than a miss, and so does every request for a copy whose component class this engine does not know (kept, because a worker of another deploy may know it). The `asset/` bytes are not re-hashed when served, so the cache operator is trusted. Successful responses carry `Access-Control-Allow-Origin: *` (`citry/_owned_resource.py:157`, `:165`, `:179`), so any site that has the URL can read a `css_data()` stylesheet; `css_data()` must not return secrets. 404s carry no CORS header. | `docs/security.md:2437-2476` |
-| i18n messages route | Message JSON | 64 KiB, exact fields, allowed locales, known public message ids (`citry/ext/i18n/routes.py:79`). | `docs/i18n/browser.md:227-229` |
-| Preview routes (experimental) | Component previews | Mounted only by the preview command, loopback `Host` and `Origin` only (`citry/ext/preview/host.py:57-87`). | `docs/advanced/previews.md:109-115` |
+| Every adapter | Any response | Adds `X-Content-Type-Options: nosniff` unless the response sets that header itself, and `charset=utf-8` to a `text/*` string body (`citry/util/routing.py:_NOSNIFF_HEADER`, `citry/util/routing.py:sent_content_type`). A 405 for a method the route does not accept names the accepted methods in an `Allow` header (`route_allowed_methods`, `citry/util/routing.py:route_allowed_methods`). | `docs/advanced/extensions.md#serve-extension-routes` |
+| Events response body and errors | JSON, or `text/plain` without JavaScript | Strict JSON; error text that echoes request values is only sent as `text/plain` or JSON with `nosniff`. Exception text appears only when the `citry` logger is at `DEBUG` (`citry/ext/events/dispatcher.py:_debug_enabled`). A `GET` call answers with `Cache-Control: no-store` (`_respond`, `citry/ext/events/routes.py:_respond`); a `Download` always does (`citry/ext/events/dispatcher.py:EventsDispatcher._extract_response_result`). | `docs/security.md#keep-debug-logs-off-in-production` |
+| Runtime files (`citry..js`, `ext/events/definitions/.js`, `ext/events/assets/.css`, i18n runtime) | Citry's own files | Digest must be 64 hex characters; a shared-cache copy is served only if its hash matches (`citry/_hashed_runtime.py:is_content_digest`, `citry/_hashed_runtime.py:HashedRuntime._stored`; `citry/_vue/events.py:_load_asset`). These, and their 404s, carry `Access-Control-Allow-Origin: *` (`citry/_owned_resource.py:PUBLIC_ASSET_CORS_HEADERS`); hashed files are sent as `immutable`. | `docs/security.md#keep-the-cors-header-when-a-proxy-or-cdn-serves-citrys-files` |
+| `cache/..{js,css}`, `asset/` | Component files and the `css_data()` stylesheet | Class must be registered; type from a fixed table; a hash must be hex and a file name `<12 hex>.` whose extension holds only ASCII letters, digits and `._~+-`, up to 128 characters, checked before any lookup; content only from Citry's cache (`citry/ext/dependencies/routes.py:dependency_routes.serve_cached_script`, `citry/ext/dependencies/routes.py:dependency_routes.serve_asset`). A `.js` hash that names no class version always misses, because Citry writes `js_data()` only into the page (`get_script`). A `css_data()` stylesheet is built again from its stored values, and its name must be one this engine's key gives those values (`_rebuild_css_data_stylesheet`), so a guessed value cannot be confirmed except with a configured cache and no secret (section 6). With a configured cache, the page writes each stylesheet it links into the cache again when it is serialized, if the cache no longer holds it (`publish_css_data_stylesheets`, `citry/ext/dependencies/emission.py:publish_css_data_stylesheets`). The `ext/events/assets/` copy of that stylesheet is served from a shared cache only when this route would serve the same bytes (`check_css_data_stylesheet_copy`). On both routes a refused name makes the same cache calls as a miss, and an entry that an earlier release left is deleted the first time it is refused (`get_script`, `check_css_data_stylesheet_copy`). Until an operator deletes those entries, the first request for one takes slightly longer than a miss, and so does every request for a copy whose component class this engine does not know (kept, because a worker of another deploy may know it). The `asset/` bytes are not re-hashed when served, so the cache operator is trusted. Successful responses carry `Access-Control-Allow-Origin: *` (`citry/_owned_resource.py:_OwnedResource.response`, `citry/_owned_resource.py:_OwnedResource.immutable_response`, `citry/_owned_resource.py:_OwnedResource.revalidated_response`), so any site that has the URL can read a `css_data()` stylesheet; `css_data()` must not return secrets. 404s carry no CORS header. | `docs/security.md#keep-the-cors-header-when-a-proxy-or-cdn-serves-citrys-files` |
+| i18n messages route | Message JSON | 64 KiB, exact fields, allowed locales, known public message ids (`citry/ext/i18n/routes.py:_decode_request`). | `docs/i18n/browser.md#load-ids-from-variables` |
+| Preview routes (experimental) | Component previews | Mounted only by the preview command, loopback `Host` and `Origin` only (`citry/ext/preview/host.py:_is_loopback_authority`, `citry/ext/preview/host.py:_is_local_request`). | `docs/advanced/previews.md#browse-the-gallery` |
## 11. Extension hooks, cache, and debug output
@@ -342,29 +348,29 @@ a hook may pass request data through.
| Input | Who may supply it | Browser | What Citry does, and where | Docs |
|---|---|---|---|---|
-| `on_component_rendered()`, `on_slot_rendered()` return | `str`: request data OK. `Markup`: app code | Text / markup | `_text_or_html_part` (`citry/component_render.py:2877`), the same rule as `{{ }}`, on static, Vue, and Events `Render` paths. Hooks do not run on a cache hit; the stored output replays. | `docs/advanced/extensions.md:115-149` |
-| `on_attrs_resolved()` return: names | App code; may not add a code-capable name | Attribute names | `_reject_vue_code_from_attrs_hook` and `_reject_script_capable_from_attrs_hook` (`citry/extension.py:1512`, `:1531`) refuse an added `v-`/`:`/`@`/`on*`/`innerHTML`/`outerHTML`/`srcdoc` name; `validate_html_attr_name` runs on every name (`citry/nodes/__init__.py:1333`, reached from capture at `citry/_vue/capture.py:1230`). | `docs/advanced/extensions.md:167-170` |
-| `on_attrs_resolved()` return: values | App code | Attribute text; URLs navigate; an existing `on*` value runs | Escaped; not scheme-checked. A hook may change the value of an `on*` attribute the template wrote. | `docs/advanced/extensions.md:172-176` |
-| `on_serialize()` return (the whole page) | Extension's own text only | Markup | Used as it is after a type check (`citry/extension.py:2459`); on a Vue page `finalize` refuses a result that changes or removes the element Vue mounts on, reading which elements sit inside it the way a browser does (`citry/_vue/serialization.py:659`). The output checks run after it. | `docs/advanced/extensions.md:148-149`; `docs/advanced/extensions.md:153-165` |
-| `on_template_loaded()`, `on_template_compiled()`, `on_template_foreign_compiled()`, `on_template_foreign_spans()` return | Author only (the hook acts as the template author) | Markup | Parsed or used as authored template source; type checks only (`citry/extension.py:1462-1479`). | `docs/advanced/extensions.md:153-165`; added by this change: the compile hooks named there |
-| `on_js_loaded()`, `on_css_loaded()`, `on_messages_loaded()` return | Author only | Runs / CSS / message text | Used as the component's own `js`, `css`, or messages. | `docs/advanced/extensions.md:153-165`; added by this change: `on_messages_loaded` named there |
-| `on_dependencies` hook (`ctx.scripts`, `ctx.styles`) | App code | Runs / CSS | As `Script` / `Style` in section 6. | `docs/advanced/extensions.md` ("Add scripts and styles") |
-| `on_component_input()`, `on_component_data()` changes | Request data OK to the same degree as the kwarg or variable it fills | As the template uses it | No hook-specific check; the template rules apply. | Docstrings `citry/extension.py:952-966` |
-| `browser_plugin()`, `prepare_browser_render()` (experimental) | Script: app code. `payload`: request data OK as JSON | Runs / JSON | `_validate_plugin` and `_validate_json` (`citry/browser_render.py:280`, `:365`); the payload is written with `script_json`. | Experimental |
-| `Extension.urls` route handlers | App code | As its content type says | The adapter adds `nosniff` and a charset; the body is the handler's choice. | `docs/advanced/extensions.md:412-416` |
-| A stored render-cache entry | Whoever can write the cache store (trusted like the database) | Markup, scripts, CSS | Decoded strictly (`citry/ext/cache/artifact.py:334`, `:360`, `:423`); template text, raw blocks, Vue bindings, dynamic tags, render ids, and the CSS data are checked against this process's live templates on replay (`citry/ext/cache/replay.py:937`, `:1031-1051`). Trusted HTML parts and template-written attribute text replay as stored. The Events State a cached component builds in `state_data()` is stored with its HTML (`citry/ext/events/cache.py:29-60`). Citry itself stores JSON text (`citry/ext/cache/artifact.py:336-353`). A store that unpickles what it reads runs code on the server for anyone who can write to it: most of Django's cache backends behind `DjangoCache` (`citry/contrib/django.py:760`), and a `diskcache` store behind `DiskCache` (`citry/contrib/caches.py:76`). | `docs/performance/caching.md:200-207` ("Protect the cache store like your database"); `docs/security.md:1642-1650`. Unpickling stores: Missing |
-| Cache keys (`Component.Cache`, ``) | Key values (a component's `Kwargs`, `Component.Cache.vary()`, `c-vary`): app code, and they may include request values. A `` `key`, including a `c-key` expression: author only, because the name is shared across the whole app | None directly; a wrong key serves one user's HTML, and the Events State stored with it, to another user | Hashed (`citry/ext/cache/keys.py:188-295`); `Secret` refused as a key part (`:404`). A component's key is its class id plus its `Kwargs`, or the values `vary()` returns (`citry/ext/cache/extension.py:263-293`). A `` key holds the `key`, the `vary` values and the version, but not which template wrote the region (`_lookup_fragment`, `citry/ext/cache/extension.py:310-346`), so two regions with the same `key` share entries. Citry also accepts `c-key`, an expression. | `docs/performance/caching.md:134-137` ("Give it a fixed `key`"), `:181-195` |
-| `export_render_cache()`, `stage_render_cache()`, `render_cache_bypass_reason()` | App code | Through the extension's own output | `render_cache_mode` defaults to `"deny"` (`citry/extension.py:759`), which skips caching for any render a hook touched (`:1794-1797`); a stored payload must be strict JSON (`citry/ext/cache/artifact.py:435`). With `"stateless"`, Citry stores nothing from the extension (`citry/extension.py:1798-1799`) and the hook does not run on a hit, so its output replays as part of the stored HTML. The key holds none of the values the hook read. A stateless hook must add the same output for every request that shares the key. A text replacement that `stage_render_cache()` returns may only swap one i18n binding marker value for another, and every ID in both values must have the shape the i18n extension writes (`is_binding_id`, checked in `citry/ext/cache/replay.py:541`), because replay puts the new value into stored HTML without escaping it again. | `docs/advanced/extensions.md:329-371`. The stateless rule: Missing |
+| `on_component_rendered()`, `on_slot_rendered()` return | `str`: request data OK. `Markup`: app code | Text / markup | `_text_or_html_part` (`citry/component_render.py:_text_or_html_part`), the same rule as `{{ }}`, on static, Vue, and Events `Render` paths. Hooks do not run on a cache hit; the stored output replays. | `docs/advanced/extensions.md#return-text-or-html` |
+| `on_attrs_resolved()` return: names | App code; may not add a code-capable name | Attribute names | `_reject_vue_code_from_attrs_hook` and `_reject_script_capable_from_attrs_hook` (`citry/extension.py:_reject_vue_code_from_attrs_hook`, `citry/extension.py:_reject_script_capable_from_attrs_hook`) refuse an added `v-`/`:`/`@`/`on*`/`innerHTML`/`outerHTML`/`srcdoc` name; `validate_html_attr_name` runs on every name (`citry/nodes/__init__.py:ElementAttrsNode._resolve_for_output`, reached from capture at `citry/_vue/capture.py:PreparedElementOpenNode.render`). | `docs/advanced/extensions.md#keep-hook-output-safe` |
+| `on_attrs_resolved()` return: values | App code | Attribute text; URLs navigate; an existing `on*` value runs | Escaped; not scheme-checked. A hook may change the value of an `on*` attribute the template wrote. | `docs/advanced/extensions.md#keep-hook-output-safe` |
+| `on_serialize()` return (the whole page) | Extension's own text only | Markup | Used as it is after a type check (`citry/extension.py:ExtensionManager.on_serialize`); on a Vue page `finalize` refuses a result that changes or removes the element Vue mounts on, reading which elements sit inside it the way a browser does (`citry/_vue/serialization.py:VueSerializationPlan.finalize`). The output checks run after it. | `docs/advanced/extensions.md#return-text-or-html`; `docs/advanced/extensions.md#keep-hook-output-safe` |
+| `on_template_loaded()`, `on_template_compiled()`, `on_template_foreign_compiled()`, `on_template_foreign_spans()` return | Author only (the hook acts as the template author) | Markup | Parsed or used as authored template source; type checks only (`citry/extension.py:_as_str`, `citry/extension.py:_as_node_list`). | `docs/advanced/extensions.md#keep-hook-output-safe`; added by this change: the compile hooks named there |
+| `on_js_loaded()`, `on_css_loaded()`, `on_messages_loaded()` return | Author only | Runs / CSS / message text | Used as the component's own `js`, `css`, or messages. | `docs/advanced/extensions.md#keep-hook-output-safe`; added by this change: `on_messages_loaded` named there |
+| `on_dependencies` hook (`ctx.scripts`, `ctx.styles`) | App code | Runs / CSS | As `Script` / `Style` in section 6. | `docs/advanced/extensions.md#add-scripts-and-stylesheets-to-a-page` |
+| `on_component_input()`, `on_component_data()` changes | Request data OK to the same degree as the kwarg or variable it fills | As the template uses it | No hook-specific check; the template rules apply. | Docstrings `citry/extension.py:Extension.on_component_input`, `citry/extension.py:Extension.on_component_data` |
+| `browser_plugin()`, `prepare_browser_render()` (experimental) | Script: app code. `payload`: request data OK as JSON | Runs / JSON | `_validate_plugin` and `_validate_json` (`citry/browser_render.py:_validate_plugin`, `citry/browser_render.py:_validate_json`); the payload is written with `script_json`. | Experimental |
+| `Extension.urls` route handlers | App code | As its content type says | The adapter adds `nosniff` and a charset; the body is the handler's choice. | `docs/advanced/extensions.md#serve-extension-routes` |
+| A stored render-cache entry | Whoever can write the cache store (trusted like the database) | Markup, scripts, CSS | Decoded strictly (`citry/ext/cache/artifact.py:_decode_artifact_with_size`, `citry/ext/cache/artifact.py:_validate_typed_artifact`, `citry/ext/cache/artifact.py:_validate_root_marker`); template text, raw blocks, Vue bindings, dynamic tags, render ids, and the CSS data are checked against this process's live templates on replay (`citry/ext/cache/replay.py:_export_typed_leaf`, `citry/ext/cache/replay.py:_require_authored_span`, `citry/ext/cache/replay.py:_require_produced_binding`, `citry/ext/cache/replay.py:_require_authored_values_expression`). Trusted HTML parts and template-written attribute text replay as stored. The Events State a cached component builds in `state_data()` is stored with its HTML (`citry/ext/events/cache.py:export_events_cache`). Citry itself stores JSON text (`citry/ext/cache/artifact.py:_decode_artifact_with_size`). A store that unpickles what it reads runs code on the server for anyone who can write to it: most of Django's cache backends behind `DjangoCache` (`citry/contrib/django.py:DjangoCache`), and a `diskcache` store behind `DiskCache` (`citry/contrib/caches.py:DiskCache`). | `docs/performance/caching.md#protect-private-output` ("Protect the cache store like your database"); `docs/security.md#protect-the-render-cache`. Unpickling stores: Missing |
+| Cache keys (`Component.Cache`, ``) | Key values (a component's `Kwargs`, `Component.Cache.vary()`, `c-vary`): app code, and they may include request values. A `` `key`, including a `c-key` expression: author only, because the name is shared across the whole app | None directly; a wrong key serves one user's HTML, and the Events State stored with it, to another user | Hashed (`citry/ext/cache/keys.py:_build_physical_key`); `Secret` refused as a key part (`citry/ext/cache/keys.py:_canonical_cache_tree`). A component's key is its class id plus its `Kwargs`, or the values `vary()` returns (`citry/ext/cache/extension.py:CacheExtension._lookup_component`). A `` key holds the `key`, the `vary` values and the version, but not which template wrote the region (`_lookup_fragment`, `citry/ext/cache/extension.py:CacheExtension._lookup_fragment`), so two regions with the same `key` share entries. Citry also accepts `c-key`, an expression. | `docs/performance/caching.md#c-cache-regions` ("Give it a fixed `key`"), `docs/performance/caching.md#protect-private-output` |
+| `export_render_cache()`, `stage_render_cache()`, `render_cache_bypass_reason()` | App code | Through the extension's own output | `render_cache_mode` defaults to `"deny"` (`citry/extension.py:Extension.render_cache_mode`), which skips caching for any render a hook touched (`citry/extension.py:ExtensionManager._export_render_cache`); a stored payload must be strict JSON (`citry/ext/cache/artifact.py:_validate_frozen_json`). With `"stateless"`, Citry stores nothing from the extension (`citry/extension.py:ExtensionManager._export_render_cache`) and the hook does not run on a hit, so its output replays as part of the stored HTML. The key holds none of the values the hook read. A stateless hook must add the same output for every request that shares the key. A text replacement that `stage_render_cache()` returns may only swap one i18n binding marker value for another, and every ID in both values must have the shape the i18n extension writes (`is_binding_id`, checked in `citry/ext/cache/replay.py:_replay_boundary_artifact`), because replay puts the new value into stored HTML without escaping it again. | `docs/advanced/extensions.md#support-caching`. The stateless rule: Missing |
| Hooks whose return does not reach the page: `on_extension_created`, `on_component_class_created`, `on_component_registered`, `on_component_unregistered`, `on_citry_cleared`, `on_template_reset`, `on_render_context_merge`, `on_files_reset`, `on_component_cache_hit`, `validate_config_fields`, `inspect_component`, `inspect_template_namespace` | App code | Nothing from the return value | Return values are ignored or used only for metadata and analysis. Changes these hooks make (to `ctx.parent_context.extra`, or to a component class) reach the page only through the extension's other hooks or the class itself. | Docstrings in `citry/extension.py` |
-| `citry.ext.debug.Debug` boxes | App code (config) | Text labels | Labels written as escaped text (`citry/ext/debug.py:47`); debug output is never cached. | `docs/guides/troubleshooting.md:292-348` |
+| `citry.ext.debug.Debug` boxes | App code (config) | Text labels | Labels written as escaped text (`citry/ext/debug.py:_wrap_result`); debug output is never cached. | `docs/guides/troubleshooting.md#visualize-component-and-slot-boundaries` |
## 12. Settings and the opt-in output checks
| Setting | Who may supply it | What Citry does, and where | Docs |
|---|---|---|---|
-| `security_csp` (`off`, `warn`, `strict`) | App code | One Rust scan of the final page, after every hook: `check_output_html` (`crates/citry_html_transform/src/output_policy.rs:188`, via `citry/_output_policy.py:138`). Reports template-written `