Conversation
| data = {"body": review_comment} | ||
|
|
||
| async with httpx.AsyncClient() as client: | ||
| await client.post(comments_url, json=data, headers=headers) |
Check failure
Code scanning / CodeQL
Full server-side request forgery Critical
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 8 months ago
To fix the issue, we will ensure that the comments_url is selected from a predefined list of trusted URLs on the server, rather than relying on user-provided input. This eliminates the possibility of SSRF attacks by removing user control over the URL entirely. Specifically:
- Replace the dynamic
comments_urlwith a server-controlled URL based on the repository's full name or other trusted attributes. - Remove the validation logic for
comments_urlsince it will no longer be necessary. - Update the
client.postcall to use the server-controlled URL.
| @@ -50,27 +50,6 @@ | ||
| # Validate comments_url domain (trust but verify) | ||
| comments_url = payload["pull_request"]["comments_url"] | ||
|
|
||
| # Define a whitelist of allowed base URLs | ||
| allowed_urls = [ | ||
| "https://web4application.github.io/repos/" | ||
| ] | ||
|
|
||
| # Parse and validate the comments_url | ||
| try: | ||
| parsed_url = urlparse(comments_url) | ||
| if not parsed_url.scheme in ["http", "https"]: | ||
| raise HTTPException(status_code=400, detail="Invalid comments_url: Unsupported URL scheme") | ||
| if not any(comments_url.startswith(allowed_url) for allowed_url in allowed_urls): | ||
| raise HTTPException(status_code=400, detail="Invalid comments_url: URL not in allowed whitelist") | ||
|
|
||
| # Resolve domain to IP and validate against trusted range | ||
| import socket | ||
| resolved_ip = socket.gethostbyname(parsed_url.netloc) | ||
| trusted_ips = ["192.30.252.0/22", "185.199.108.0/22"] # Example GitHub IP ranges | ||
| from ipaddress import ip_address, ip_network | ||
| if not any(ip_address(resolved_ip) in ip_network(trusted_range) for trusted_range in trusted_ips): | ||
| raise HTTPException(status_code=400, detail="Invalid comments_url: IP address not in trusted range") | ||
| except Exception as e: | ||
| raise HTTPException(status_code=400, detail=f"Invalid comments_url: {str(e)}") | ||
|
|
||
| # Construct a server-controlled comments_url based on repository full name | ||
| base_url = "https://web4application.github.io/repos/" | ||
| repo_full_name = payload["repository"]["full_name"] | ||
| comments_url = f"{base_url}{repo_full_name}/comments" | ||
| headers = { |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
Warning Review the following alerts detected in dependencies. According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Signed-off-by: Web4 <167559384+Web4application@users.noreply.github.com>
Signed-off-by: Web4 <167559384+Web4application@users.noreply.github.com>
…ine.yaml Signed-off-by: Web4 <167559384+Web4application@users.noreply.github.com>
Signed-off-by: Web4 <167559384+Web4application@users.noreply.github.com>
Signed-off-by: Web4 <167559384+Web4application@users.noreply.github.com>
@dependabot recreate
@dependabot rebase
@dependabot merge