Skip to content

Potential fix for code scanning alert no. 80: Server-side request forgery#205

Merged
Dargon789 merged 1 commit intomasterfrom
alert-autofix-80
Oct 24, 2025
Merged

Potential fix for code scanning alert no. 80: Server-side request forgery#205
Dargon789 merged 1 commit intomasterfrom
alert-autofix-80

Conversation

@Dargon789
Copy link
Copy Markdown
Owner

@Dargon789 Dargon789 commented Oct 24, 2025

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.

  • In npm/src/const.ts, update getRegistryUrl() to include validation for allowed hosts.
  • Provide an allow-list (array) of hostnames, and check the computed URL against it.
  • If the URL host is not in the allow-list, throw an error (or, for greatest safety, default to the npmjs registry).
  • Optionally, for flexibility, permit adding to the allow-list by configuration, but never allow arbitrary values.
  • You may add a helper method like isAllowedRegistryHostname.
  • Document the list and consider whether subdomains should be permitted.

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:

  • Reject registry URLs whose hostnames are not in a fixed allow-list and throw an error to prevent unauthorized SSRF targets

Enhancements:

  • Introduce ALLOWED_REGISTRY_HOSTS array and isAllowedRegistryHostname helper to centralize and streamline registry host validation

…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>
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Oct 24, 2025

Reviewer's Guide

Restrict the registry URL in getRegistryUrl by validating its hostname against a predefined allow-list and refusing untrusted hosts.

Class diagram for updated registry URL validation

classDiagram
    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
Loading

Flow diagram for registry URL validation process

flowchart 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"]
Loading

File-Level Changes

Change Details Files
Validate registry URLs using a trusted allow-list
  • Define ALLOWED_REGISTRY_HOSTS array with approved domains
  • Implement isAllowedRegistryHostname helper to parse and check hostnames
  • Capture the candidate URL in getRegistryUrl before returning
  • Invoke the helper in getRegistryUrl and throw an error if validation fails
npm/src/const.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@vercel
Copy link
Copy Markdown

vercel bot commented Oct 24, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
next Ready Ready Preview Comment Oct 24, 2025 8:43am
react Ready Ready Preview Comment Oct 24, 2025 8:43am

@snyk-io
Copy link
Copy Markdown

snyk-io bot commented Oct 24, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Dargon789 Dargon789 merged commit a970332 into master Oct 24, 2025
25 of 38 checks passed
@Dargon789 Dargon789 deleted the alert-autofix-80 branch October 24, 2025 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant