scorpiox-bot-plugin-filesystem
←SECURITY.mdmarkdown
104 lines · 5 KBHEAD
BlameDownload

Security model

plugin_filesystem gives an agent write access to a slice of your disk.

Everything in this file exists to answer one question: *what can this binary

actually touch?*

If you read only one line: **it can create, overwrite, edit, move and delete

files inside the directories in roots.json and nowhere else**, and when

roots.json is missing the allowlist is /workspace and $HOME.

One gate, every entry point

A path arriving from --mcp, from ?action=sandbox_test, or from a roots

mutation goes through the same five checks, in this order:

# Check What it stops
1 Shape — absolute, no NUL, no control bytes, no .. segment anywhere .. traversal, %2e%2e, NUL smuggling, relative-path confusion
2 Canonicalise — realpath() on POSIX, GetFullPathNameA() then GetFinalPathNameByHandleA() on Windows symlink indirection, //, redundant . segments
3 Prefix-match against every root, in both the configured and the canonical form a sandbox that silently breaks on macOS /tmp → /private/tmp
4 Deny list — /proc, /sys, /dev always, plus operator denied entries reading /proc/self/environ under an allowed /-ish root
5 Write mode only — re-resolve the parent, refuse a symlinked leaf writing through a link that points out of the sandbox

Step 2 before step 3 is the whole point. Checking the raw string and then

resolving is the bug that makes a symlink sandbox worthless, so resolution

happens first and the prefix test only ever sees a real path.

.. is refused outright rather than normalised away. A caller that means the

parent directory sends the parent's absolute path. That single rule kills

every encoded-traversal variant at once.

NUL bytes

yyjson preserves the full length of a JSON string, but every C helper below

it stops at the first NUL. Without a guard, a.txt\u0000secret becomes

a.txt — a path the caller never asked for. ju_cstr() compares

strlen(s) with yyjson_get_len() and refuses the value outright; any string

treated as a path, pattern, or file body passes through it. tests/run.sh

asserts the refusal.

Writes

write_file never writes to the target. Content goes to <path>.tmp-<pid>,

is flushed and fsynced, then rename()d over the target. Same-directory so

the rename is atomic, same-filesystem by construction. A process killed

mid-write leaves the old file or the new one — the suite proves it by

SIGKILLing the connector mid-request and checking both the target bytes and

the absence of a stray .tmp.

edit_file is all-or-nothing: every edit must match before anything is

written. move_file refuses to overwrite — silently replacing a file an

agent was never shown is the one failure mode an unattended tool must not

have.

The permission switches are not decoration

The plugin page's per-tool toggles are read by --mcp, not just displayed. A

disabled tool answers with an isError reply naming the tool and telling the

operator where to switch it back on, so an agent gets an explanation instead

of a missing tool. list_allowed_directories cannot be switched off — it is

how you debug a refusal you did not expect.

What the binary cannot do

Enforced by tests/run.sh grepping the source, not by this page's promise:

  • no network. No socket, no connect, no HTTP client, no libcurl.
  • no process spawning. No system(), no popen(), no fork+exec.
  • no manual `Content-Length` framing of its own in CGI mode.
  • no CDN, no `<script src=>` in the page, so the settings UI cannot be

silently changed by a third-party host.

  • zero shared-library dependencies on all six dist targets.

Configuration is outside the binary

~/.scorpiox/connectors/plugin_filesystem/roots.json
/workspace/.scorpiox/connectors/plugin_filesystem/roots.json
%LOCALAPPDATA%\scorpiox\connectors\plugin_filesystem\roots.json

so a reinstall never widens or narrows the sandbox by accident. roots.json

is written with the same temp+rename discipline as write_file, because a

half-written allowlist would silently change what the sandbox means.

Threat model — read this honestly

The sandbox is a confinement mechanism, not a **security boundary against

a hostile operator**. Anyone who can write roots.json, or who can set

FS_ALLOWED_ROOTS, chooses what the connector can read. That is the same

trust level as running the binary at all. What the sandbox does protect

against is the realistic failure: an agent, doing its best, walking out of the

directory it was pointed at.

The settings page requires the node password (require_node_auth()); every

?action= returns 401 without it, unauthenticated or not.

Hardening that is actually built

tests/run.sh runs the suite under -fsanitize=address,undefined (leaks

included) and separately with -D_FORTIFY_SOURCE=2 -O2, and asserts a

warning-free -Wall -Wextra -Wpedantic build. Two real defects were caught

that way in the first pass: an off-by-one at the end of the 64 KiB stdin

chunk buffer, and a comma written into a buffer before it was initialised.