Skip to content

[critical] fix: [sourcecache] validate URLs before archiving to block SSRF - #941

Open
elhoim wants to merge 3 commits into
MISP:mainfrom
elhoim:fix/062-sourcecache-ssrf-url-validation-v2
Open

elhoim wants to merge 3 commits into
MISP:mainfrom
elhoim:fix/062-sourcecache-ssrf-url-validation-v2

Conversation

@elhoim

@elhoim elhoim commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

BLUF

  • Priority: critical.
  • Problem: sourcecache hands the attribute value straight to url_archiver. Enriching a hostile link or url attribute therefore makes the MISP server fetch any URL it can reach, such as loopback services or cloud metadata endpoints, and store the answer in the event as a page capture.
  • Fix: the module fetches only http and https URLs whose host resolves solely to globally routable addresses. Anything else returns an error before url_archiver is called.
  • Scope: this rebuilds the fix of the earlier PR on the current module, which now returns a page-capture object.

Details

misp_modules/modules/expansion/sourcecache.py gains an is_safe_url() check. It runs in handler() before the page is archived.

  • The scheme must be http or https, and the URL must name a host.
  • Every address the host resolves to must be globally routable (ipaddress.is_global). This refuses loopback, private, link-local (169.254.169.254) and reserved targets.
  • A URL with a backslash, whitespace or a control character is refused outright. urlparse and the requests stack behind url_archiver split such a URL differently: http://127.0.0.1\@example.com/ would be checked as example.com and fetched from 127.0.0.1.
  • A refused URL returns {"error": "Blocked URL ..."} and url_archiver is never called.

Known limits: url_archiver performs the request itself. A public URL that redirects to an internal one, or a host that is rebound between the check and the fetch, is not covered here. Closing those needs url_archiver to validate each hop, or the fetch to move into the module.

Tests

tests/test_sourcecache.py gains three cases. An internal address, a file:// URL and a backslash-userinfo URL each return an error without calling the archiver. All 12 tests in that file pass. flake8, with the repository's settings, is clean on the changed module.

Supersedes #873.

elhoim and others added 2 commits October 16, 2026 22:27
The module hands the attribute value straight to url_archiver, so enriching a hostile link or url attribute makes the MISP server fetch any URL it can reach, loopback services and cloud metadata endpoints included, and store the answer in the event. Fetch only http and https URLs whose host resolves solely to globally routable addresses, and return an error otherwise.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
urlparse and the requests stack that url_archiver fetches with disagree on a backslash in the authority: http://127.0.0.1\@example.com/ is checked as example.com and fetched from 127.0.0.1. Refuse backslashes, whitespace and control characters before checking the host.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@adulau

adulau commented Oct 17, 2026

Copy link
Copy Markdown
Member

Thanks. Could you review it to include also IPv6 infrastructure?

- An IPv6 address that carries an IPv4 one (IPv4-mapped ::ffff:0:0/96, 6to4
  2002::/16, NAT64 64:ff9b::/96) must be routable on both counts:
  http://[64:ff9b::7f00:1]/ reaches 127.0.0.1 and is now refused
- An unparsable address or an unclosed IPv6 bracket ("http://[::1/") is
  refused instead of raising
- Tests: IPv6 loopback, unspecified, unique local, link-local, IPv4-mapped,
  NAT64 and 6to4 literals are not fetched; a name with any internal AAAA
  record is not fetched; a name with public AAAA records is

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants