fix: Potential fix for code scanning alert no. 12: Uncontrolled data used in path expression#13
Merged
Merged
Conversation
…in path expression Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Contributor
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds strict validation for S3 multipart upload IDs in uploadPart to mitigate an uncontrolled data in path expression code scanning alert, rejecting malformed upload IDs before any filesystem or metadata operations. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The
uploadIDPatternlength bounds (16–128 chars) implicitly encode assumptions about server-generated IDs; consider deriving these limits from the actual upload ID generator or documenting the rationale nearby to avoid future divergence. - If
uploadIDis validated in other paths (e.g., multipart init/complete handlers), you may want to reuseuploadIDPatternthere as well to keep validation centralized and consistent. - The new error message
"invalid upload id"differs slightly from existing wording patterns; consider aligning it with other S3-style messages in this file for consistency (e.g., capitalization or phrasing).
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `uploadIDPattern` length bounds (16–128 chars) implicitly encode assumptions about server-generated IDs; consider deriving these limits from the actual upload ID generator or documenting the rationale nearby to avoid future divergence.
- If `uploadID` is validated in other paths (e.g., multipart init/complete handlers), you may want to reuse `uploadIDPattern` there as well to keep validation centralized and consistent.
- The new error message `"invalid upload id"` differs slightly from existing wording patterns; consider aligning it with other S3-style messages in this file for consistency (e.g., capitalization or phrasing).Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Replace loose uploadIDPattern regex with shared.ValidateUploadID (exact 32-char lowercase hex matching generateUploadID output), add missing validation to listParts, and align error message casing to "uploadId".
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/skyoo2003/devcloud/security/code-scanning/12
Use strict input validation for
uploadIDbefore any filesystem path construction/use inuploadPart.Best fix without changing behavior: enforce that
uploadIDmatches the expected server-generated format (hex string). This codebase already uses hex utilities/imports, so validating as lowercase/uppercase hex with a reasonable non-empty length is appropriate and minimally invasive.Concretely in
internal/services/s3/provider.go:uploadPart, reject invaliduploadIDearly with an S3-styleInvalidArgumentresponse.filepath.Baseand metadata checks; this adds defense-in-depth and satisfies path taint concerns.No new imports are required because
regexpis already imported.Suggested fixes powered by Copilot Autofix. Review carefully before merging.