Harden SSRF in HandwrittenText/generate.py#23
Open
eprifti wants to merge 1 commit into
Open
Conversation
get_handwritten() called requests.get(link) on a caller-provided URL with no scheme check, no timeout, and redirects enabled — reachable to cloud metadata endpoints (e.g. 169.254.169.254) and arbitrary hosts. On older validators (<0.20) the URL validator also accepts non-HTTP schemes, further widening the surface. - Require scheme to be http:// or https:// before fetching - timeout=10 to prevent hangs - allow_redirects=False to prevent open-redirect pivots - raise_for_status() so 4xx/5xx errors surface instead of feeding error pages into the HTML parser Reported in alphanumericslab#22.
This was referenced Apr 18, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
get_handwritten()incodes/ecg-image-generator/HandwrittenText/generate.pycallsrequests.get(link)on a caller-provided URL (the--linkCLI flag) with no scheme check, no timeout, no response-size cap, and redirects enabled. This creates an SSRF surface:file://,gopher://,dict://) are accepted byvalidators.urlin versions <0.20http://169.254.169.254/latest/meta-data/) on AWS/GCP/AzureChange
Four-line, behaviour-preserving hardening:
Related
Test plan
validators.urlbranch).txtbranchHappy to adjust the timeout or add a host allowlist if you'd prefer stricter defaults.