| 1 | 1 | new file mode 100644 |
| index 0000000..91049f2 | ||
| --- /dev/null | ||
| +++ b/docs/SECURITY.md | ||
| @@ -0,0 +1,104 @@ | ||
| 1 | +# Security model | |
| 2 | + | |
| 3 | +`plugin_filesystem` gives an agent **write** access to a slice of your disk. | |
| 4 | +Everything in this file exists to answer one question: *what can this binary | |
| 5 | +actually touch?* | |
| 6 | + | |
| 7 | +If you read only one line: **it can create, overwrite, edit, move and delete | |
| 8 | +files inside the directories in `roots.json` and nowhere else**, and when | |
| 9 | +`roots.json` is missing the allowlist is `/workspace` and `$HOME`. | |
| 10 | + | |
| 11 | +## One gate, every entry point | |
| 12 | + | |
| 13 | +A path arriving from `--mcp`, from `?action=sandbox_test`, or from a roots | |
| 14 | +mutation goes through the same five checks, in this order: | |
| 15 | + | |
| 16 | +| # | Check | What it stops | | |
| 17 | +|---|---|---| | |
| 18 | +| 1 | **Shape** — absolute, no NUL, no control bytes, no `..` segment anywhere | `..` traversal, `%2e%2e`, NUL smuggling, relative-path confusion | | |
| 19 | +| 2 | **Canonicalise** — `realpath()` on POSIX, `GetFullPathNameA()` then `GetFinalPathNameByHandleA()` on Windows | symlink indirection, `//`, redundant `.` segments | | |
| 20 | +| 3 | **Prefix-match against every root**, in both the configured and the canonical form | a sandbox that silently breaks on macOS `/tmp` → `/private/tmp` | | |
| 21 | +| 4 | **Deny list** — `/proc`, `/sys`, `/dev` always, plus operator `denied` entries | reading `/proc/self/environ` under an allowed `/`-ish root | | |
| 22 | +| 5 | **Write mode only** — re-resolve the *parent*, refuse a symlinked leaf | writing *through* a link that points out of the sandbox | | |
| 23 | + | |
| 24 | +Step 2 before step 3 is the whole point. Checking the raw string and then | |
| 25 | +resolving is the bug that makes a symlink sandbox worthless, so resolution | |
| 26 | +happens first and the prefix test only ever sees a real path. | |
| 27 | + | |
| 28 | +`..` is refused outright rather than normalised away. A caller that means the | |
| 29 | +parent directory sends the parent's absolute path. That single rule kills | |
| 30 | +every encoded-traversal variant at once. | |
| 31 | + | |
| 32 | +## NUL bytes | |
| 33 | + | |
| 34 | +`yyjson` preserves the full length of a JSON string, but every C helper below | |
| 35 | +it stops at the first NUL. Without a guard, `a.txt\u0000secret` becomes | |
| 36 | +`a.txt` — a path the caller never asked for. `ju_cstr()` compares | |
| 37 | +`strlen(s)` with `yyjson_get_len()` and refuses the value outright; any string | |
| 38 | +treated as a path, pattern, or file body passes through it. `tests/run.sh` | |
| 39 | +asserts the refusal. | |
| 40 | + | |
| 41 | +## Writes | |
| 42 | + | |
| 43 | +`write_file` never writes to the target. Content goes to `<path>.tmp-<pid>`, | |
| 44 | +is flushed and `fsync`ed, then `rename()`d over the target. Same-directory so | |
| 45 | +the rename is atomic, same-filesystem by construction. A process killed | |
| 46 | +mid-write leaves the old file or the new one — the suite proves it by | |
| 47 | +`SIGKILL`ing the connector mid-request and checking both the target bytes and | |
| 48 | +the absence of a stray `.tmp`. | |
| 49 | + | |
| 50 | +`edit_file` is all-or-nothing: every edit must match before anything is | |
| 51 | +written. `move_file` refuses to overwrite — silently replacing a file an | |
| 52 | +agent was never shown is the one failure mode an unattended tool must not | |
| 53 | +have. | |
| 54 | + | |
| 55 | +## The permission switches are not decoration | |
| 56 | + | |
| 57 | +The plugin page's per-tool toggles are read by `--mcp`, not just displayed. A | |
| 58 | +disabled tool answers with an `isError` reply naming the tool and telling the | |
| 59 | +operator where to switch it back on, so an agent gets an explanation instead | |
| 60 | +of a missing tool. `list_allowed_directories` cannot be switched off — it is | |
| 61 | +how you debug a refusal you did not expect. | |
| 62 | + | |
| 63 | +## What the binary cannot do | |
| 64 | + | |
| 65 | +Enforced by `tests/run.sh` grepping the source, not by this page's promise: | |
| 66 | + | |
| 67 | +* **no network.** No socket, no `connect`, no HTTP client, no `libcurl`. | |
| 68 | +* **no process spawning.** No `system()`, no `popen()`, no `fork`+`exec`. | |
| 69 | +* **no manual `Content-Length`** framing of its own in CGI mode. | |
| 70 | +* **no CDN, no `<script src=>`** in the page, so the settings UI cannot be | |
| 71 | + silently changed by a third-party host. | |
| 72 | +* zero shared-library dependencies on all six dist targets. | |
| 73 | + | |
| 74 | +## Configuration is outside the binary | |
| 75 | + | |
| 76 | +``` | |
| 77 | +~/.scorpiox/connectors/plugin_filesystem/roots.json | |
| 78 | +/workspace/.scorpiox/connectors/plugin_filesystem/roots.json | |
| 79 | +%LOCALAPPDATA%\scorpiox\connectors\plugin_filesystem\roots.json | |
| 80 | +``` | |
| 81 | + | |
| 82 | +so a reinstall never widens or narrows the sandbox by accident. `roots.json` | |
| 83 | +is written with the same temp+rename discipline as `write_file`, because a | |
| 84 | +half-written allowlist would silently change what the sandbox means. | |
| 85 | + | |
| 86 | +## Threat model — read this honestly | |
| 87 | + | |
| 88 | +The sandbox is a **confinement** mechanism, not a **security boundary against | |
| 89 | +a hostile operator**. Anyone who can write `roots.json`, or who can set | |
| 90 | +`FS_ALLOWED_ROOTS`, chooses what the connector can read. That is the same | |
| 91 | +trust level as running the binary at all. What the sandbox *does* protect | |
| 92 | +against is the realistic failure: an agent, doing its best, walking out of the | |
| 93 | +directory it was pointed at. | |
| 94 | + | |
| 95 | +The settings page requires the node password (`require_node_auth()`); every | |
| 96 | +`?action=` returns 401 without it, unauthenticated or not. | |
| 97 | + | |
| 98 | +## Hardening that is actually built | |
| 99 | + | |
| 100 | +`tests/run.sh` runs the suite under `-fsanitize=address,undefined` (leaks | |
| 101 | +included) and separately with `-D_FORTIFY_SOURCE=2 -O2`, and asserts a | |
| 102 | +warning-free `-Wall -Wextra -Wpedantic` build. Two real defects were caught | |
| 103 | +that way in the first pass: an off-by-one at the end of the 64 KiB stdin | |
| 104 | +chunk buffer, and a comma written into a buffer before it was initialised. | |
| 0 | 105 |
| 1 | new file mode 100644 | 1 | new file mode 100644 |
| index 0000000..91049f2 | index 0000000..91049f2 | ||
| --- /dev/null | --- /dev/null | ||
| +++ b/docs/SECURITY.md | +++ b/docs/SECURITY.md | ||
| @@ -0,0 +1,104 @@ | @@ -0,0 +1,104 @@ | ||
| 1 | +# Security model | ||
| 2 | + | ||
| 3 | +`plugin_filesystem` gives an agent **write** access to a slice of your disk. | ||
| 4 | +Everything in this file exists to answer one question: *what can this binary | ||
| 5 | +actually touch?* | ||
| 6 | + | ||
| 7 | +If you read only one line: **it can create, overwrite, edit, move and delete | ||
| 8 | +files inside the directories in `roots.json` and nowhere else**, and when | ||
| 9 | +`roots.json` is missing the allowlist is `/workspace` and `$HOME`. | ||
| 10 | + | ||
| 11 | +## One gate, every entry point | ||
| 12 | + | ||
| 13 | +A path arriving from `--mcp`, from `?action=sandbox_test`, or from a roots | ||
| 14 | +mutation goes through the same five checks, in this order: | ||
| 15 | + | ||
| 16 | +| # | Check | What it stops | | ||
| 17 | +|---|---|---| | ||
| 18 | +| 1 | **Shape** — absolute, no NUL, no control bytes, no `..` segment anywhere | `..` traversal, `%2e%2e`, NUL smuggling, relative-path confusion | | ||
| 19 | +| 2 | **Canonicalise** — `realpath()` on POSIX, `GetFullPathNameA()` then `GetFinalPathNameByHandleA()` on Windows | symlink indirection, `//`, redundant `.` segments | | ||
| 20 | +| 3 | **Prefix-match against every root**, in both the configured and the canonical form | a sandbox that silently breaks on macOS `/tmp` → `/private/tmp` | | ||
| 21 | +| 4 | **Deny list** — `/proc`, `/sys`, `/dev` always, plus operator `denied` entries | reading `/proc/self/environ` under an allowed `/`-ish root | | ||
| 22 | +| 5 | **Write mode only** — re-resolve the *parent*, refuse a symlinked leaf | writing *through* a link that points out of the sandbox | | ||
| 23 | + | ||
| 24 | +Step 2 before step 3 is the whole point. Checking the raw string and then | ||
| 25 | +resolving is the bug that makes a symlink sandbox worthless, so resolution | ||
| 26 | +happens first and the prefix test only ever sees a real path. | ||
| 27 | + | ||
| 28 | +`..` is refused outright rather than normalised away. A caller that means the | ||
| 29 | +parent directory sends the parent's absolute path. That single rule kills | ||
| 30 | +every encoded-traversal variant at once. | ||
| 31 | + | ||
| 32 | +## NUL bytes | ||
| 33 | + | ||
| 34 | +`yyjson` preserves the full length of a JSON string, but every C helper below | ||
| 35 | +it stops at the first NUL. Without a guard, `a.txt\u0000secret` becomes | ||
| 36 | +`a.txt` — a path the caller never asked for. `ju_cstr()` compares | ||
| 37 | +`strlen(s)` with `yyjson_get_len()` and refuses the value outright; any string | ||
| 38 | +treated as a path, pattern, or file body passes through it. `tests/run.sh` | ||
| 39 | +asserts the refusal. | ||
| 40 | + | ||
| 41 | +## Writes | ||
| 42 | + | ||
| 43 | +`write_file` never writes to the target. Content goes to `<path>.tmp-<pid>`, | ||
| 44 | +is flushed and `fsync`ed, then `rename()`d over the target. Same-directory so | ||
| 45 | +the rename is atomic, same-filesystem by construction. A process killed | ||
| 46 | +mid-write leaves the old file or the new one — the suite proves it by | ||
| 47 | +`SIGKILL`ing the connector mid-request and checking both the target bytes and | ||
| 48 | +the absence of a stray `.tmp`. | ||
| 49 | + | ||
| 50 | +`edit_file` is all-or-nothing: every edit must match before anything is | ||
| 51 | +written. `move_file` refuses to overwrite — silently replacing a file an | ||
| 52 | +agent was never shown is the one failure mode an unattended tool must not | ||
| 53 | +have. | ||
| 54 | + | ||
| 55 | +## The permission switches are not decoration | ||
| 56 | + | ||
| 57 | +The plugin page's per-tool toggles are read by `--mcp`, not just displayed. A | ||
| 58 | +disabled tool answers with an `isError` reply naming the tool and telling the | ||
| 59 | +operator where to switch it back on, so an agent gets an explanation instead | ||
| 60 | +of a missing tool. `list_allowed_directories` cannot be switched off — it is | ||
| 61 | +how you debug a refusal you did not expect. | ||
| 62 | + | ||
| 63 | +## What the binary cannot do | ||
| 64 | + | ||
| 65 | +Enforced by `tests/run.sh` grepping the source, not by this page's promise: | ||
| 66 | + | ||
| 67 | +* **no network.** No socket, no `connect`, no HTTP client, no `libcurl`. | ||
| 68 | +* **no process spawning.** No `system()`, no `popen()`, no `fork`+`exec`. | ||
| 69 | +* **no manual `Content-Length`** framing of its own in CGI mode. | ||
| 70 | +* **no CDN, no `<script src=>`** in the page, so the settings UI cannot be | ||
| 71 | + silently changed by a third-party host. | ||
| 72 | +* zero shared-library dependencies on all six dist targets. | ||
| 73 | + | ||
| 74 | +## Configuration is outside the binary | ||
| 75 | + | ||
| 76 | +``` | ||
| 77 | +~/.scorpiox/connectors/plugin_filesystem/roots.json | ||
| 78 | +/workspace/.scorpiox/connectors/plugin_filesystem/roots.json | ||
| 79 | +%LOCALAPPDATA%\scorpiox\connectors\plugin_filesystem\roots.json | ||
| 80 | +``` | ||
| 81 | + | ||
| 82 | +so a reinstall never widens or narrows the sandbox by accident. `roots.json` | ||
| 83 | +is written with the same temp+rename discipline as `write_file`, because a | ||
| 84 | +half-written allowlist would silently change what the sandbox means. | ||
| 85 | + | ||
| 86 | +## Threat model — read this honestly | ||
| 87 | + | ||
| 88 | +The sandbox is a **confinement** mechanism, not a **security boundary against | ||
| 89 | +a hostile operator**. Anyone who can write `roots.json`, or who can set | ||
| 90 | +`FS_ALLOWED_ROOTS`, chooses what the connector can read. That is the same | ||
| 91 | +trust level as running the binary at all. What the sandbox *does* protect | ||
| 92 | +against is the realistic failure: an agent, doing its best, walking out of the | ||
| 93 | +directory it was pointed at. | ||
| 94 | + | ||
| 95 | +The settings page requires the node password (`require_node_auth()`); every | ||
| 96 | +`?action=` returns 401 without it, unauthenticated or not. | ||
| 97 | + | ||
| 98 | +## Hardening that is actually built | ||
| 99 | + | ||
| 100 | +`tests/run.sh` runs the suite under `-fsanitize=address,undefined` (leaks | ||
| 101 | +included) and separately with `-D_FORTIFY_SOURCE=2 -O2`, and asserts a | ||
| 102 | +warning-free `-Wall -Wextra -Wpedantic` build. Two real defects were caught | ||
| 103 | +that way in the first pass: an off-by-one at the end of the 64 KiB stdin | ||
| 104 | +chunk buffer, and a comma written into a buffer before it was initialised. | ||
| 0 | 105 |