Repository navigation
Description
When an app sets security_csp="warn" or "strict", Citry checks each page's final HTML while it serializes, including HTML that extensions added. It reports three kinds of problem that a strict Content Security Policy would block in the browser:
- a raw
<script>or<style>element written in a template; - a native inline event handler such as
onclick="..."; - a
javascript:URL inaction,formaction,href,src,xlink:href, ordataon<object>.
Today you see these only when a page renders: "warn" emits one RuntimeWarning listing them, and "strict" raises a ValueError. A template that contains one of them literally could be flagged much earlier, in the editor and by citry check.
Proposal
Add a static check to citry check and the language server that reports the same three problems in literal template content, on apps that set security_csp to "warn" or "strict".
- Values that come from Python data, and HTML added by extensions, can only be checked at render time, so the render-time check stays.
- The static check and the render-time check must agree. Both should use one shared set of rules, which today live in
packages/py/citry/citry/_csp_validation.py:- how event attributes are recognised (today: any attribute name longer than two characters that starts with
on); - which attributes count as URLs;
- how attribute values are decoded before matching.
- how event attributes are recognised (today: any attribute name longer than two characters that starts with
- Give the finding its own diagnostic code in
packages/protocol/diagnostics/v1/catalog.json, with a fix for each case: move the script or style intoComponent.jsor a structured dependency, use a Vue handler such as@clickin place ofonclick, and use a real URL with a Vue handler in place ofjavascript:. "warn"reports the finding as a warning and"strict"as an error.
Strict serialization also rejects other things, such as a missing csp_nonce or a script or style dependency that is not a structured Script or Style. Those depend on how the page is served, so they stay out of this check.
Error modes to decide
- With
security_csp="off"(the default), the check reports nothing. serialize(security_csp=...)can change the mode for one render. A static check sees only the engine's setting, so it uses that.- A template the parser cannot read is already reported by the parser, so this check skips it rather than reporting it twice.
- The
onprefix rule also matches custom attributes such asonlineoronboarding-step. Decide whether the shared rule should keep matching everyonname, so new browser events are caught too, or use a list of known event names.
Planned for after 0.6.0.
Activity
feat: report strict-CSP problems in templates in citry check and the …