Skip to content

sync_from_registry.py crashes on backslashes and does not escape JSON embedded in script tags #106

Closed

Description

@TMHSDigital

Why it matters

scripts/sync_from_registry.py regenerates the README, CLAUDE.md and docs/index.html from registry.json, and a required CI check depends on it. Two escaping bugs let ordinary registry content crash the sync or corrupt the generated output.

Evidence

  1. Replacement string treated as a regex template.
    • scripts/sync_from_registry.py:323 calls pattern.sub(replacement, text, count=1) with a plain string, so backslash sequences in generated content are interpreted.
    • Reproduced: a body containing C:\dev raises bad escape \d, and \1 would silently insert a captured group.
    • Sibling helpers in the same file already pass a lambda.
  2. JSON in <script> not escaped.
    • render_embedded_registry (:215) and render_search_index (:296) write json.dumps(...) straight into <script type="application/json">.
    • A registry string containing a closing script tag ends the block early. That breaks the page, weakens the "no unsafe DOM sinks" posture in CLAUDE.md, and breaks the next sync run, because the replace_script_block regex stops at the first closing tag.
    • Registry content is maintainer-reviewed, so this is defense in depth, but registry entries are meant to come in through contributor PRs.

Suggested approach

  • Use one helper for all region replacement, always pattern.sub(lambda _m: replacement, ...).
  • Escape <, > and & in embedded JSON as \u003c, \u003e and \u0026 (or at minimum </ and <!--).
  • Cover both cases in the new unit tests (see the test coverage issue).

Done when

A registry description containing backslashes or markup round-trips through sync_from_registry.py, and --check stays idempotent.

Activity

  1. added
    bug
    priority: medium
    security
    on Oct 8, 2026
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

    bugpriority: mediumregistrysecurity

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions