Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: zip slip issue #19711

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions util/io/files/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,16 @@
}
return fmt.Errorf("error while iterating on tar reader: %w", err)
}
if header == nil || header.Name == "." {
if header == nil {
continue
}

target := filepath.Join(dstPath, header.Name)
// Sanity check to protect against zip-slip

normalizedHeaderName := filepath.Clean(header.Name)
if normalizedHeaderName == "." || strings.Contains(normalizedHeaderName, "..") {

Check failure on line 87 in util/io/files/tar.go

View workflow job for this annotation

GitHub Actions / Check changes to generated code

undefined: strings

Check failure on line 87 in util/io/files/tar.go

View workflow job for this annotation

GitHub Actions / Lint Go code

undefined: strings (typecheck)

Check failure on line 87 in util/io/files/tar.go

View workflow job for this annotation

GitHub Actions / Lint Go code

undefined: strings) (typecheck)

Check failure on line 87 in util/io/files/tar.go

View workflow job for this annotation

GitHub Actions / Lint Go code

undefined: strings) (typecheck)

Check failure on line 87 in util/io/files/tar.go

View workflow job for this annotation

GitHub Actions / Lint Go code

undefined: strings) (typecheck)

Check failure on line 87 in util/io/files/tar.go

View workflow job for this annotation

GitHub Actions / Build & cache Go code

undefined: strings
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if normalizedHeaderName == "." || strings.Contains(normalizedHeaderName, "..") {
if normalizedHeaderName == "." || strings.Contains(normalizedHeaderName, "..") {

you need to import the strings package in order to use the method.

continue
}

target := filepath.Join(dstPath, normalizedHeaderName)
if !Inbound(target, dstPath) {
return fmt.Errorf("illegal filepath in archive: %s", target)
}
Expand Down
Loading