Repository navigation
feat: report strict-CSP problems in templates in citry check and the editor - #478
Merged
Merged
Conversation
…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
force-pushed
the
feat/csp-static-check
branch
from
October 28, 2026 11:33
34fbdea to
8fe5d6c
Compare
This was referenced Oct 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #181. Builds on #471 (the Rust function), which has merged; this branch is rebased onto
main.When an app sets
security_cspto"warn"or"strict",citry checkand the editor now report what a strict Content Security Policy blocks, at the place the template writes it:<script>or<style>element;on*attribute such asonclick(any name longer than two characters that starts withon, as agreed in the design: option A);javascript:URL inaction,formaction,href,src,xlink:href, ordataon<object>, after character references are decoded."warn"reports warnings and"strict"errors, so with"strict"citry checkfails. With"off", the default, nothing is reported, andcitry check --staticand an editor that has not loaded the app report nothing, because they cannot know the setting.How it works
citry_core.html_transform._csp_attribute_problemfrom 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)._check_csp_elementincitry/_markup_lint.py, inside the walk thatcitry checkand the editor already share.MarkupLintConsumergets acspfield. A template shared by several components gets the strictest owner's severity.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.citry.template.csp-incompatible, with messages for an inline element, an event attribute and ajavascript:URL. It is off by default (defaultSeverity: "ignore"), becausesecurity_cspis the switch, not arule_*setting.test_diagnostics.pylists it as a code that a setting other thanLintSettingsturns 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:
c-href,c-bind) and HTML passed to a component in an attribute: the render-time check covers them;:hrefandv-bind: they get their values in the browser, and neither check sees them;<Card>that may be a Vue component;<noscript>,<iframe>,<xmp>,<noembed>,<noframes>and<plaintext>, which the browser and the page check read as text;<title>or<style>, which the template parser reads as text (the render-time check still reports it);javascript:value that holds extension syntax (anon*name is still reported).One finding during review: when
security_cspis 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 withsecurity_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 boundc-is,<Card>, the SVG text cases), each with the reason.test_analysis.py: theTemplateLintInforound trip, the record without the field, bad values, and the engine's value reaching the record.test_check.py:citry checkwith"warn","strict"and"off", line and column,--static.citry_lsp/tests/test_engine.py: the editor's diagnostics and severity for each mode.Evidence
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.test_extract_first_party_security_error) only happens because citry_core loads from an unpacked wheel outside the repo.--platform linux),scripts/validate.pyandgenerate_diagnostic_catalog.py --checkall 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
c-href="'javascript:x'", which the design names as a follow-up.ignoreplus an explicit test exemption instead of a schema change.🤖 Generated with Claude Code