validate write_files paths and snapshot dirs (review follow-up to #1) - #11
Closed
KoLDXr00T wants to merge 2 commits into
Closed
validate write_files paths and snapshot dirs (review follow-up to #1)#11KoLDXr00T wants to merge 2 commits into
KoLDXr00T wants to merge 2 commits into
Conversation
Two changes from a source security review (analysis in bluebox-hardening/): 1. Sandbox names are now validated once, inside the sandbox package, by ValidName (letters/digits/._- , max 64, alphanumeric first char). Dir/DataDir/LogPath enforce it, so no command -- including destroy --data, reset and rename, which run os.RemoveAll/os.Rename on name-derived paths -- can act outside BLUEBOX_HOME via a crafted name like "../../something". 2. Bluefile fields that are data, not instructions, are validated at parse time so the generated Containerfile is a faithful rendering of the parsed spec: env keys must be identifiers and values cannot contain newlines (a newline would inject a Containerfile instruction), write_files modes must be octal (a mode like "0755; curl ...|sh" ran as a second shell command), blueprint user names/shells are constrained, packages must be plain tokens, and base must be whitespace-free. All shipped examples still parse; both packages gain table-driven regression tests.
Address review on chxperiments#1: - blueprint.write_files[].path reaches `RUN chmod <mode> <path>`, so a path like "/tmp/x; touch /tmp/PWNED #" ran as a second build command. It is now constrained to plain absolute paths by pathRe, which subsumes the old leading-"/" check. Regression test added. - SnapshotsDir now calls ValidName itself, matching the "validate where the path is built" rule the other path builders follow.
Contributor
Author
|
Closing as superseded: upstream 6c674ef landed the same two changes (write_files pathRe + SnapshotsDir ValidName) directly on main, so this PR now conflicts with its own content. I verified main's version matches mine functionally — only comment wording and test-string details differ. Nothing further needed here. Thanks for the fast turnaround on the review items. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #1, addressing the review there:
Blocking item:
write_files[].pathreached aRUNline unvalidatedAs raised in review,
pathonly had a leading-/check but is interpolated intoRUN chmod <mode> <path>, so this parsed cleanly and executedtouch /tmp/PWNEDat build time:pathRe(^/[A-Za-z0-9/._-]+$, mirroringshellRe) now constrains paths to plain absolute paths, subsuming the old check. Rejection test added to the same grammar table.Non-blocking nit
SnapshotsDirnow callsValidNameitself instead of relying on callers having validated first — consistent with where the other path builders enforce.Verification
go build,go vet,gofmt -l,go test ./internal/...all clean; all shipped examples still parse.