Repository navigation
fix(sandbox): validate pip specifiers against shell injection - #679
Merged
Merged
Conversation
sanitizePipPackage validated only the base package name and rejected a short list of shell metacharacters. The raw specifier was then joined into `pip install --no-cache-dir <spec>`, so whitespace, `<`, `>`, quotes and `#` passed through — e.g. `pkg>=1.0 --index-url=...` reached pip as extra options, and `<`/`>` could act as shell redirections. Validate the whole specifier against a strict allowlist (alphanumerics plus . _ + - ! ~ < > = * , [ ]; no whitespace, path separators, quotes or option prefixes) and shell-quote each accepted specifier before joining. This is defence in depth: a caller who can call PipInstall can already call Exec with an arbitrary command in the same sandbox, so it is not a privilege boundary.
Contributor
|
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 #676. Addresses F10 from
docs/security/sandbox-security-review.md.Change
sanitizePipPackagenow validates the whole specifier against a strict allowlist instead of only the base package name:. _ + - ! ~ < > = * , [ ]./), quotes,;,&,|,$, backticks, parentheses,#, and any leading-(so--index-url=…/-e …cannot be smuggled in).PipInstallalso shell-quotes each accepted specifier (shellSingleQuote) before joining, so the version-comparison characters (<,>,=) cannot act as shell redirections.Scope / severity
This is defence in depth, not a privilege boundary: a caller who can call
PipInstallcan already callExecwith an arbitrary command in the same sandbox. The value is that the sanitizer now actually enforces the property it claims, and thatPipInstallis safe if it is ever exposed to a less-privileged caller (e.g. a future MCP tool).Tests
New
pkg/sandboxmatrix/grpc/pip_test.go:TestSanitizePipPackage— valid names/versions/extras/comma specifiers; rejects injection, whitespace, path traversal, option injection and newlines.TestShellSingleQuote— quoting and embedded-quote escaping.Validation
go build ./... go test ./pkg/sandboxmatrix/... -count=1All pass.
Remaining follow-ups (separate PRs)
K8E_E2B_SIGNING_SECRETin production.SnapshotPut/Get/List) per tenant.SeccompProfile: RuntimeDefaultafter workload validation.