Skip to content

Commit ccdee2c

Browse files
committed
Add output path traversal protection and list available platforms in missing manifest error
1 parent 1ac836e commit ccdee2c

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

image.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@ func createOutputTar(ref ImageReference, tempDir, outputDir string, platform Pla
160160

161161
outputPath := filepath.Join(outputDir, imageFilename(ref, platform))
162162

163+
// Defense-in-depth: confirm the assembled path stays within the output directory.
164+
cleanOut := filepath.Clean(outputDir)
165+
cleanPath := filepath.Clean(outputPath)
166+
if !strings.HasPrefix(cleanPath, cleanOut+string(filepath.Separator)) {
167+
return "", fmt.Errorf("output path escapes cache directory: %s", cleanPath)
168+
}
169+
163170
log.Println("Creating tar archive...")
164171
if err := createTar(tempDir, outputPath); err != nil {
165172
return "", fmt.Errorf("failed to create tar: %w", err)

registry.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,13 @@ func (c *RegistryClient) selectManifestDigest(ref ImageReference, list *Manifest
282282
return c.getManifestByDigest(ref, m.Digest)
283283
}
284284
}
285-
if platform.Variant != "" {
286-
return nil, fmt.Errorf("no manifest found for platform %s/%s/%s", platform.OS, platform.Architecture, platform.Variant)
285+
286+
available := make([]string, 0, len(list.Manifests))
287+
for _, m := range list.Manifests {
288+
p := Platform{OS: m.Platform.OS, Architecture: m.Platform.Architecture, Variant: m.Platform.Variant}
289+
available = append(available, p.String())
287290
}
288-
return nil, fmt.Errorf("no manifest found for platform %s/%s", platform.OS, platform.Architecture)
291+
return nil, fmt.Errorf("no manifest found for platform %s; available: %s", platform, strings.Join(available, ", "))
289292
}
290293

291294
// parseManifestResponse parses the manifest response body based on content type

0 commit comments

Comments
 (0)