Skip to content

fix: Potential fix for code scanning alert no. 12: Uncontrolled data used in path expression#13

Merged
skyoo2003 merged 3 commits into
mainfrom
alert-autofix-12
Apr 20, 2026
Merged

fix: Potential fix for code scanning alert no. 12: Uncontrolled data used in path expression#13
skyoo2003 merged 3 commits into
mainfrom
alert-autofix-12

Conversation

@skyoo2003
Copy link
Copy Markdown
Owner

Potential fix for https://github.com/skyoo2003/devcloud/security/code-scanning/12

Use strict input validation for uploadID before any filesystem path construction/use in uploadPart.
Best fix without changing behavior: enforce that uploadID matches 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:

  • Add a package-level regex for upload ID validation (allowlist).
  • In uploadPart, reject invalid uploadID early with an S3-style InvalidArgument response.
  • Keep existing filepath.Base and metadata checks; this adds defense-in-depth and satisfies path taint concerns.

No new imports are required because regexp is already imported.

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

…in path expression

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

sourcery-ai Bot commented Apr 19, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds 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

Change Details Files
Introduce allowlist-based validation for multipart upload IDs and enforce it early in uploadPart.
  • Define a package-level regular expression that only allows upload IDs consisting of 16–128 hexadecimal characters.
  • Add an early check in uploadPart that validates the uploadID against the regex and returns an S3 InvalidArgument error if it fails.
  • Leave existing partNumber validation, filepath.Base usage, and metadata lookups unchanged to preserve behavior while adding defense-in-depth.
internal/services/s3/provider.go

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

@skyoo2003 skyoo2003 changed the title Potential fix for code scanning alert no. 12: Uncontrolled data used in path expression fix: Potential fix for code scanning alert no. 12: Uncontrolled data used in path expression Apr 19, 2026
@skyoo2003 skyoo2003 self-assigned this Apr 19, 2026
@skyoo2003 skyoo2003 marked this pull request as ready for review April 19, 2026 18:50
Copy link
Copy Markdown
Contributor

@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 - I've left some high level feedback:

  • 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).
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).

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.

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".
@skyoo2003 skyoo2003 merged commit 2a31d7f into main Apr 20, 2026
10 checks passed
@skyoo2003 skyoo2003 deleted the alert-autofix-12 branch April 20, 2026 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working services AWS service implementations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant