Skip to content

Commit a881715

Browse files
committed
fix: Added the security assumption comment to Generate() and a reference to it in GenerateMultiple
chore: newline
1 parent d035a38 commit a881715

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ nixos.qcow2
3737
http_cache.sqlite
3838
nix-sbom.spdx.json
3939
sbom.cdx.json
40-
sbom.csv
40+
sbom.csv

nix/packages/sbom/internal/nix/wrapper.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ func (w *Wrapper) Generate(derivationPath, outputPath string) error {
2626
return fmt.Errorf("derivation path does not exist: %s", derivationPath)
2727
}
2828

29-
// Validate and sanitize outputPath to prevent path traversal
29+
// Validate and sanitize outputPath to prevent path traversal.
30+
// Security assumption: outputPath is operator-controlled via command-line flags
31+
// (e.g., --output in main.go). Untrusted input must not be accepted here.
32+
// Allowing absolute paths that clean to system locations is intentional since
33+
// input is trusted. If Generate() becomes reachable from untrusted sources,
34+
// this validation must be strengthened.
3035
cleanOutputPath := filepath.Clean(outputPath)
3136
if strings.Contains(cleanOutputPath, "..") {
3237
return fmt.Errorf("invalid output path: path traversal detected")
@@ -54,7 +59,8 @@ func (w *Wrapper) GenerateMultiple(derivationPaths []string, outputPath string)
5459
return w.Generate(derivationPaths[0], outputPath)
5560
}
5661

57-
// Validate and sanitize outputPath to prevent path traversal
62+
// Validate and sanitize outputPath to prevent path traversal.
63+
// See security assumption comment in Generate().
5864
cleanOutputPath := filepath.Clean(outputPath)
5965
if strings.Contains(cleanOutputPath, "..") {
6066
return fmt.Errorf("invalid output path: path traversal detected")

0 commit comments

Comments
 (0)