Escape HTML in markdown report to prevent injection - #29
Open
elhoim wants to merge 1 commit into
Open
Conversation
response_to_table and the summary/heading fields embedded attacker-influenced module output (WHOIS, passive DNS, sandbox responses) into the generated markdown report with only newline/pipe sanitization. Since the report is often rendered as HTML (e.g. via a markdown viewer), a module response containing <script> or other tags reached the output verbatim, and to_inline's literal <br> implied HTML rendering was expected. Fix: html.escape() every scalar (keys and values) before embedding, in addition to the existing pipe/newline handling, in scalar_to_text, response_to_table's key/value pairs, and the summary/heading fields (input_value, explicit_type, selected_modules, module, attribute_type, status, reason, queried_at, cache).
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.
Finding 20 (Medium) —
bin/cli.py:403-422,442-470Problem
response_to_table escapes only newlines and pipes - <script> from a module response reaches the markdown report verbatim, and to_inline emits a literal
, implying HTML rendering. The summary/heading fields at :442-470 (input_value, module, reason) get NO escaping. Module output (WHOIS, passive DNS, sandbox) is attacker-influenced.
Fix
Finding 20 (markdown-html-injection, medium): format_markdown_output in bin/cli.py embedded attacker-influenced module response data (WHOIS, passive DNS, sandbox output) and summary/heading fields into the generated markdown report with only newline/pipe sanitization, no HTML escaping. Since to_inline emits a literal
<br>(implying HTML rendering) and the report can be rendered as HTML, a module response containing<script>or other tags reached the output verbatim. Fix: addedhtml.escape()calls for every scalar (keys and values) in scalar_to_text (used throughout format_nested_value, to_inline, and response_to_table's fallback scalar branch), for keys in response_to_table's dict branch, and for the summary/heading fields (input_value, explicit_type, selected_modules, module, attribute_type, status, reason, queried_at, cache), in addition to the existing pipe/newline handling. Escaping happens before the pipe/newline replace, which is order-independent since html.escape does not touch|or\n.Verification
Reproduced against the unmodified code at
9b8c605, then re-checked after the change.Before
After
python bin/cli.py --helpexits 0 and the module still imports cleanly. Verification was performed offline against the pure functions — no runningmisp-modulesinstance is required.Branched from
9b8c605. This PR addresses only this finding; the other findings from the same review are in separate PRs, so they will need rebasing against each other as they merge.🤖 Generated with Claude Code
https://claude.ai/code/session_01DYX4TKA5inzByJ4qGWKjqh