Skip to content

Commit 962ee4f

Browse files
authored
Prevent path traversal in module resolution (#1353)
1 parent b4af172 commit 962ee4f

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

server/build.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,10 @@ func (ctx *BuildContext) buildModule(analyzeMode bool) (meta *BuildMeta, include
728728
}
729729

730730
filename = path.Join(ctx.wd, "node_modules", ctx.esmPath.PkgName, modulePath)
731+
// check if the filename is within the working directory
732+
if !strings.HasPrefix(filename, ctx.wd+string(os.PathSeparator)) {
733+
return esbuild.OnResolveResult{}, fmt.Errorf("could not resolve module %s", specifier)
734+
}
731735

732736
// split the module that includes `export * from "external"` statement
733737
if entry.module && len(pkgJson.Dependencies)+len(pkgJson.PeerDependencies) > 0 && args.Kind == esbuild.ResolveJSImportStatement {

0 commit comments

Comments
 (0)