Repository navigation
fix(server): harden server mode, CLI flag parsing, and readwrite-root mounting - #871
Merged
Merged
Conversation
…eadwrite root Arguments after `-c command_string` are now always $0 and positional parameters, as in bash, so --root/--json/--readwrite-root can no longer be injected through positional args. --readwrite-root now mounts the symlink-resolved path it validated, so swapping a symlink after startup cannot redirect later server sessions.
- run session.exec under a per-connection context that is canceled when the client disconnects, and add Config.MaxExecTimeout - retry temporary Accept errors with backoff and close live connections whenever Serve returns - cap request size (Config.MaxRequestBytes) and session count (Config.MaxSessions) - use 128-bit random session ids - saturate huge timeout_ms values instead of overflowing - add stdout_base64/stderr_base64 when output is not valid UTF-8 - never answer JSON-RPC notifications - log internal errors and return a generic INTERNAL error - hard-link the Unix socket into place so a concurrently bound socket is never replaced, only remove the socket path while it is still ours, and report sun_path length errors against the requested path
… multi-line input
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-review findings for server mode, the shared CLI, the wasm package, and the scripts/docker tooling.
CLI (
cli/)-c: everything after-c command_string(or a script path) is now$0and positional args, as in bash. Before this,gbash -c 'ls' --root=/ xmounted the whole host filesystem, and anyone controlling positional args could inject--jsonor--readwrite-rootthe same way. A--is inserted before the positionals so the invocation parser leaves them alone.--readwrite-rootsymlink swap: the runtime now mounts the symlink-resolved path that passed the system-temp check. Previously each new server session resolved the original path again, so swapping a symlink after startup could mount any directory read-write.--listen localhostnow binds127.0.0.1directly instead of trusting/etc/hostsor DNS, and the bound address is checked again to be loopback.--jsonaddsstdoutBase64/stderrBase64when a stream isn't valid UTF-8. These fields are omitted otherwise, so existing consumers are unaffected.Server (
server/)session.execruns under a per-connection context, so a client disconnect cancels the exec and the session goes back to idle. Before this, the session stayedrunningforever, destroy and exec returnedSESSION_BUSY, and the reaper skipped it. Requests are decoded on a separate goroutine so the disconnect is noticed while an exec is running. New optionalConfig.MaxExecTimeout.Serveretries temporary Accept errors (EMFILE and similar) with backoff, and closes every live connection whenever it returns.Config.MaxRequestBytes(default 16 MiB; oversized requests getREQUEST_TOO_LARGEand the connection closes) andConfig.MaxSessions(default 256; extra creates getSESSION_LIMIT, code -32012).sess-<32 hex>) instead of sequential.session.listis sorted by creation time.timeout_msvalues too large for a Go duration now saturate instead of overflowing (18446744073710used to become a ~448µs timeout).stdout_base64/stderr_base64are added when output isn't valid UTF-8.idmember) are processed but never answered, per JSON-RPC 2.0.INTERNALerror, since the details could include absolute host paths.sun_pathlimit fail with an error naming the requested path, not the staging path.Other
packages/gbash-wasm: the custom-command fast path is skipped for commands containing$, backtick,*,?,[, CR or LF, so its simple tokenizer never disagrees with real shell expansion.scripts/collect_fuzz_failure_artifacts.sh: it requires an argument orRUNNER_TEMP(${RUNNER_TEMP:?}) and refuses/. Before, with neither set, it ranrm -rf /fuzz-failure-artifacts.docker/compat/Dockerfile: the Go tarball is checked against a pinned sha256 per version and arch (1.26.0 and 1.26.1; values matched on both go.dev and dl.google.com). It can be overridden with aGO_SHA256build-arg.For reviewers
-c SCRIPTare no longer parsed. This ordering is the vulnerability itself. The README and website quick-start examples (gbash -c 'echo hello' --json) and twocmd/gbashtests were updated to put the flags first. Outside scripts that use the old ordering will see the flag as$0instead.go.modGo versions: the compat image build fails until a checksum row is added to the Dockerfile (orGO_SHA256is passed).server.ConfiggainsMaxSessions,MaxRequestBytesandMaxExecTimeout(zero means the default; negative disables the session and request caps).--jsonand the §6.2 server mode bullets cover the new guarantees, including the cross-user exposure of loopback TCP (prefer--socketon multi-user hosts).Testing
go test -race ./server/... ./cli/... ./cmd/...passes, andmake lintis clean.make bats-testpasses, including new tests for the fuzz-artifacts script.shared.test.mjspasses. It ran through Node's built-in TypeScript support because the package's TS dependencies weren't installed locally.go test ./..., these fail for reasons outside this change:tail -fCLI tests. These flake at the same rate on the base commit.Example of the flag fix: