Repository navigation
fix(builtins): harden file builtins against host probes, size bombs and symlink escapes - #874
Merged
Merged
Conversation
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 the verified security and correctness findings from the review of file-touching builtins under
internal/builtins/. Each fix has a regression test that checks exit codes, stdout/stderr and sandbox filesystem effects.User-visible changes
Compat host-path remap (HIGH)
filepath.EvalSymlinkson the real host filesystem. Before, a script could probe whether arbitrary host paths existed (for exampleexport GBASH_COMPAT_ROOT=/private/tmp; mkdir /claude-501succeeded because the host path existed).Config.CompatHostRoots/gbash.WithCompatHostRootsor the repeatablegbash --compat-host-root DIRflag.GBASH_COMPAT_ROOT,abs_top_builddirandabs_top_srcdirin the script env no longer rewrite paths.scripts/gnu-test.shwas the only thing relying on the old behaviour. Its launcher now passes both the logical and physical workdir.Size limits and timeouts (HIGH)
truncate,dd(block sizes, seeks, writes),gunzipandtar -xreject sizes beyondMaxFileBytesbefore allocating and reportFile too large.MaxFileBytesis unlimited. Before,echo a | dd bs=200000000000000caused a fatal Go out-of-memory error.splitcreates at most 100000 files per invocation. The widths forsplit -a,csplit -nand--suffix-formatare capped at 4096.csplitreads its input through the boundedcommands.ReadAll.tar (HIGH/MEDIUM)
-Croot through archive-created symlink chains (a -> .,a/b -> ..,a/b/escaped.txt).tar -cf out.tar .now names members./…, as GNU does. It also skips its own archive with a warning instead of trying to archive it.cp / install (HIGH/MEDIUM)
Realpathfallback. Before,ln a b; cp a bsilently truncatedaon MemoryFS, and in follow-modecp a link-to-adid the same.cp -brefuses to replace a directory backup (cannot backup … Is a directory).cp -r d dlink/subrecursed forever and ignored the timeout.find (MEDIUM)
findnow walks with Lstat by default (GNU-P) and follows symlinks only with-H,-Lor-follow. It supports-type l, and-Lreports loops instead of following them.-deletecan no longer delete outside the tree through symlinked directories. Under the default SymlinkDeny policy, a symlink in the tree no longer aborts the whole search with exit 126.mktemp (MEDIUM)
mktemp -p /tmp XXXXXX,--tmpdir=/tmp XXXXXXandTMPDIR=/tmp mktemp -t XXXXXXnow create the file inside/tmp. Before, they created/tmpXXXXXXin/.SPEC updates
--compat-host-rootCLI flag entry andCompatHostRootsto theConfiglisting.Notes for reviewers
CompatHostRootsfrom the embedder down to builtins, this PR touches files outsideinternal/builtins:api.go,options.go,internal/runtime,internal/shell/core.go,commands/(newInvocationOptions.CompatHostRootsand(*Invocation).CompatHostRoots()) andcli/runtime_options.go.pwdandmkdirstill readGBASH_COMPAT_ROOTfrom the env, but only to formatpwdoutput and to pick the umask; neither touches the host.grep -rfollowing symlinked dirs is left to the text-builtins work.Testing
go test ./internal/builtins/... ./internal/runtime/... ./cli/... ./commands/... .passes, with the pinned diff and ripgrep oracles set.go test ./cmd/gbashpasses except forTestRunCLIHostUtilityTailGroupedQuietFollowFlags, which failed once under the full parallel run. It passed 3/3 alone and looks timing-flaky.make lint's custom binary, run with--allow-parallel-runnersbecause other sessions held the lock): 0 issues.