Skip to content

fix(sandbox): stop treating text arguments as paths in the bash check - #1872

Merged
edenreich merged 7 commits into
mainfrom
fix/issue-1870
Nov 16, 2026
Merged

edenreich merged 7 commits into
mainfrom
fix/issue-1870

Conversation

@inference-gateway-maintainer

@inference-gateway-maintainer inference-gateway-maintainer Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Resolves #1870

Summary

The bash auto-approval path check ran every word of an allow-listed command through the sandbox path rules, so text that merely looks like a path got the command blocked with Blocked: Bash requires approval, fatal in headless CI runs where nobody can approve: jq filters (-q .files[].path), commit messages and titles starting with /, gh api endpoints, and /dev/null. Three changes, each a rule rather than a per-command list:

  • A word that names no existing file is text, not a path. A read-only command cannot read what is not there, so such a word passes. Creating commands (mkdir, ln) keep their write check, since their target does not exist yet by design.
  • The dot-glob rule fires only for a component that can actually expand to . or .. (.*, .?). A malformed pattern such as .files[].path is literal text to bash and reaches the command as written. A pattern bash reads differently from the check ([!a], [[:alpha:]]) now asks, since its expansion cannot be enumerated. The old rule let [!a]* through on Go's reading of it.
  • /dev/null is a read-only entry in the default sandbox policy, so reading it needs no approval while writing to it still asks.

Changes

  • internal/sandbox/bash_paths.go: validateBashRead passes a path that does not exist. globOutsideSandbox rejects bash-only bracket syntax, narrows the dot rule to components matching . or .. (hiddenGlobReachesParent), and treats a malformed pattern as the literal word it already checked.
  • config/sandbox.go: /dev/null with access: read in DefaultSandboxConfig.
  • internal/sandbox/bash_paths_test.go: the fixture now holds the secret files the blocked cases name (.env.local, nested/.env.production, ~/.aws/credentials), since a missing file is no longer a path. New auto-approved cases: unquoted jq filters, a /-prefixed commit message, a gh pr create title with brackets, a nonexistent absolute path. New blocked cases: ls .?, ls .??* (matches .env), ls .[!e]*, ls .[[:alpha:]]*, git commit -m msg .env, gh pr create --body-file /etc/hosts, wc -c /dev/null /etc/hosts, mkdir /dev/null.
  • docs/tools-reference.md, docs/configuration-reference.md: the rules and the new default.

Not covered

  • A command naming a nonexistent path outside the sandbox now runs and fails with the shell's own error where it used to ask either way, so the model learns that the path is absent. Existence is all it learns, never content.
  • A path that does not exist at check time but is created before the command runs by another process is a race the check does not see. The command itself cannot create it: read-only commands do not write, and creating commands keep the write check.
  • A user ~/.infer/sandbox.yaml that sets its own filesystem.allowed list replaces the default list and needs /dev/null added by hand:
filesystem:
  allowed:
    - path: /dev/null
      access: read

Verification

  • go test ./internal/sandbox/ is green, including the new allowed and blocked cases.
  • go vet cross-compiled for Linux and Windows is clean.
  • task precommit:run is green.

…h check

gh -q/--jq filters, gh --title/--body, git commit -m messages and gh api endpoints are text the command never opens as a file, and /dev/null carries no data, so an allow-listed read-only command naming them runs without approval again instead of asking in headless runs.
Comment thread internal/sandbox/bash_paths_test.go Resolved
Comment thread internal/sandbox/bash_paths_test.go Resolved
Comment thread internal/sandbox/bash_paths_test.go Resolved
Drop the per-command text flag rules. They duplicated the regex allow-list and let real paths past the check. The default sandbox policy now allows reading /dev/null, so an allow-listed command naming it runs without approval while writes to it still ask.
@edenreich edenreich changed the title fix(sandbox): exempt text flag values and /dev/null from the bash path check fix(sandbox): let bash read /dev/null by default Nov 16, 2026
…h check

A read-only command cannot read what is not there, so a word naming no existing file passes the path check instead of asking: jq filters, commit messages and titles that start with a slash were text the check took for paths. The dot-glob rule now fires only for a component that can expand to . or .., a malformed pattern is the literal word bash passes along, and a pattern bash reads differently from Go, such as [!a] or [[:alpha:]], asks since its expansion cannot be enumerated.
@edenreich edenreich changed the title fix(sandbox): let bash read /dev/null by default fix(sandbox): stop treating text arguments as paths in the bash check Nov 16, 2026
bashSkipsHiddenMatch skipped every hidden match of a wildcard component, which only mirrors bash for a component without a leading dot: .??* does match .env in bash, so its matches must reach the denied check. The blanket rule that rejected every dot-leading glob used to hide this.
The hint for head ~/.aws/credentials needs the file to exist now that a missing path is text, so the test creates it under a temp HOME instead of reading the machine's.
…x on Linux

A temp dir lives under /tmp on Linux, which the default policy allows, so the test now allows only its project dir.
@edenreich
edenreich merged commit 6007af5 into main Nov 16, 2026
1 check passed
@edenreich
edenreich deleted the fix/issue-1870 branch November 16, 2026 02:54
edenreich added a commit that referenced this pull request Nov 16, 2026
Resolves #1874
Based on #1872.
Docs follow-up: a `[DOCS]` ticket for the docs repository is drafted and
will be filed separately.

## Summary

The Bash sandbox was an approval decision only: the allow-list decides
what runs without a prompt and the path check keeps an unattended
command off paths its arguments name. Once a command runs, nothing
confines it. In `auto` mode, or after approval, a write can land
anywhere the CLI process can write.

Every Bash command the allow-list runs unattended, which in `auto` mode
is every command, now runs under an OS sandbox that lets it read and
execute anything but write only under the writable allowed paths, the
grants, the writable carve-outs, the temp dir and the build caches. A
write elsewhere fails in the kernel and the tool result tells the model
why. A command the user approved runs as approved, unconfined, so the
approval flow for a path outside the sandbox keeps its meaning. The path
check stays as the read guard, since the kernel cannot tell `gh` reading
its own token from `head` reading it.

## Changes

- `config/sandbox.go`: `filesystem.enforce` (default `true`). `false`
turns the kernel wrapper off.
- `internal/sandbox/enforce.go`: `WritePaths(cfg, mode)` lists what a
Bash child may write: writable allowed entries and grants, the writable
carve-outs (skills, plugins, runtime dirs, plans, insights, memory), the
temp dir, the Go, cargo and npm caches, and `/dev`. Plan mode gives the
project up for the scratchpad, as `ValidateWrite` does.
- `internal/sandbox/paths.go`: the carve-out predicates now share list
helpers with `WritePaths`. Behaviour unchanged.
- `internal/sandbox/infrastructure/kernel*.go`: `Command(ctx, cfg, mode,
command)` builds the confined `Child`, and `Child.Start` is the one call
that goes through the package. Linux applies a Landlock ruleset on the
thread that forks bash (read and execute everywhere, write under the
listed paths, every right the kernel's ABI knows), so only the child
inherits it and the process stays as it was. No re-exec, no hidden
command, and it works under Docker's default seccomp profile. macOS runs
`/usr/bin/sandbox-exec` with an allow-default profile that denies
`file-write*` outside the listed paths, with each path in its written
and symlink-resolved spelling since Seatbelt matches the resolved one.
Other platforms run plain bash. `DeniedHint` names the policy when the
output shows a refused write.
- `internal/tools/bash.go`: `confines` decides per command - the
allow-list runs it unattended, so the kernel wraps it, or somebody
approved it, so it runs plain. A failed confined command gets the hint
appended to its output.
- Tests: `WritePaths` per mode, the `confines` decision per mode and
allow-list outcome, the Seatbelt profile rendering and escaping, a Linux
test that a confined child writes only under a listed directory while
the parent keeps writing anywhere, and an e2e in auto mode that proves
an outside `mkdir` is refused with the hint while an inside one lands.
- Docs: configuration reference, tools reference, the sandbox context
README and the AGENTS.md security note.

## Not covered

- Windows has no kernel sandbox, so the path check stays the only guard
there.
- Denied patterns such as `*.env` are not kernel-enforced: Landlock is
allow-only and cannot deny inside a granted tree. The path check and the
file tools keep enforcing them for unattended commands.
- A Linux kernel without Landlock runs the child unconfined with a debug
log, as `enforce` promises best effort. A kernel that has Landlock but
refuses the ruleset fails the command with a message naming
`filesystem.enforce`.
- A tool cache outside the listed ones (for example `~/.bun`) needs an
`allowed` entry.

## Verification

- `go test` for sandbox, infrastructure, config, cmd/sandboxexec,
cmd/runtime and tools is green on macOS, with the tools tests running
under Seatbelt.
- `go vet` cross-compiled for Linux (`CGO_ENABLED=0`) and Windows is
clean.
- The new e2e passes on macOS and on the Linux CI runner. The Linux unit
test also ran in Docker against a 7.0 kernel with the default seccomp
profile.
- `task precommit:run` is green.

---------

Co-authored-by: inference-gateway-maintainer[bot] <246577062+inference-gateway-maintainer[bot]@users.noreply.github.com>
@edenreich edenreich moved this from Todo to Done in 2026 Nov 16, 2026
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.262.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@inference-gateway-releaser inference-gateway-releaser Bot added the released Shipped in a release label Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[BUG] Bash approval treats non-path arguments as paths outside the sandbox

1 participant