Skip to content

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

Closed

Description

@JuroOravec

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:

  1. a raw <script> or <style> element written in a template;
  2. a native inline event handler such as onclick="...";
  3. a javascript: URL in action, formaction, href, src, xlink:href, or data on <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.
  • 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 into Component.js or a structured dependency, use a Vue handler such as @click in place of onclick, and use a real URL with a Vue handler in place of javascript:.
  • "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 on prefix rule also matches custom attributes such as online or onboarding-step. Decide whether the shared rule should keep matching every on name, so new browser events are caught too, or use a list of known event names.

Planned for after 0.6.0.

Activity

  1. added a commit that references this issue on Oct 28, 2026
    8fe5d6c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions