Potential fix for code scanning alert no. 80: Server-side request forgery#205
Merged
Potential fix for code scanning alert no. 80: Server-side request forgery#205
Conversation
…gery Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Signed-off-by: Dargon789 <64915515+Dargon789@users.noreply.github.com>
Reviewer's GuideRestrict the registry URL in getRegistryUrl by validating its hostname against a predefined allow-list and refusing untrusted hosts. Class diagram for updated registry URL validationclassDiagram
class getRegistryUrl {
+getRegistryUrl()
}
class isAllowedRegistryHostname {
+isAllowedRegistryHostname(urlString: string): boolean
}
class ALLOWED_REGISTRY_HOSTS {
<<Array<string>>
}
getRegistryUrl --> isAllowedRegistryHostname
getRegistryUrl --> ALLOWED_REGISTRY_HOSTS
isAllowedRegistryHostname --> ALLOWED_REGISTRY_HOSTS
Flow diagram for registry URL validation processflowchart TD
A["Read registry URL from environment (npm_config_registry, REGISTRY_URL, or default)"] --> B["Validate hostname with isAllowedRegistryHostname"]
B -->|Allowed| C["Return registry URL"]
B -->|Not allowed| D["Throw error: Refusing to use registry URL not in allowed list"]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
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/Dargon789/foundry/security/code-scanning/80
To fix the SSRF vulnerability, ensure that the registry URL used for package downloads is restricted. Rather than accepting arbitrary values from environment variables, validate the resulting hostname against a fixed allow-list. Only permit URLs whose host is in a list of known good registries (such as
registry.npmjs.org, or other configured/trusted domains). Disallow internal IP addresses, AWS/GCP metadata endpoints, local network IPs, and other sensitive addresses.npm/src/const.ts, updategetRegistryUrl()to include validation for allowed hosts.isAllowedRegistryHostname.Allow-listing should be performed immediately after resolving the environment variable, never after, e.g., following redirects. The code in both files needs to enforce this.
Suggested fixes powered by Copilot Autofix. Review carefully before merging.
Summary by Sourcery
Enforce host allow-list for registry URLs in getRegistryUrl to mitigate SSRF vulnerabilities by validating and restricting environment-provided registry addresses.
Bug Fixes:
Enhancements: