Skip to content

Prevent path traversal in module resolution#1353

Merged
ije merged 1 commit into
mainfrom
path-traversal
May 6, 2026
Merged

Prevent path traversal in module resolution#1353
ije merged 1 commit into
mainfrom
path-traversal

Conversation

@ije
Copy link
Copy Markdown
Member

@ije ije commented May 6, 2026

No description provided.

Copilot AI review requested due to automatic review settings May 6, 2026 01:49
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens server-side module resolution to prevent path traversal by validating that resolved module file paths remain within the build working directory (ctx.wd), reducing the risk of resolving/reading files outside the intended package workspace.

Changes:

  • Add a working-directory boundary check after computing a module’s resolved filename under node_modules/<pkgName>/....
  • Fail resolution with a generic error when the computed path escapes the working directory.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server/build.go

filename = path.Join(ctx.wd, "node_modules", ctx.esmPath.PkgName, modulePath)
// check if the filename is within the working directory
if !strings.HasPrefix(filename, ctx.wd+string(os.PathSeparator)) {
@ije ije merged commit 962ee4f into main May 6, 2026
9 checks passed
@ije ije deleted the path-traversal branch May 6, 2026 05:15
@ije ije mentioned this pull request May 8, 2026
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.

2 participants