Potential fix for code scanning alert no. 25: Server-side request forgery#18
Merged
Potential fix for code scanning alert no. 25: Server-side request forgery#18
Conversation
…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>
Reviewer's GuideFix SSRF by validating Sequence diagram for SSRF-protected acceleration service requestsequenceDiagram
actor User
participant API as AccelerationRoutes
participant Logger
participant MempoolService
User->>API: HTTP request to /api/v1/services/{userPath}
API->>API: Extract userPath from req.originalUrl
API->>API: Lookup userPath in allow-list
alt userPath is allowed
API->>MempoolService: Forward request to safe endpoint
MempoolService-->>API: Response
API-->>User: Response
else userPath is not allowed
API->>Logger: Log invalid path
API-->>User: HTTP 400 with error
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey @Dargon789 - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `backend/src/api/acceleration/acceleration.routes.ts:51` </location>
<code_context>
+ const userPath = req.originalUrl.replace('/api/v1/services/', '');
+ const safePath = allowedPaths[userPath];
+ if (!safePath) {
+ logger.err(`Invalid path requested: ${userPath}`, this.tag);
+ res.status(400).send({ error: 'Invalid path' });
+ return;
</code_context>
<issue_to_address>
Logging user input directly may expose sensitive information.
Sanitize or restrict the logged userPath to prevent sensitive or malicious data from appearing in logs.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
if (!safePath) {
logger.err(`Invalid path requested: ${userPath}`, this.tag);
res.status(400).send({ error: 'Invalid path' });
return;
=======
if (!safePath) {
// Log only the attempted key, not the raw user input, to avoid leaking sensitive data
const sanitizedPath = Object.prototype.hasOwnProperty.call(allowedPaths, userPath) ? userPath : '[unrecognized]';
logger.err(`Invalid path requested: ${sanitizedPath}`, this.tag);
res.status(400).send({ error: 'Invalid path' });
return;
>>>>>>> REPLACE
</suggested_fix>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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/mempool/security/code-scanning/25
To fix the SSRF vulnerability, we need to ensure that user input (
req.originalUrl) is validated and sanitized before being used to construct theurl. Specifically:urldoes not allow path traversal or other manipulations that could redirect the request to unintended endpoints.The best approach is to use an allow-list to map user input to known, safe paths. This ensures that the outgoing request is limited to trusted endpoints.
Changes to make:
req.originalUrl.replace('/api/v1/services/', '')with a lookup in the allow-list.Suggested fixes powered by Copilot Autofix. Review carefully before merging.
Summary by Sourcery
Restrict service requests to a predefined set of safe endpoints by mapping user input through an allow-list and rejecting any unexpected paths to fix a server-side request forgery vulnerability
Bug Fixes:
Enhancements: