Skip to content

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

Merged
skyoo2003 merged 2 commits into
mainfrom
alert-autofix-5
Apr 19, 2026
Merged

fix: Potential fix for code scanning alert no. 5: Uncontrolled data used in path expression#20
skyoo2003 merged 2 commits into
mainfrom
alert-autofix-5

Conversation

@skyoo2003
Copy link
Copy Markdown
Owner

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

To fix this without changing intended behavior, validate path components (accountID, functionName) as single safe path segments before constructing filesystem paths.

Best approach in this code:

  • In internal/services/lambda/store.go, add a small validator method (for example validatePathComponent) that rejects:
    • empty values,
    • "." / "..",
    • any / or \ separators.
  • Call this validator in codePath for both accountID and functionName before filepath.Join.
  • Keep the existing base-directory containment check as defense-in-depth.
  • Also handle filepath.Abs errors instead of ignoring them.

This addresses all alert variants because they all converge on the same sink (os.WriteFile(path, ...)) and same tainted source path.

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

…n 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

Adds strict validation of path components used in Lambda code storage paths and propagates filesystem path resolution errors to fully address a code-scanning alert about uncontrolled data in path expressions.

File-Level Changes

Change Details Files
Introduce reusable validator for individual path components and use it in Lambda code path construction.
  • Add validatePathComponent helper that rejects empty values, dot/dot-dot, and any path separators in a path component.
  • Invoke validatePathComponent for accountID and functionName at the start of codePath to ensure both are single safe path segments.
internal/services/lambda/store.go
Strengthen path containment logic by handling errors from filepath.Abs instead of ignoring them.
  • Capture and return errors from filepath.Abs when resolving the base code directory.
  • Capture and return errors from filepath.Abs when resolving the cleaned code path before performing the prefix check.
internal/services/lambda/store.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

@github-actions github-actions Bot added the services AWS service implementations label Apr 19, 2026
@skyoo2003 skyoo2003 changed the title Potential fix for code scanning alert no. 5: Uncontrolled data used in path expression fix: Potential fix for code scanning alert no. 5: 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 14:30
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 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.

Resolve conflicts in internal/services/lambda/store.go by keeping
main's validPathComponent and filepath.Rel-based traversal detection,
which already covers the path traversal fix from this branch.
@github-actions github-actions Bot added the bug Something isn't working label Apr 19, 2026
@skyoo2003 skyoo2003 merged commit 84e5b99 into main Apr 19, 2026
10 checks passed
@skyoo2003 skyoo2003 deleted the alert-autofix-5 branch April 19, 2026 19:09
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