hermes - 💡(How to fix) Fix test: Discord document handling tests fail due to SSRF protection blocking fake CDN URLs

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

3 tests in tests/gateway/test_discord_document_handling.py fail because url_safety.py blocks the fake CDN URL https://cdn.discordapp.com/attachments/fake/file as a private/internal address (resolves to 198.18.0.156).

Root Cause

Tests use make_attachment() with default URL https://cdn.discordapp.com/attachments/fake/file. The SSRF protection in tools/url_safety.py resolves this hostname to 198.18.0.156 (a benchmark/testing reserved range 198.18.0.0/15), which triggers the private address block:

WARNING  tools/url_safety:url_safety.py:208 Blocked request to private/internal address: cdn.discordapp.com -> 198.18.0.156

The _cache_discord_document method raises ValueError("Blocked unsafe attachment URL (SSRF protection)") and the test gets media_urls=[] instead of the expected cached file.

Fix Action

Fix

Tests need to mock the SSRF check for test URLs, e.g.:

@patch("gateway.platforms.discord.is_safe_url", return_value=True)

Code Example

WARNING  tools/url_safety:url_safety.py:208 Blocked request to private/internal address: cdn.discordapp.com -> 198.18.0.156

---

@patch("gateway.platforms.discord.is_safe_url", return_value=True)

---

.venv/bin/python -m pytest tests/gateway/test_discord_document_handling.py::TestIncomingDocumentHandling -v
RAW_BUFFERClick to expand / collapse

Summary

3 tests in tests/gateway/test_discord_document_handling.py fail because url_safety.py blocks the fake CDN URL https://cdn.discordapp.com/attachments/fake/file as a private/internal address (resolves to 198.18.0.156).

Affected Tests

  • TestIncomingDocumentHandling::test_pdf_document_cached
  • TestIncomingDocumentHandling::test_zip_document_cached
  • TestIncomingDocumentHandling::test_mid_sized_zip_under_32mb_is_cached

Root Cause

Tests use make_attachment() with default URL https://cdn.discordapp.com/attachments/fake/file. The SSRF protection in tools/url_safety.py resolves this hostname to 198.18.0.156 (a benchmark/testing reserved range 198.18.0.0/15), which triggers the private address block:

WARNING  tools/url_safety:url_safety.py:208 Blocked request to private/internal address: cdn.discordapp.com -> 198.18.0.156

The _cache_discord_document method raises ValueError("Blocked unsafe attachment URL (SSRF protection)") and the test gets media_urls=[] instead of the expected cached file.

Fix

Tests need to mock the SSRF check for test URLs, e.g.:

@patch("gateway.platforms.discord.is_safe_url", return_value=True)

Reproduction

.venv/bin/python -m pytest tests/gateway/test_discord_document_handling.py::TestIncomingDocumentHandling -v

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING