Skip to content
This repository was archived by the owner on Nov 25, 2026. It is now read-only.
This repository was archived by the owner on Nov 25, 2026. It is now read-only.

render_report: finding text with an unclosed '<!--' and '<script' breaks the HTML report (data island swallows the app script) #157

Open

Description

@CloneOfAlex

Describe the bug

render_report.py inject() embeds the findings JSON in <script id="report-data" type="application/json"> and escapes only </ (as <\/). The HTML parser also treats <!-- and <script specially inside script data. A JSON string containing <!-- followed by <script, with no --> after it, switches the tokenizer into the script data double-escaped state. The island's own </script> then no longer ends the element.

The data island swallows everything up to the next </script>, which is the report app's own script. The page ends up with one script element instead of two, the island is no longer valid JSON, and the report renders blank or broken.

Findings quote the files under analysis, so this triggers whenever a finding's evidence, title or recommendation quotes an HTML template or asset with an open comment before a script tag. That's realistic when analyzing skills that ship HTML, including this repo's own report-shell.html.

Steps to reproduce

cd skills/bmad-workflow-builder
python3 -c 'import json;print(json.dumps({"subject":"tpl","grade":"fair","findings":[{"id":"F1","lens":"structure","severity":"medium","title":"Unclosed comment","evidence":"line 40 opens <!-- before <script src=x> and never closes it"}]}))' > y.json
python3 scripts/render_report.py y.json --shell assets/report-shell.html -o y.html
pip install html5lib
python3 - <<'EOF'
import html5lib, json
d = html5lib.parse(open('y.html').read(), namespaceHTMLElements=False)
s = d.findall('.//script'); print(len(s), [x.get('id') for x in s])     # 1 ['report-data']  (expected 2)
isl = s[0].text; print(len(isl), 'function esc' in isl)                   # 20084 True  -> app code swallowed
json.loads(isl)                                                            # JSONDecodeError
EOF

Opening y.html in a browser shows the same broken page.

Expected behavior

Escape every < in the embedded JSON as \u003c (and optionally > as \u003e and & as \u0026). The result is still identical for JSON.parse, and no HTML tokenizer state can be triggered from the data. Add a regression test with <!--<script> in a finding.

Environment

Activity

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