🛡️ Sentinel: Fix SSRF vulnerability in URL validation#89
🛡️ Sentinel: Fix SSRF vulnerability in URL validation#89google-labs-jules[bot] wants to merge 1 commit intomainfrom
Conversation
- Added DNS resolution to `validate_folder_url` to check for private IPs. - Used `socket.gethostbyname` to resolve domains. - Verified that resolved IPs are not private or loopback addresses. - Added `socket` import.
|
👋 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. |
| resolved_ip_str = socket.gethostbyname(hostname) | ||
| resolved_ip = ipaddress.ip_address(resolved_ip_str) | ||
| if resolved_ip.is_private or resolved_ip.is_loopback: | ||
| log.warning(f"Skipping unsafe URL (domain resolves to private IP {resolved_ip_str}): {sanitize_for_log(url)}") |
Check warning
Code scanning / Pylint (reported by Codacy)
Line too long (130/100) Warning
| # We'll allow it to proceed to HTTP request which will likely fail, | ||
| # or we could be strict and reject it. | ||
| # Being strict is safer for security. | ||
| log.warning(f"Skipping unsafe URL (DNS resolution failed): {sanitize_for_log(url)}") |
Check warning
Code scanning / Pylint (reported by Codacy)
Line too long (101/100) Warning
| # Not an IP literal, it's a domain. | ||
| pass | ||
| try: | ||
| # Resolve domain to IP to check for private addresses (SSRF protection) |
Check notice
Code scanning / Pylint (reported by Codacy)
Catching too general exception Exception Note
| # We'll allow it to proceed to HTTP request which will likely fail, | ||
| # or we could be strict and reject it. | ||
| # Being strict is safer for security. | ||
| log.warning(f"Skipping unsafe URL (DNS resolution failed): {sanitize_for_log(url)}") |
Check notice
Code scanning / Pylint (reported by Codacy)
Bad indentation. Found 17 spaces, expected 16 Note
| # or we could be strict and reject it. | ||
| # Being strict is safer for security. | ||
| log.warning(f"Skipping unsafe URL (DNS resolution failed): {sanitize_for_log(url)}") | ||
| return False |
Check notice
Code scanning / Pylint (reported by Codacy)
Bad indentation. Found 17 spaces, expected 16 Note
| # or we could be strict and reject it. | ||
| # Being strict is safer for security. | ||
| log.warning(f"Skipping unsafe URL (DNS resolution failed): {sanitize_for_log(url)}") | ||
| return False |
Check warning
Code scanning / Pylintpython3 (reported by Codacy)
Line too long (130/100) Warning
main.py
Outdated
Check warning
Code scanning / Pylintpython3 (reported by Codacy)
Line too long (101/100) Warning
main.py
Outdated
Check warning
Code scanning / Pylintpython3 (reported by Codacy)
Variable name "e" doesn't conform to snake_case naming style Warning
| # or we could be strict and reject it. | ||
| # Being strict is safer for security. | ||
| log.warning(f"Skipping unsafe URL (DNS resolution failed): {sanitize_for_log(url)}") | ||
| return False |
Check notice
Code scanning / Pylintpython3 (reported by Codacy)
Use lazy % formatting in logging functions Note
main.py
Outdated
Check notice
Code scanning / Pylintpython3 (reported by Codacy)
Use lazy % formatting in logging functions Note
main.py
Outdated
Check notice
Code scanning / Pylintpython3 (reported by Codacy)
Bad indentation. Found 17 spaces, expected 16 Note
main.py
Outdated
Check notice
Code scanning / Pylintpython3 (reported by Codacy)
Use lazy % formatting in logging functions Note
| # or we could be strict and reject it. | ||
| # Being strict is safer for security. | ||
| log.warning(f"Skipping unsafe URL (DNS resolution failed): {sanitize_for_log(url)}") | ||
| return False |
Check warning
Code scanning / Prospector (reported by Codacy)
Use lazy % formatting in logging functions (logging-fstring-interpolation) Warning
| return False | ||
| except Exception as e: | ||
| log.warning(f"Failed to resolve domain for URL {sanitize_for_log(url)}: {e}") | ||
| return False |
Check warning
Code scanning / Prospector (reported by Codacy)
over-indented (comment) (E117) Warning
| return False | ||
| except Exception as e: | ||
| log.warning(f"Failed to resolve domain for URL {sanitize_for_log(url)}: {e}") | ||
| return False |
Check warning
Code scanning / Prospector (reported by Codacy)
indentation is not a multiple of four (comment) (E114) Warning
| except Exception as e: | ||
| log.warning(f"Failed to resolve domain for URL {sanitize_for_log(url)}: {e}") | ||
| return False | ||
|
|
Check warning
Code scanning / Prospector (reported by Codacy)
indentation is not a multiple of four (comment) (E114) Warning
| except Exception as e: | ||
| log.warning(f"Failed to resolve domain for URL {sanitize_for_log(url)}: {e}") | ||
| return False | ||
|
|
Check warning
Code scanning / Prospector (reported by Codacy)
over-indented (comment) (E117) Warning
main.py
Outdated
Check warning
Code scanning / Prospector (reported by Codacy)
over-indented (E117) Warning
main.py
Outdated
Check warning
Code scanning / Prospector (reported by Codacy)
Use lazy % formatting in logging functions (logging-fstring-interpolation) Warning
main.py
Outdated
Check warning
Code scanning / Prospector (reported by Codacy)
Use lazy % formatting in logging functions (logging-fstring-interpolation) Warning
main.py
Outdated
Check warning
Code scanning / Prospector (reported by Codacy)
Bad indentation. Found 17 spaces, expected 16 (bad-indentation) Warning
main.py
Outdated
Check warning
Code scanning / Prospector (reported by Codacy)
Use lazy % formatting in logging functions (logging-fstring-interpolation) Warning
|
Superseded: SSRF protection already in main via PR #109. |
🛡️ Sentinel: [HIGH] Fix SSRF vulnerability in folder URL validation
🚨 Severity: HIGH
💡 Vulnerability: The previous validation logic allowed domains that resolve to private IP addresses (SSRF), as it only checked for explicit "localhost" strings or IP literals.
🎯 Impact: An attacker could potentially access internal network resources by providing a URL pointing to a local service via a domain name.
🔧 Fix: Updated
validate_folder_urlto resolve domain names to IP addresses and verify that they do not point to private or loopback ranges using theipaddresslibrary.✅ Verification: Verified with a test script simulating domains resolving to private and public IPs.
PR created automatically by Jules for task 12945820800002383074 started by @abhimehro