Skip to content

Make the path validators correct on Windows, and follow links (#1000) - #1036

Merged
scttfrdmn merged 6 commits into
mainfrom
fix/1000
Oct 17, 2026
Merged

scttfrdmn merged 6 commits into
mainfrom
fix/1000

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #1000

What each validator protects, and the decision per function

function callers whose path rules now
ValidatePathForReading cmd/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) host host OS rules
ValidateMountPath none in production instance (a Linux spore) POSIX (path) on every host
SanitizePath none in production display string forward slashes on every host

ValidatePathForReading

  • Windows: refuses %SystemRoot%, %SystemDrive%\Windows, ProgramData (EC2Launch state, OpenSSH host keys and administrators_authorized_keys, spored's log) and System Volume Information, with C:\ 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, so C:\Windows.\x opens C:\Windows\x).
  • Every OS: refuses any .. element before cleaning (notes..txt is now allowed), refuses NUL bytes, and compares roots case-insensitively (on macOS /ETC/passwd is /etc/passwd). It also resolves symlinks and junctions in the longest existing prefix with filepath.EvalSymlinks and checks the result too. That catches a link to /etc or C:\Windows, and also an 8.3 short name like C:\WINDOW~1. It works even when the leaf, or a glob, doesn't exist yet. /private/etc and /var/root were added for macOS.
  • filepath.IsLocal / os.Root don'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 follow IsLocal's (no colons past the drive, no reserved names) but are stricter about CON.txt.

Queue runner: a second hole, on Linux too

Only the pattern was checked, so /e*c/passwd, or <results>/l*/hosts where link -> /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) and path_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\..., an mklink /J junction, 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 counting RoundTripper, 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, /etc itself, /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=windows but not run. Once #973 lands, remove pkg/security from scripts/windows-test-skips.txt. That file doesn't exist on main yet, so this PR can't edit it.

make check: everything passes except the known Docker-only TestGenerateWrapper_ChownFixesCrossUIDStickyUnlink_Docker. make check-nested: all 9 modules pass. GOOS=windows go vet ./... is clean apart from the pre-existing pkg/service / pkg/taskproto test-compile errors (#925, fixed by #941), which also fail on main.

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).

@codecov

codecov Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.15789% with 18 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/security/path.go 88.40% 9 Missing and 7 partials ⚠️
pkg/security/path_resolve_other.go 83.33% 1 Missing and 1 partial ⚠️

📢 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.
@scttfrdmn
scttfrdmn merged commit 95f376c into main Oct 17, 2026
8 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1000 branch October 17, 2026 00:06
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.

security: path validators are POSIX-only, so on Windows ValidatePathForReading denies nothing

1 participant