π Fix SSRF DNS Rebinding Vulnerability#13
Conversation
Introduced a custom `undici` Agent with a secure lookup function that validates IP addresses against internal ranges immediately before connection. This prevents Time-of-Check Time-of-Use (TOCTOU) attacks where DNS rebinding could bypass initial validation. - Added `IPGuard.secureLookup` and `IPGuard.getSecureDispatcher`. - Updated `Fetcher` to use the secure dispatcher when no proxy is configured. - Added unit tests for `IPGuard` and updated `Fetcher` integration tests.
|
π Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a π emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Explicitly typed the callback arguments in `dns.lookup` to prevent TypeScript from inferring `never` for the `address` parameter when handling array results, which caused a build failure.
Updated integration tests (`crawler.test.ts`, `fetcher.test.ts`) to mock `IPGuard.getSecureDispatcher` so that it returns the `MockAgent` configured in the tests, ensuring the tests can intercept requests. Updated `redirect_safety.test.ts` to mock `undici.Agent` which was missing from the existing mock and causing instantiation errors.
This PR fixes a critical SSRF vulnerability caused by a DNS Rebinding race condition. Previously, the
Fetchervalidated hostnames usingIPGuard.validateHostbefore making a request, but the subsequent request performed a new DNS resolution, allowing an attacker to switch the IP to an internal address between the check and the use.The fix introduces a custom
undiciAgent that hooks into the DNS lookup phase. By validating the resolved IP address immediately before the connection is established, we eliminate the race condition window.Changes:
plugins/core/src/core/security/ipGuard.ts: AddedsecureLookupmethod andgetSecureDispatcherhelper.plugins/core/src/crawler/fetcher.ts: UpdatedFetcherto usesecureDispatcherfor direct connections.plugins/core/tests/ipGuard.test.ts: Added tests for the new secure lookup logic.plugins/core/tests/fetcher_safety.test.ts: Updated mocks to supportundici.Agent.Risk:
Without this fix, an attacker could control a DNS server to return a public IP during validation and a private/internal IP during the request, allowing them to access internal network resources via the crawler.
Verification:
secureLookup.PR created automatically by Jules for task 7903518880006150675 started by @saurabhsharma2u