-
Notifications
You must be signed in to change notification settings - Fork 0
π‘οΈ Sentinel: [HIGH] Fix Server-Side Request Forgery in JobParser #224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
anchapin
wants to merge
3
commits into
main
Choose a base branch
from
sentinel-ssrf-fix-13007455400231532099
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
37742f6
π‘οΈ Sentinel: [HIGH] Fix Server-Side Request Forgery in JobParser
google-labs-jules[bot] 977032b
π‘οΈ Sentinel: [HIGH] Fix Server-Side Request Forgery in JobParser
google-labs-jules[bot] 80dc267
π‘οΈ Sentinel: [HIGH] Fix Server-Side Request Forgery in JobParser
google-labs-jules[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,10 @@ | ||
| ## 2025-02-12 - [Critical] API Authentication Fail-Open Default | ||
| **Vulnerability:** The API authentication mechanism (`api/auth.py`) defaulted to allowing access if the `RESUME_API_KEY` environment variable was not set ("dev mode"). Additionally, it used a timing-vulnerable string comparison for the API key check. | ||
| **Learning:** "Dev mode" defaults that bypass security controls are dangerous because they can easily be deployed to production by accident, leaving the system wide open. | ||
| **Prevention:** Implement a "fail-closed" strategy. If a security configuration (like an API key) is missing, the application should refuse to start or deny all requests, rather than failing open. Always use `secrets.compare_digest` for sensitive string comparisons. | ||
| ## 2024-03-22 - [JobParser] Add SSRF protection | ||
|
|
||
| ## 2025-02-19 - [Critical] LaTeX Injection in Cover Letter Generator | ||
| **Vulnerability:** The `CoverLetterGenerator` used a standard Jinja2 environment (intended for HTML/XML or plain text) to render LaTeX templates. This allowed malicious user input (or AI hallucinations) containing LaTeX control characters (e.g., `\input{...}`) to be injected directly into the LaTeX source, leading to potential Local File Inclusion (LFI) or other exploits. | ||
| **Learning:** Jinja2's default `autoescape` is context-aware based on file extensions, but usually only for HTML/XML. It does NOT automatically escape LaTeX special characters. Relying on manual filters (like `| latex_escape`) in templates is error-prone and brittle, as developers might forget to apply them to every variable. | ||
| **Prevention:** Always use a dedicated Jinja2 environment for LaTeX generation that enforces auto-escaping via a `finalize` hook (e.g., `tex_env.finalize = latex_escape`). This ensures *all* variable output is sanitized by default, providing defense-in-depth even if the template author forgets explicit filters. | ||
| **Vulnerability:** | ||
| The `JobParser.parse_from_url` method passed arbitrary user-provided URLs directly to `requests.get` without any validation. This exposed the application to Server-Side Request Forgery (SSRF) attacks, where an attacker could coerce the server into making requests to internal network resources (e.g., AWS IMDS at `169.254.169.254`, `localhost`, etc). | ||
|
|
||
| **Learning:** | ||
| When an application takes a URL from untrusted user input and makes a server-side request using it, it is critical to resolve the hostname and validate the target IP address to ensure it does not belong to private or reserved IP ranges. Additionally, the IP validation should fail securely if resolution errors occur, and `0.0.0.0` needs explicit checks as it may resolve to localhost depending on the environment. Time-of-check to time-of-use (TOCTOU) issues via DNS rebinding can still technically occur if the hostname is passed to requests instead of the verified IP, but validating the IP is a crucial first step. | ||
|
|
||
| **Prevention:** | ||
| Always validate both the scheme and the resolved IP address (using a tool like Python's `ipaddress` library with `is_private`, `is_loopback`, `is_reserved`, etc.) before making requests to user-supplied URLs. Ensure the failure modes fail closed instead of open. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (bug_risk): Catching broad
ValueError/RuntimeErrorhere may hide programming errors unrelated to URL fetching.This
except (requests.RequestException, ValueError, RuntimeError)will also catchValueError/RuntimeErrorfrom_parse_htmlor other later code, incorrectly rewrapping them as fetch failures. Please restrict this handler to the concrete exceptions raised by_fetch_url_safe/requests, or split thetryso parsing errors are not masked as network/URL-fetch errors.Suggested implementation:
If there are other calls to
_parse_htmlwrapped in the same broadexcept (requests.RequestException, ValueError, RuntimeError)pattern elsewhere in this file, they should be refactored similarly: keep the exception handler around only the fetch/validation logic, and let parsing errors propagate normally.