Skip to content

Commit d0e719f

Browse files
authored
Merge pull request #128 from mattn/fix/nsite-path-traversal
nsite: fix path traversal vulnerability in download command
2 parents 405be6e + 1878422 commit d0e719f

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

nsite.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,11 @@ var nsite = &cli.Command{
273273
signer := keyer.NewReadOnlySigner(pk)
274274

275275
for path, hash := range mnf.Paths {
276-
fullPath := filepath.Join(outputDir, filepath.FromSlash(strings.TrimPrefix(path, "/")))
276+
relPath := strings.TrimPrefix(path, "/")
277+
if !filepath.IsLocal(relPath) {
278+
return fmt.Errorf("manifest path %q escapes output directory", path)
279+
}
280+
fullPath := filepath.Join(outputDir, filepath.FromSlash(relPath))
277281
if err := os.MkdirAll(filepath.Dir(fullPath), 0o755); err != nil {
278282
return fmt.Errorf("failed to create %s: %w", filepath.Dir(fullPath), err)
279283
}

0 commit comments

Comments
 (0)