Skip to content

fix: validate TEST_TMPDIR path traversal in getWritableDirs#29648

Open
Ashutosh0x wants to merge 1 commit into
bazelbuild:masterfrom
Ashutosh0x:fix/test-tmpdir-validation
Open

fix: validate TEST_TMPDIR path traversal in getWritableDirs#29648
Ashutosh0x wants to merge 1 commit into
bazelbuild:masterfrom
Ashutosh0x:fix/test-tmpdir-validation

Conversation

@Ashutosh0x
Copy link
Copy Markdown
Contributor

Fixes #29457

Summary

AbstractSandboxSpawnRunner.getWritableDirs() reads TEST_TMPDIR from the action environment and passes it directly to addWritablePath() without validation. A malicious rule can set TEST_TMPDIR to a relative path containing ../ traversal sequences, causing the resolved path to escape the sandbox exec root.

Root Cause

Same class of issue as #3296 (TMPDIR sanitization). The fix was partial -- TMPDIR was sanitized but TEST_TMPDIR was missed.

Variable Sanitized? Risk
TMPDIR Yes None (fixed in #3296)
TEST_TMPDIR No Traversal sequences can escape sandbox

Fix

Added validateTestTmpdir() using PathFragment.containsUplevelReferences() to reject ../ traversal before addWritablePath(). Absolute paths are allowed (legitimate via --test_tmpdir).

Related

@github-actions github-actions Bot added team-Local-Exec Issues and PRs for the Execution (Local) team awaiting-review PR is awaiting review from an assigned reviewer labels May 26, 2026
Add validateTestTmpdir() to reject '../' traversal in TEST_TMPDIR
before addWritablePath(). Add direct :pathfragment dep to BUILD.

Fixes bazelbuild#29457
@Ashutosh0x Ashutosh0x force-pushed the fix/test-tmpdir-validation branch from bb76a78 to 0e016b4 Compare May 26, 2026 08:44
@Ashutosh0x
Copy link
Copy Markdown
Contributor Author

Hi @meteorcloudy @iancha1992 — Requesting review on this security fix. It validates TEST_TMPDIR paths in getWritableDirs to prevent path traversal outside the sandbox. Minimal change, ready for merge. Thanks!

@iancha1992
Copy link
Copy Markdown
Member

iancha1992 commented May 27, 2026

cc: @meisterT @Wyverald

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-review PR is awaiting review from an assigned reviewer team-Local-Exec Issues and PRs for the Execution (Local) team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

linux-sandbox: TEST_TMPDIR from action env is used as -w bind mount without validation; TMPDIR is sanitized, TEST_TMPDIR is not

2 participants