-
Notifications
You must be signed in to change notification settings - Fork 34
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 prefix validation edge-case when extracting #715
Conversation
Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is subtle - nice catch! Can you add a test or testdata sample that verifies we continue to get this right?
Will do! |
Added the samples that were running into this in chainguard-dev/malcontent-samples#48. |
c2010ca
to
0ef7ab6
Compare
Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
Signed-off-by: Evan Gibler <20933572+egibs@users.noreply.github.com>
I'm going to have a follow-up PR to test the new logic (it definitely works but I don't want to hold up the release). The new sample data only contain data files, so their refreshes and tests will need to selectively use that to prevent negatively affecting other tests (otherwise they'll run afoul of the new clean <= 2 severity check). It might just be easier to add some unit tests, but TBD. Edit: unit tests were easier 🙂 |
Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
@@ -48,6 +48,11 @@ func isSupportedArchive(path string) bool { | |||
return archiveMap[getExt(path)] | |||
} | |||
|
|||
// isValidPath checks if the target file is within the given directory. | |||
func isValidPath(target, dir string) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still works as expected:
$ go run cmd/mal/mal.go --all analyze out/chainguard-dev/malcontent-samples/linux/clean/gitlab-rails/iosswift.tar.gz
🔎 Scanning "out/chainguard-dev/malcontent-samples/linux/clean/gitlab-rails/iosswift.tar.gz"
├─ 🟡 out/chainguard-dev/malcontent-samples/linux/clean/gitlab-rails/iosswift.tar.gz ∴ /project.bundle [MEDIUM]
│ ≡ credential [MEDIUM]
│ 🟡 sniffer/bpf — BPF (Berkeley Packet Filter): bpf
│ ≡ networking [MEDIUM]
│ 🟡 tcp/ssh — Supports SSH (secure shell)
│ ≡ process [LOW]
│ 🔵 chdir — changes working directory: cd B
│
├─ 🔵 out/chainguard-dev/malcontent-samples/linux/clean/gitlab-rails/iosswift.tar.gz ∴ /tree/project.json [LOW]
│ ≡ credential [LOW]
│ 🔵 password — references a 'password': require_password_to_approve
│
Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
I noticed that several
.tar.gz
files have been failing to extract:Turns out, we were checking the target path for a prefix with
/
appended, so the check would fail (and I was reporting the header name rather than the target file name).This PR checks for just the clean directory name instead (and we're already handling relative path traversal checks elsewhere).
With these changes: