Skip to content

Potential fix for code scanning alert no. 24: Server-side request forgery#29

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

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

Conversation

@Dargon789
Copy link
Owner

@Dargon789 Dargon789 commented Oct 2, 2025

Potential fix for https://github.com/Dargon789/mempool/security/code-scanning/24

To fix this SSRF vulnerability, we must ensure that user-supplied data cannot arbitrarily control the target of the server-side HTTP request. As seen in other functions like $getAcceleratorAccelerationsHistoryAggregated and $getAcceleratorEstimate, the code uses an allowedPaths allow-list to restrict which paths may be proxied/fetched based on user input, mapping user-supplied input to a controlled, known set of API endpoints. We should replicate this pattern in $getAcceleratorAccelerationsStats.

Specifically:

  • Add an allowedPaths mapping specifying valid relative API endpoints.
  • Retrieve the requested path from the user's request, strip the /api/v1/services/ prefix, and check if it exists in the allow-list.
  • Only make the proxied request if the path is explicitly allowed; otherwise, return a 400 error.
  • No change to imports is needed.
  • Only lines within the $getAcceleratorAccelerationsStats method require editing.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

Summary by Sourcery

Bug Fixes:

  • Restrict proxied requests in $getAcceleratorAccelerationsStats to an explicit allow-list of valid API paths and return 400 for invalid paths

…gery

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: AU_gdev_19 <64915515+Dargon789@users.noreply.github.com>
@sourcery-ai
Copy link

sourcery-ai bot commented Oct 2, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Implements SSRF mitigation in $getAcceleratorAccelerationsStats by introducing an allow-list for service paths and validating user-supplied input before proxying requests.

Sequence diagram for SSRF mitigation in $getAcceleratorAccelerationsStats

sequenceDiagram
  participant User as actor User
  participant API as AccelerationRoutes
  participant Logger
  participant Service as MEMPOOL_SERVICES.API

  User->>API: Request to /api/v1/services/{userPath}
  API->>API: Strip '/api/v1/services/' prefix
  API->>API: Check if userPath is in allowedPaths
  alt Path allowed
    API->>Service: GET /{safePath}
    Service-->>API: Response
    API-->>User: Return service response
  else Path not allowed
    API->>Logger: Log invalid path
    API-->>User: 400 error (Invalid path)
  end
Loading

Class diagram for updated AccelerationRoutes SSRF mitigation

classDiagram
  class AccelerationRoutes {
    +$getAcceleratorAccelerationsStats(req: Request, res: Response): Promise<void>
    -allowedPaths: {accelerations, accelerations/history, accelerations/stats, estimate}
  }
  AccelerationRoutes --> "uses" logger: Logger
  AccelerationRoutes --> "uses" config: Config
  AccelerationRoutes --> "uses" axios: Axios
Loading

File-Level Changes

Change Details Files
Add allow-list validation for proxied service paths to mitigate SSRF
  • Define allowedPaths mapping of valid relative endpoints
  • Extract userPath by stripping the /api/v1/services/ prefix
  • Validate safePath against allowedPaths, log errors and return 400 on invalid path
  • Build downstream URL using the validated path instead of raw input
backend/src/api/acceleration/acceleration.routes.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

@Dargon789 Dargon789 marked this pull request as ready for review October 2, 2025 08:20
Copy link

@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 5602b3e into master Oct 2, 2025
12 checks passed
@Dargon789 Dargon789 deleted the alert-autofix-24 branch October 2, 2025 08:40
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