Skip to content

validate write_files paths and snapshot dirs (review follow-up to #1) - #11

Closed
KoLDXr00T wants to merge 2 commits into
chxperiments:mainfrom
KoLDXr00T:hardening/name-and-spec-validation
Closed

validate write_files paths and snapshot dirs (review follow-up to #1)#11
KoLDXr00T wants to merge 2 commits into
chxperiments:mainfrom
KoLDXr00T:hardening/name-and-spec-validation

Conversation

@KoLDXr00T

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #1, addressing the review there:

Blocking item: write_files[].path reached a RUN line unvalidated

As raised in review, path only had a leading-/ check but is interpolated into RUN chmod <mode> <path>, so this parsed cleanly and executed touch /tmp/PWNED at build time:

blueprint:
  write_files:
    - path: "/tmp/x; touch /tmp/PWNED # "
      content: "hi"
      mode: "0644"

pathRe (^/[A-Za-z0-9/._-]+$, mirroring shellRe) now constrains paths to plain absolute paths, subsuming the old check. Rejection test added to the same grammar table.

Non-blocking nit

SnapshotsDir now calls ValidName itself 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.

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.
@KoLDXr00T

Copy link
Copy Markdown
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.

@KoLDXr00T KoLDXr00T closed this Aug 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant