Potential fix for code scanning alert no. 1: Server-side request forgery#42
Open
Potential fix for code scanning alert no. 1: Server-side request forgery#42
Conversation
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
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.
Potential fix for https://github.com/saad2134/donor-sync/security/code-scanning/1
In general, the fix is to prevent arbitrary user input from controlling the URL used in
fetch. Instead of accepting a full URL, the code should either (a) select from a fixed set of known‑good base URLs or (b) validate the provided URL strictly and reject anything that is not an HTTPS URL to an expected host (and possibly path prefix). This ensures the server only makes outbound requests to intended verification providers and not to arbitrary internal or external endpoints.The least invasive, functionality‑preserving change here is to parse
user_json_urlwith the built‑inURLclass, validate its components (scheme, hostname, optionally port and pathname), and only proceed withfetchif it passes these checks. Otherwise, return a 400 error. We don’t need new libraries for this; Node/Next.js already providesURL. Concretely, infrontend-web/app/api/verify-email/route.ts, right after checking thatuser_json_urlis present (after line 7–9) and beforefetch, we can:parsed.protocol === 'https:'(or'http:'too if truly needed, but preferably just HTTPS),parsed.hostnamebelongs to an allow‑list of acceptable verification providers (for example, a single provider domain, or a small set drawn from environment variables).Then, instead of calling
fetch(user_json_url, ...), callfetch(validatedUrl.toString(), ...)(wherevalidatedUrlis the parsedURLthat has passed the checks). This preserves existing behavior for legitimate URLs while blocking SSRF vectors.Suggested fixes powered by Copilot Autofix. Review carefully before merging.