Harden report output against stored-XSS via markdown#195
Open
seonghobae wants to merge 1 commit into
Open
Conversation
A security tool should not emit an injectable report. Findings from external engines can carry attacker-influenced text (a scanned file's `<script>` in a message); when a generated markdown report is rendered as HTML that becomes stored XSS. - appguardrail_core/reports.py: _sanitize_for_markdown() HTML-escapes the prose fields (message/remediation/verification) and neutralizes ``` code-fence breakout in snippets, applied at every report normalization site (covers all report types). Constrained identifiers (rule_id/category/context/severity), which also drive gate logic, are left untouched. - Tests: tests/test_report_sanitization.py (no raw <script>/<iframe>/<b> in any report type, entity escaping, fence-breakout neutralized, benign text unchanged / no over-escaping). - Verified: full suite 208 passed (benign existing messages unaffected). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EywwS2Du8pimW7xqRP3An3
9358b6b to
e993d83
Compare
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.
Summary
A security tool shouldn't emit an injectable artifact. Report renderers interpolate finding fields into markdown; findings from external engines (Trivy/Bandit/Semgrep) can carry attacker-influenced text — a scanned file's
<script>landing in amessage. When that markdown report is later rendered as HTML (GitHub, a viewer, a PDF pipeline), it's stored XSS._sanitize_for_markdown()returns a render-safe copy: prose fields (message/remediation/verification) HTML-escaped, andsnippetneutralized so it can't break out of its ``` code fence. Applied at every report normalization site, so all report types (buyer-diligence, founder-friendly, agency, fix-pack) are covered.rule_id/category/context/severity) — which also drive gate logic — are intentionally left untouched.Found by the repo's own
strixscan flagging unsanitized interpolation in report rendering — fixing it at the shared boundary rather than per call site.Test plan
pytest— 208 passed, incl.tests/test_report_sanitization.py(no raw<script>/<iframe>/<b>in any report type, entity escaping, fence-breakout neutralized, benign messages unchanged — no over-escaping)Follow-up: the
compliancereport (PR #192) will adopt_sanitize_for_markdownonce both land.🤖 Generated with Claude Code