Enhance SSRF DNS validation with comprehensive IP checks and IPv6 support#85
Conversation
- Enhanced exception handling to catch OSError in addition to socket.gaierror - Added comprehensive IP range checks (link_local, reserved, multicast) - Strip IPv6 zone identifiers before validation - Document TOCTOU vulnerability limitation in code comments and sentinel.md Co-authored-by: abhimehro <84992105+abhimehro@users.noreply.github.com>
Co-authored-by: abhimehro <84992105+abhimehro@users.noreply.github.com>
…copilot/sub-pr-72
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
Test valid URLprint('Testing valid URL:', validate_folder_url('REDACTED')) Test localhostprint('Testing localhost:', validate_folder_url('https://localhost/te 53 -j ACCEPT` (dns block)
Test different exception typestest_cases = [ print('Testing exception handling...')
|
There was a problem hiding this comment.
Pull request overview
This pull request enhances SSRF protection in URL validation by adding DNS resolution checks to detect domains that resolve to restricted IP addresses, expanding IP range validation to include link-local, reserved, and multicast addresses, and properly handling IPv6 zone identifiers.
Key Changes:
- Enhanced IP range validation to check for link_local, reserved, and multicast addresses in addition to private and loopback
- Added DNS resolution logic to validate domains don't resolve to restricted IPs
- Implemented proper IPv6 zone identifier stripping before IP validation
- Documented TOCTOU vulnerability limitations in both code comments and sentinel.md
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| main.py | Enhanced validate_folder_url with comprehensive IP range checks for both literal IPs and DNS-resolved IPs, added IPv6 zone identifier handling, and documented TOCTOU limitations |
| .jules/sentinel.md | Documented the SSRF via DNS resolution vulnerability, prevention measures, and known limitations including DNS rebinding attacks |
Comments suppressed due to low confidence (2)
main.py:223
- There are duplicate TOCTOU comments. Lines 216-219 and lines 222-223 both describe the same Time-Of-Check-Time-Of-Use limitation. Remove the duplicate comment at lines 222-223 to avoid redundancy.
# Note: This check has a Time-Of-Check-Time-Of-Use (TOCTOU) limitation.
# DNS rebinding attacks could return a safe IP during validation and a
# private IP during the actual request. This is a known limitation of
# DNS-based SSRF protection.
try:
# Resolve hostname to IPs
# Note: This check has a Time-Of-Check-Time-Of-Use (TOCTOU) limitation.
# A malicious DNS server could return a safe IP now and a private IP later.
.jules/sentinel.md:57
- The documentation contains duplicate content. Lines 45-52 and lines 53-57 both describe the same vulnerability, learning, and prevention steps. Remove the duplicate section (lines 53-57) to avoid confusion and maintain clean documentation.
**Learning:** Blocking IP literals is insufficient for SSRF protection. DNS resolution must be performed to verify that a domain does not resolve to a restricted IP address. Note that check-time validation has TOCTOU limitations vs request-time verification.
**Prevention:**
1. Resolve domain names using `socket.getaddrinfo` before making requests.
2. Verify all resolved IP addresses against private, loopback, link-local, reserved, and multicast ranges.
3. Handle DNS resolution failures and zone identifiers (IPv6) securely.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
cbb3b23
into
sentinel-ssrf-dns-resolution-5407761294063338854
Addresses review feedback on the SSRF DNS resolution fix to close remaining security gaps and edge cases.
Changes
Expanded IP range validation: Added checks for
is_link_local,is_reserved, andis_multicastin addition tois_privateandis_loopback. Applied consistently to both literal IP and DNS resolution paths.IPv6 zone identifier handling: Strip zone IDs (e.g.,
%eth0) from IPv6 addresses before validation to prevent parsing errors:Comprehensive exception handling: Catch
OSErrorin addition tosocket.gaierrorduring DNS resolution to handle network failures and timeouts.TOCTOU limitation documented: Added inline comments and sentinel.md entry noting that DNS rebinding attacks remain theoretically possible—an attacker's DNS server could return safe IPs during validation and private IPs during the actual request. This is a known limitation of DNS-based SSRF protection.
Example
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.