-
Notifications
You must be signed in to change notification settings - Fork 301
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Disallow artifact path traversal, escape-hatch experiment #2815
Conversation
* Remove astonishing `i += 100` loop * Rename getTargetPath to targetPath * Rename args (they're both paths, with different purposes) * Rename internal variables * Use filepath.Join where appropriate * Add call to filepath.Clean for dlPath * Rewrite tests in table-driven form * Remove ...x/x/x/x/x/x/x... test
* Remove astonishing `i += 100` loop * Rename getTargetPath to targetPath * Rename args (they're both paths, with different purposes) * Rename internal variables * Use filepath.Join where appropriate * Add call to filepath.Clean for dlPath * Rewrite tests in table-driven form * Remove ...x/x/x/x/x/x/x... test
4a4a257
to
822ac07
Compare
// of the download path, then trim the last component of the destination. | ||
lastIndex := len(destPathComponents) - 1 | ||
lastDestComponent := destPathComponents[lastIndex] | ||
if lastDestComponent == dlPathComponents[0] { |
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.
not relevant to this PR, but this isn't mentioned anywhere in the doc: https://buildkite.com/docs/agent/v3/cli-artifact#downloading-artifacts-artifact-download-examples
😮
agent/download.go
Outdated
if c := dlPathComponents[0]; c != "" && c != ".." { | ||
break | ||
} | ||
dlPathComponents = dlPathComponents[1:] |
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.
I feel mutating users' intention is a bit questionable. It's likely to cause some support tickets. 🤔
And given they can add relative path in both download path and destination path, is this fix sufficient?
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.
I answered this out of band, but basically, it's less surprising if a user has deliberately written the command:
buildkite-agent artifact download "*foo" ../../dest
than if they wrote the following (and "*foo" happened to match an artifact with path "../../dest"):
buildkite-agent artifact download "*foo" .
I'm strongly considering inverting the experiment, as there's little evidence I can find that anyone is relying on the old behaviour. |
Description
Prevent
..
path components in artifact records from causingartifact download
to traverse outside the destination path, unless a new experiment is enabled.A secondary change is the removal of the loop from target path calculation that compared every 100th download path component against the final destination path component; the probability anyone has exercised the code path is effectively zero, and the behaviour would be incredibly surprising if it were hit.
Context
https://linear.app/buildkite/issue/PS-68/fix-surprising-agent-behaviour-in-artifact-download
Changes
..
path componentsfor ... i += 100
loopTesting
go test ./...
). Buildkite employees may check this if the pipeline has run automatically.go fmt ./...
)