Repository navigation
fix(utils): prevent SSRF in untrusted URL downloads - #2298
KevinAndrewDong wants to merge 3 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (7)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe change adds a server-side URL fetch helper that validates destinations and redirect targets. The scraper and API URL-download path use this helper. The patch also adds server-specific utility exports and tests for validation, error handling, and download behavior. ChangesSSRF-safe URL retrieval
Priority: ⬆️ High Estimated code review effort: 4 (Complex) | ~45 minutes Change: Bug fix · Severity of issue fixed: High Sequence Diagram(s)sequenceDiagram
participant MiscController
participant MiscService
participant scrapeWeblink
participant safeFetch
participant socketLookup
participant remoteHost
MiscController->>MiscService: submit URL for scraping
MiscService->>scrapeWeblink: scrape URL
scrapeWeblink->>safeFetch: fetch URL
safeFetch->>socketLookup: validate DNS answers
socketLookup-->>safeFetch: return validated address
safeFetch->>remoteHost: request URL
remoteHost-->>safeFetch: return response or redirect
safeFetch->>socketLookup: validate redirect destination
safeFetch-->>scrapeWeblink: return response
scrapeWeblink-->>MiscService: return metadata
MiscService-->>MiscController: return scrape result
Merge Risk: ⚪ Minimal · up to This change adds SSRF protection for URL downloads, with test certificates and HTTPS tests for the new guard. No merge-blocking issue was identified in the reviewed files. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change narrows outbound network access without an established expansion of authentication or storage authority. No introduced security issue was identified in the reviewed paths. Complete caller coverage and production HTTPS behavior remain unverified. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 7 files. (6 skipped: 6 unsupported.)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Untrusted URLs passed to
/v1/misc/scrapeanddumpFileFromURLcould reach internal services and return page metadata or upload response bodies. Both paths now use a shared server-onlysafeFetch.Fixes #2280.
pipelining: 0.ParamsErrorand normalize DNS/connection failures toConnectionError, without exposing URLs, resolved addresses or chained causes.Compatibility
safeFetchandscrapeWeblinkfrom@refly/utils/serverso Node dependencies do not enter the browser-facing root export. Update the existing API consumers.ipaddr.jsandundicias direct dependencies.Validation
Latest HTTPS follow-up (2026-10-08; production implementation unchanged):
Original implementation validation (2026-10-01; not rerun for this test-only follow-up):
Full suites are not green. The original comparison against clean main
71f8b875found:ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG; neither full run completed.The HTTPS tests use real Undici/TLS connections with mocked DNS, a test CA and test-only routing to a local server after the production socket lookup approves the public address. Default certificate and hostname checks remain enabled. Public-network HTTPS and production end-to-end behavior remain unverified.
AI assistance
ChatGPT assisted with SSRF threat-model and compatibility review. Codex assisted with reproduction, the shared fetch guard and regression validation, including the local HTTPS follow-up.
Summary by CodeRabbit