Skip to content

fix(sandbox): validate pip specifiers against shell injection - #679

Merged
xiaods merged 2 commits into
mainfrom
fix/sandbox-pip-specifier-injection
Nov 16, 2026
Merged

xiaods merged 2 commits into
mainfrom
fix/sandbox-pip-specifier-injection

Conversation

@xiaods

@xiaods xiaods commented Nov 16, 2026

Copy link
Copy Markdown
Owner

Summary

Follow-up to #676. Addresses F10 from docs/security/sandbox-security-review.md.

Change

sanitizePipPackage now validates the whole specifier against a strict allowlist instead of only the base package name:

  • Allowed: alphanumerics plus . _ + - ! ~ < > = * , [ ].
  • Rejected: whitespace, path separators (/), quotes, ;, &, |, $, backticks, parentheses, #, and any leading - (so --index-url=… / -e … cannot be smuggled in).

PipInstall also 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 PipInstall can already call Exec with an arbitrary command in the same sandbox. The value is that the sanitizer now actually enforces the property it claims, and that PipInstall is 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=1

All pass.

Remaining follow-ups (separate PRs)

  • F8: require a credential on loopback if the gateway host is shared.
  • F11: require an explicit K8E_E2B_SIGNING_SECRET in production.
  • Scope snapshots (SnapshotPut/Get/List) per tenant.
  • Optionally SeccompProfile: RuntimeDefault after workload validation.

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.
@github-actions

Copy link
Copy Markdown
Contributor

Test Results

1 061 tests  +2   1 034 ✅ +2   6m 52s ⏱️ -17s
  121 suites ±0      27 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit 8f230fb. ± Comparison against base commit a737c24.

@sonarqubecloud

Copy link
Copy Markdown

@xiaods
xiaods merged commit 62847c3 into main Nov 16, 2026
7 of 8 checks passed
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