fix(report): prevent code-fence breakout in vulnerability markdown#817
Merged
Conversation
render_vulnerability_md wrapped LLM-authored poc_script_code and code snippet values in a fixed three-backtick fence, so a triple-backtick inside the value closed the fence early and the rest rendered as live markdown (headings, tracking-beacon images) in the shareable report deliverable. Open each such block with a fence one backtick longer than the longest backtick run in the payload (CommonMark: a block closes only on a fence at least as long as the opener), so the content always renders verbatim. The adjacent ```diff block is already safe (its lines are '- '/'+ ' prefixed and so can never be a bare-backtick closing fence) and is left unchanged. Fixes usestrix#815
Contributor
Greptile SummaryThis PR prevents attacker-influenced report content from escaping Markdown code blocks. The main changes are:
Confidence Score: 5/5This looks safe to merge.
Important Files Changed
Reviews (1): Last reviewed commit: "fix(report): prevent code-fence breakout..." | Re-trigger Greptile |
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.
What
render_vulnerability_mdnow opens thepoc_script_codeand codesnippetfences with a backtick run longer than any run inside the payload, so those
LLM/target-authored values always render verbatim and cannot break out of the
code fence.
Why
Both blocks used a fixed three-backtick fence with no escaping. A triple-backtick
inside the value closed the fence early and everything after it rendered as live
markdown — e.g. an injected
## headingand atracking image — in a report that is a shareable deliverable (GitHub, dashboards,
PRs). The values originate from a scan of an attacker-influenced target.
Change
_safe_fence(content): returns a fence one backtick longer than thelongest backtick run in
content(min 3). Per CommonMark a fenced block closesonly on a fence at least as long as the opener, so breakout becomes impossible.
poc_script_codeblock and the codesnippetblock.```diffblock is deliberately left unchanged: every line thereis prefixed with
-/+, so no line can be a bare-backtick closing fence.poc_script_codebreakout attempt and asnippetbreakoutattempt, asserting the payload stays enclosed.
Fixes #815