Skip to content

feat: report strict-CSP problems in templates in citry check and the editor - #478

Merged
JuroOravec merged 1 commit into
mainfrom
feat/csp-static-check
Oct 28, 2026
Merged

JuroOravec merged 1 commit into
mainfrom
feat/csp-static-check

Conversation

@JuroOravec

@JuroOravec JuroOravec commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Fixes #181. Builds on #471 (the Rust function), which has merged; this branch is rebased onto main.

When an app sets security_csp to "warn" or "strict", citry check and the editor now report what a strict Content Security Policy blocks, at the place the template writes it:

  • an inline <script> or <style> element;
  • an on* attribute such as onclick (any name longer than two characters that starts with on, as agreed in the design: option A);
  • a javascript: URL in action, formaction, href, src, xlink:href, or data on <object>, after character references are decoded.

"warn" reports warnings and "strict" errors, so with "strict" citry check fails. With "off", the default, nothing is reported, and citry check --static and an editor that has not loaded the app report nothing, because they cannot know the setting.

How it works

  • One copy of the rules. Each attribute goes through citry_core.html_transform._csp_attribute_problem from feat: judge one template attribute by the strict-CSP output rules #471, which calls the same Rust predicates and decoder as the render-time page check. <c-raw> content goes through the page check itself (check_output_html).
  • The rule is _check_csp_element in citry/_markup_lint.py, inside the walk that citry check and the editor already share. MarkupLintConsumer gets a csp field. A template shared by several components gets the strictest owner's severity.
  • The setting reaches both surfaces through TemplateLintInfo.security_csp, filled from the engine's settings. The detached record leaves the field out while it is "off", so an older language server still reads it. A newer citry with CSP on needs a matching citry-lsp; the citry-lsp changelog says so. The schema version stays 1.
  • New code citry.template.csp-incompatible, with messages for an inline element, an event attribute and a javascript: URL. It is off by default (defaultSeverity: "ignore"), because security_csp is the switch, not a rule_* setting. test_diagnostics.py lists it as a code that a setting other than LintSettings turns on.

What it reads, and what it leaves alone

It reads only fixed text: a static attribute with no binding prefix, including names with a dot such as onclick.prevent; <script>/<style> in any letter case (<SCRIPT>, <Script>); <c-element is="..."> as the element it names; and v-pre regions, because Vue still sets the attributes it leaves as written.

It skips:

  • Citry bindings (c-href, c-bind) and HTML passed to a component in an attribute: the render-time check covers them;
  • Vue bindings such as :href and v-bind: they get their values in the browser, and neither check sees them;
  • attributes on component tags, including a capitalized tag such as <Card> that may be a Vue component;
  • the content of <noscript>, <iframe>, <xmp>, <noembed>, <noframes> and <plaintext>, which the browser and the page check read as text;
  • markup inside an SVG <title> or <style>, which the template parser reads as text (the render-time check still reports it);
  • a javascript: value that holds extension syntax (an on* name is still reported).

One finding during review: when security_csp is on, Citry does not server-render a Vue page, so the render-time check never sees what Vue builds in the browser. For Vue components this static check is the only coverage of literal markup. The docs now say so.

Tests

  • test_markup_lint.py: every mode and the strictest-owner merge; each reported case with its exact range and message; each skipped case; <c-raw> with UTF-8 byte offsets and names as written; extension-syntax values; and an agreement test that renders each of about 45 snippets with security_csp="warn" and requires the render-time check and the static rule to report the same things. A separate list records the deliberate differences (v-pre in a Vue page, a bound c-is, <Card>, the SVG text cases), each with the reason.
  • test_analysis.py: the TemplateLintInfo round trip, the record without the field, bad values, and the engine's value reaching the record.
  • test_check.py: citry check with "warn", "strict" and "off", line and column, --static.
  • citry_lsp/tests/test_engine.py: the editor's diagnostics and severity for each mode.

Evidence

  • citry tests without e2e: 9,785 passed, 7 skipped, 1 xfailed.
  • citry_lsp tests: 858 passed, 1 failed. The failure (test_runtime_ty_version_matches_every_declared_ty_pin) reads the shared venv's older citry-lsp metadata; this branch does not touch the ty pins.
  • docs_site tests without e2e: 1,135 passed, 1 failed. The failure (test_extract_first_party_security_error) only happens because citry_core loads from an unpacked wheel outside the repo.
  • Focused CSP files after the last edits: 513 passed.
  • ruff, ruff format, the gate's mypy list (also with --platform linux), scripts/validate.py and generate_diagnostic_catalog.py --check all pass.

Local runs use a citry_core wheel built from #471 by the Rust lane, placed first on PYTHONPATH; I did not build Rust. PR CI builds the extension from this branch.

Reviews: an independent technical review with a prose pass, a delta review of its fold-in, and a docs cold read, all folded in.

Not in this PR

  • Reading constant expressions such as c-href="'javascript:x'", which the design names as a follow-up.
  • A catalog field for "severity follows a setting": the entry uses ignore plus an explicit test exemption instead of a schema change.

🤖 Generated with Claude Code

Base automatically changed from feat/csp-attribute-problem to main October 28, 2026 11:27
…editor

With security_csp set to "warn" or "strict", citry check and the editor
now report what a strict Content Security Policy blocks, at the place a
template writes it: an inline <script> or <style>, an on* attribute such
as onclick, and a javascript: URL. "warn" gives warnings and "strict"
errors; with the default "off" nothing is reported.

Each fixed attribute goes through _csp_attribute_problem from #471,
which uses the render-time check's own predicates and decoder, and
<c-raw> content goes through the page check, so there is one copy of the
rules. The engine's security_csp reaches both surfaces through
TemplateLintInfo, which leaves the field out while it is off. A template
shared by several components gets its strictest owner's severity.

The check reads only fixed text. Citry bindings and HTML passed to a
component in an attribute stay with the render-time check. Vue bindings,
attributes on component tags, and content the browser reads as text
(<noscript>, <iframe>, <xmp>, <noembed>, <noframes>, <plaintext>) are
skipped. v-pre regions are checked, because Vue still sets the
attributes it leaves as written, and <c-element is="..."> is checked as
the element it names.

The new code citry.template.csp-incompatible is off by default. Tests
compare the static rule with the render-time check on about 45 snippets
and record the deliberate differences.

Fixes #181

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@JuroOravec
JuroOravec force-pushed the feat/csp-static-check branch from 34fbdea to 8fe5d6c Compare October 28, 2026 11:33
@JuroOravec
JuroOravec merged commit 515d78c into main Oct 28, 2026
0 of 30 checks passed
@JuroOravec
JuroOravec deleted the feat/csp-static-check branch October 28, 2026 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show CSP problems in the editor and citry check before a page renders

1 participant