Repository navigation
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
ValidatePathForReading compared filepath.Abs against /etc-style prefixes, so on Windows it refused nothing. It now applies the host's rules: - Windows: refuses the Windows directory, ProgramData and System Volume Information (case-insensitive, either separator), UNC and \\?\, \\.\, \??\ prefixes, alternate data streams, reserved device names, and elements ending in a dot or space. - Every OS: any ".." element (before cleaning), NUL bytes, case-insensitive root comparison (macOS /ETC), and symlink/junction resolution of the longest existing prefix via filepath.EvalSymlinks; /private/etc and /var/root added for macOS. spored's queue runner now validates every glob match, not only the pattern, so a wildcard or a link through an allowed directory cannot upload a system file. ValidateMountPath describes a Linux instance path and now uses package path on every host; SanitizePath output is forward-slashed everywhere. Tests: host-neutral table plus build-tagged POSIX and Windows tables (drive letters, UNC, ADS, device names, junctions, 8.3 short names); the Windows string rules are also unit-tested on every OS. (#1000)
Since Go 1.23 (GODEBUG winsymlink=1) os.Lstat reports a junction or mount point as ModeIrregular and filepath.EvalSymlinks no longer follows it, so a junction to C:\Windows passed ValidatePathForReading. On Windows, open the longest existing prefix with FILE_FLAG_BACKUP_SEMANTICS and use GetFinalPathNameByHandle; refuse a reparse point that cannot be resolved. POSIX keeps EvalSymlinks.
This was referenced Oct 17, 2026
Merged
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.
Fixes #1000
What each validator protects, and the decision per function
ValidatePathForReadingcmd/launch_config.go(--user-data-file,--user-data @file, on the user's machine);pkg/agent/queue_runner.go(result-upload patterns, on the spore, Linux or Windows)ValidateMountPathpath) on every hostSanitizePathValidatePathForReading
%SystemRoot%,%SystemDrive%\Windows,ProgramData(EC2Launch state, OpenSSH host keys andadministrators_authorized_keys, spored's log) andSystem Volume Information, withC:\fallbacks when the env is empty. The comparison ignores case and accepts either separator. Also refused: UNC (\\host\c$\...used to get around the drive-letter check),\\?\,\\.\,\??\, alternate data streams (file:stream,::$DATA), reserved device names (CON, PRN, AUX, NUL, COM0-9/¹²³, LPT0-9/¹²³, CONIN$, CONOUT$, CLOCK$, with or without an extension), and elements ending in.or space (Windows strips these, soC:\Windows.\xopensC:\Windows\x)...element before cleaning (notes..txtis now allowed), refuses NUL bytes, and compares roots case-insensitively (on macOS/ETC/passwdis/etc/passwd). It also resolves symlinks and junctions in the longest existing prefix withfilepath.EvalSymlinksand checks the result too. That catches a link to/etcorC:\Windows, and also an 8.3 short name likeC:\WINDOW~1. It works even when the leaf, or a glob, doesn't exist yet./private/etcand/var/rootwere added for macOS.filepath.IsLocal/os.Rootdon't fit: callers legitimately read absolute paths anywhere outside the system directories, so there's no single root to confine reads to. The Windows element rules followIsLocal's (no colons past the drive, no reserved names) but are stricter aboutCON.txt.Queue runner: a second hole, on Linux too
Only the pattern was checked, so
/e*c/passwd, or<results>/l*/hostswherelink -> /etc, got through and uploaded the matched system file. Now every glob match is validated before it's uploaded.Tests
path_test.go(every OS): a host-neutral table; symlink-into-system-dir (the file, a dir above it, a nonexistent glob under it); every forbidden root refused in its own case and in swapped case; and the Windows string rules (windowsPathShapeError,underAnyRoot, root fallbacks) as tables, so they also run on Linux and macOS.path_unix_test.go(!windows) andpath_windows_test.go(windows): end-to-end host tables. Windows covers drive letters, mixed separators, case, UNC,\\?\, ADS, device names, trailing dot/space, root-relative\Windows\..., anmklink /Jjunction, and the 8.3 short name.pkg/agent/queue_runner_results_test.go: a wildcard through a symlink must be refused before any S3 request. It uses a countingRoundTripper, so no network and no HTTP fixture.Checked against reverts that compile: with only
ValidatePathForReading's body put back to the old one, the new tests fail: NUL, traversal that cleans to an allowed shape, all three symlink cases, every forbidden root in swapped case,/etcitself,/ETC,/private/etc. With only the per-match check disabled (false && err != nil), the queue test fails because the system file gets uploaded.Windows caveat: #973 (the Windows CI job) is not merged, so the Windows-tagged tests have been compiled and vetted with
GOOS=windowsbut not run. Once #973 lands, removepkg/securityfromscripts/windows-test-skips.txt. That file doesn't exist onmainyet, so this PR can't edit it.make check: everything passes except the known Docker-onlyTestGenerateWrapper_ChownFixesCrossUIDStickyUnlink_Docker.make check-nested: all 9 modules pass.GOOS=windows go vet ./...is clean apart from the pre-existingpkg/service/pkg/taskprototest-compile errors (#925, fixed by #941), which also fail onmain.Advisory caveat: the check runs before the caller's open, so a racing local attacker who swaps a link in between is out of scope (unchanged from before).