Skip to content

Fix A2A cross-site access, symlink sandbox escape, and scheduler bugs - #264

Open
fuseraft wants to merge 11 commits into
mainfrom
bughunt-fixes
Open

fuseraft wants to merge 11 commits into
mainfrom
bughunt-fixes

Conversation

@fuseraft

@fuseraft fuseraft commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Fixes found during a bug hunt at 2d6ee5f. Each commit fixes one bug and adds tests that fail on the old code and pass with the fix.

Fixes

  1. serve/A2A: refuse web pages on a tokenless loopback daemon. Before this, a cross-site text/plain POST or a DNS-rebinding Host header could run the agent. The A2A endpoint now applies the same loopback Host check as HTTP/MCP (421), and rejects requests that carry Origin (403) or a non-JSON body (415).
  2. fs: follow symlinks before applying sandbox and deny rules. A link inside the sandbox could read .env despite a **/.env deny rule, and could read or write files outside the sandbox. The real path is now checked against the sandbox root, the included roots, the exemptions and the deny rules. Links that stay inside still work, a root that is itself a link (macOS /tmp) still works, and link loops are denied.
  3. contracts: run RelatedTestsPass commands whole on Linux and macOS. bash -c received the command as one argument string, so only its first word ran. Arguments are now passed through ArgumentList.
  4. schedule: skip an empty or null job file instead of crashing with a NullReferenceException and running no jobs.
  5. schedule: exit 1 when a job fails, or when a job file can't be read, so cron and monitoring see the failure.
  6. schedule: on cancel, kill the job's whole process tree and still save its run with CancellationToken.None.
  7. fs: ResolveSafeDirectory resolves relative folders against the sandbox root instead of the process's current folder.

Behaviour changes to review

  • Browser-based A2A clients are now refused, even when a token is set. None could work before anyway, since there's no CORS.
  • schedule run can now exit non-zero, and a dry run with a bad job file exits 1.
  • ScheduleRunCommand has a new internal constructor so tests can inject the program to run. The public constructor is unchanged.

Tests

4,214 of 4,222 pass. The 8 failures are the existing Docker-dependent CodeExecutionPluginTests, which fail on machines without Docker. The new tests that start processes or create symlinks return early on Windows. Not tested: Windows junctions, and A2A behind a real TLS proxy.

Not in this PR (found, still open)

  • The macOS Keychain store strips quotes from values, which breaks the cached MCP OAuth tokens, and -w <secret> shows keys in ps.
  • Under the dotnet host, a scheduled job starts the wrong program.
  • A stale schedule lock file blocks its job forever, and creating the lock isn't atomic.
  • Relative --config paths in jobs break when cron runs them.
  • A token downgraded to read-only may keep its old write access on a task that's still running.
  • Hardening: Unix socket permissions, the queue journal's temp file being readable before its mode is set, and schedule add with a name that has no letters or digits.

…pback daemon

`fuseraft serve --a2a` on loopback with no FUSERAFT_A2A_TOKEN accepted any
Host header and any request body type, so a page the user opened could run
a hosted agent: a cross-site text/plain POST of SendMessage ran it blind, and
a page that rebinds its domain to 127.0.0.1 could also read the reply. The
HTTP/MCP listener already guards against both; A2A did not.

- On loopback without a token, require a loopback Host (the same check
  ServeHttpHost uses), before the forwarded headers a same-origin page
  could set itself.
- Refuse any request carrying Origin (403) and any POST that isn't JSON
  (415): A2A callers are programs, and a request a browser sends without a
  preflight is never application/json.
ResolveSafe and ResolveSafeDirectory compared paths only as spelled, so a
symlink inside the sandbox reached past it: with sandbox `sb/`, a link
`sb/link -> ../outside` let read_file and write_file read and create files
outside the sandbox, and a link `sb/notes.txt -> .env` read a file the
`**/.env` deny rule blocks. A cloned repo can carry such links, and an agent
with a shell can make them.

After the spelled path passes, follow every symlink along it (the part that
doesn't exist yet, such as a file about to be written, is kept as spelled)
and check that real path against the real sandbox, included roots and
exempted prefixes, and against the deny rules. Roots that are themselves
links (macOS's /tmp) keep working; a link cycle is denied.
ContractEngine started `bash` with the raw argument string `-c <command>`.
.NET splits that into words, so bash got `-c <first word>` and the rest
became its positional parameters: `npm test` ran `npm`, `dotnet test ...`
ran `dotnet` (exit 129), and `cargo test` ran `cargo`, which exits 0, so the
contract passed without running a test.

Pass the command as the one argument after -c, as ShellPlugin and
ProbePlugin already do; cmd.exe keeps the raw string it needs.
An empty file (or one holding only `~`) in ~/.fuseraft/schedule
deserializes to null. `schedule run` dereferenced it outside any
try/catch, so one such file threw a NullReferenceException and no job
after it ran. Report the file and move on, as `schedule list` and
`schedule enable/disable` already do.
`fuseraft schedule run` printed "✗ Failed (exit N)" but always exited 0,
so cron mail, a systemd timer or a CI step never saw a failed job. Exit 1
when any job that ran failed, or a job file couldn't be read (so its job
never ran). "Job not found" for --name already exits 1.

The command takes the executable that runs each job through an internal
constructor, so tests can run jobs with a stand-in script.
…ll save its run

When `fuseraft schedule run` was cancelled (Ctrl+C, a service manager
stopping it), WaitForExitAsync threw and the job's process was left
running. The lock file was still deleted, so the next tick could start the
same job alongside it, and the state update used the cancelled token, so
LastRun, LastExitCode and NextRun were never saved and the job stayed due.

On cancellation, kill the job's process tree, record the run as failed and
save its state with CancellationToken.None; don't start further jobs.
…x root

ResolveSafeDirectory full-pathed a relative directory against the process's
working directory, while ResolveSafe resolves relative paths against the
sandbox root. Whenever the two differ, a shell_run workingDirectory or a git
repoPath of `src` was denied as outside the sandbox, or pointed somewhere
else. Resolve it with ResolveAgainstRoot, as ResolveSafe does.
…ommands

Now that bash gets the whole command, an unquoted {file} or selector target
was run as shell code: a file named `x;cmd;.cs` ran `cmd`. Each now reaches
the shell as one quoted word; a value cmd.exe can't quote safely falls back
to the full suite.
…e it

Path.GetFullPath folded `..` into the text first, so `L -> a/../secret` with
`a` pointing outside the sandbox was judged to stay inside. The walk now
steps up from the real path built so far, as the kernel does.
With a token set, the Origin and JSON checks blocked browser-based clients
that held the token. They now run with the Host check, only on a tokenless
(loopback) daemon. Document that a reverse proxy or browser client needs
FUSERAFT_A2A_TOKEN.
A cancelled run moved NextRun to the next cron time, so the job was skipped
until then, and output it wrote before being stopped was lost.

This branch has not been deployed

No deployments
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.

1 participant