Repository navigation
fix: prevent HTML-to-Markdown URL parser SSRF bypass - #906
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f359a02513
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return r.text | ||
|
|
||
| for _ in range(MAX_REDIRECTS + 1): | ||
| response = requests.get(canonical_url, timeout=10, allow_redirects=False) |
There was a problem hiding this comment.
Preserve cookies while following redirects
Reuse one requests.Session for the redirect loop. Each call to the top-level requests.get creates and closes a fresh session, so cookies set by a redirect response are discarded before the next request; URLs whose 3xx response sets a session, consent, or authentication cookie required by the destination will therefore return the wrong page or fail, whereas the previous automatic redirect handling retained those cookies.
Useful? React with 👍 / 👎.
Motivation
urllib.parseandrequestsdisagreed about the effective hostname for ambiguous authority strings (e.g. backslash before@).Description
_canonicalize_url()which rejects ambiguous inputs containing backslashes and returns the canonical URL as prepared byrequests.Request(...).prepare().urlfor consistent transport semantics._is_safe_canonical_url()that parses and checks the canonicalized hostname against existing blocked ranges and resolution checks.is_safe_url()to validate the canonical representation instead of the raw input and changefetchHTML()to use the canonical URL while disabling automatic redirects and validating every redirect target before following it with aMAX_REDIRECTSlimit.tests/test_html_to_markdown.pythat assert the crafted backslash authority payload is rejected before any HTTP call and that redirects to loopback addresses are blocked.Testing
python -m pytest tests/test_html_to_markdown.py -q— all unit tests and added regression cases passed (9 tests and 5 subtests passed).python -m compileall -q misp_modules/modules/expansion/html_to_markdown.py tests/test_html_to_markdown.py— compilation checks succeeded.Codex Task