| 1 | 1 | new file mode 100644 |
| index 0000000..8ff1496 | ||
| --- /dev/null | ||
| +++ b/README.md | ||
| @@ -0,0 +1,287 @@ | ||
| 1 | +# plugin_webhook — named webhooks & REST triggers for SCORPIOX BOT | |
| 2 | + | |
| 3 | +A zero-dependency pure-C99 **MCP connector** that gives your agent one safe verb: | |
| 4 | +*fire the webhook called `deploy-note`, with this JSON body*. | |
| 5 | + | |
| 6 | +You define the endpoints. The node keeps the secrets. | |
| 7 | + | |
| 8 | +``` | |
| 9 | + ┌──────────────┐ webhook_trigger("deploy-note", {…}) ┌────────────────┐ | |
| 10 | + │ SCORPIOX │ ─────────────────────────────────────► │ plugin_webhook │ | |
| 11 | + │ BOT agent │ │ on the node │ | |
| 12 | + └──────────────┘ ◄───── "HTTP 200 in 41 ms" ─────────── └───────┬────────┘ | |
| 13 | + │ POST, headers, | |
| 14 | + │ HMAC signature | |
| 15 | + ▼ | |
| 16 | + Slack · Discord · Zapier · n8n · | |
| 17 | + IFTTT · your own REST endpoint | |
| 18 | +``` | |
| 19 | + | |
| 20 | +The agent never sees the bearer token or the signing secret. It sees | |
| 21 | +`has_secret: true`. | |
| 22 | + | |
| 23 | +--- | |
| 24 | + | |
| 25 | +## Why this shape | |
| 26 | + | |
| 27 | +Hermes Agent's `gateway/platforms/webhook` and OpenClaw's `extensions/admin-http-rpc` | |
| 28 | +both solve the same problem — *an operator's endpoint definitions, used by an agent* — | |
| 29 | +and both make the same two decisions this plugin keeps: | |
| 30 | + | |
| 31 | +1. **A named registry, not a tool per endpoint.** Publishing every hook as its own | |
| 32 | + MCP tool floods a model's context with names it will never call. Two tools | |
| 33 | + (`webhook_list`, `webhook_trigger`) scale to any number of hooks, and adding one | |
| 34 | + needs no restart. | |
| 35 | +2. **The secret never enters the prompt.** A header value or an HMAC key that has | |
| 36 | + ever appeared in a transcript is a compromised secret. Every read path here | |
| 37 | + reports presence only. | |
| 38 | + | |
| 39 | +Two things this plugin adds, because a self-hosted node has a different threat | |
| 40 | +model from a hosted gateway: | |
| 41 | + | |
| 42 | +3. **SSRF policy before the socket.** A user-supplied URL is a request to make the | |
| 43 | + node fetch something on the user's behalf. Every address the hostname resolves | |
| 44 | + to is checked against loopback / RFC1918 / link-local / CGNAT / ULA / | |
| 45 | + multicast / documentation ranges *before* connecting, and the connection then | |
| 46 | + goes to that validated numeric address — so a DNS answer that changes between | |
| 47 | + check and connect cannot move the request onto a private network. | |
| 48 | +4. **Verified TLS with no bypass.** There is no `--insecure` flag, no environment | |
| 49 | + switch and no config key that turns verification off. A webhook carrying a | |
| 50 | + token must not be sendable over a channel that cannot prove who it is talking to. | |
| 51 | + | |
| 52 | +--- | |
| 53 | + | |
| 54 | +## Install | |
| 55 | + | |
| 56 | +```sh | |
| 57 | +# from the marketplace | |
| 58 | +bot.scorpiox.net → Settings → Plugins → Marketplace → webhook → Install | |
| 59 | + | |
| 60 | +# or from source, on the node | |
| 61 | +git clone https://plugingit.scorpiox.net/scorpiox-bot-plugin-webhook.git | |
| 62 | +cd scorpiox-bot-plugin-webhook | |
| 63 | +make && install -m 0755 plugin_webhook ~/.scorpiox/plugins/ | |
| 64 | +``` | |
| 65 | + | |
| 66 | +The plugin is discovered by `GET /plugins` with no restart. On a BotCloud container | |
| 67 | +it installs into `/workspace/.scorpiox/plugins` instead, which survives a | |
| 68 | +`stop`/`start` cycle. | |
| 69 | + | |
| 70 | +--- | |
| 71 | + | |
| 72 | +## The tools | |
| 73 | + | |
| 74 | +### `webhook_list` | |
| 75 | + | |
| 76 | +```json | |
| 77 | +{} | |
| 78 | +``` | |
| 79 | + | |
| 80 | +``` | |
| 81 | +2 configured webhooks | |
| 82 | + | |
| 83 | +- deploy-note POST https://hooks.slack.com/services/<redacted> [signed: github] [2 headers] | |
| 84 | + Deploy notification | |
| 85 | +- status-probe PUT https://api.example.com/echo?<redacted> | |
| 86 | + Probe with a pasted token | |
| 87 | +``` | |
| 88 | + | |
| 89 | +`redact_url` defaults to **true**: the path is kept (it identifies the endpoint) and | |
| 90 | +the query string is replaced with `<redacted>`, because a pasted webhook URL usually | |
| 91 | +carries its token there. Pass `{"redact_url": false}` when you genuinely need to see | |
| 92 | +the whole URL — and remember the answer may then contain a credential. | |
| 93 | + | |
| 94 | +### `webhook_trigger` | |
| 95 | + | |
| 96 | +```json | |
| 97 | +{ "name": "deploy-note", "payload": { "event": "deploy", "service": "api", "status": "ok" } } | |
| 98 | +``` | |
| 99 | + | |
| 100 | +``` | |
| 101 | +POST deploy-note -> HTTP 200 in 41 ms | |
| 102 | +ok: yes | |
| 103 | +body: | |
| 104 | +ok | |
| 105 | +``` | |
| 106 | + | |
| 107 | +| argument | meaning | | |
| 108 | +|---|---| | |
| 109 | +| `name` | a name `webhook_list` reported | | |
| 110 | +| `payload` | the body. An object or array is serialised as JSON; a string is sent as a JSON string literal. Defaults to `{}` | | |
| 111 | +| `query` | optional query string appended to the hook's URL, no leading `?` (`event=deploy&env=prod`) | | |
| 112 | + | |
| 113 | +The result carries the status, latency, byte count and the first 4 KiB of the | |
| 114 | +response body. A non-2xx answer is data, not an error: `isError` is only set when the | |
| 115 | +request could not be made at all (refused address, TLS failure, timeout, unknown | |
| 116 | +hook name). | |
| 117 | + | |
| 118 | +--- | |
| 119 | + | |
| 120 | +## The page | |
| 121 | + | |
| 122 | +`GET /plugin_webhook` (node-auth required — it lists your endpoints) gives you: | |
| 123 | + | |
| 124 | +- the hook table: name, method, endpoint, signature scheme, how many secrets it carries | |
| 125 | +- a fly-out editor for name / method / URL / description / signature / secret / headers | |
| 126 | +- a test-fire panel that sends the same request the tool would, and shows the reply | |
| 127 | +- the last 50 deliveries with status, latency, bytes and reason | |
| 128 | + | |
| 129 | +The page follows the bot's theme: `?theme=`, `localStorage.bot_theme`, the | |
| 130 | +`{type:'sx-theme'}` postMessage handoff, `?embed=1` inside the Chat window, and no | |
| 131 | +remote script or CDN of any kind. | |
| 132 | + | |
| 133 | +--- | |
| 134 | + | |
| 135 | +## Signatures | |
| 136 | + | |
| 137 | +| scheme | header | what is signed | | |
| 138 | +|---|---|---| | |
| 139 | +| `github` | `X-Hub-Signature-256: sha256=<hex>` | HMAC-SHA256 over the body | | |
| 140 | +| `gitlab` | `X-Gitlab-Token: <secret>` | shared token (not a MAC) | | |
| 141 | +| `v2` | `X-Webhook-Timestamp` + `X-Webhook-Signature: t=<unix>,v1=<hex>` | HMAC-SHA256 over `"<unix>." + body` | | |
| 142 | + | |
| 143 | +`v2` exists because a body-only signature never expires: a captured request can be | |
| 144 | +replayed forever. With a timestamp the verifier can close a window. Body-only V1 is | |
| 145 | +deliberately **not** offered. | |
| 146 | + | |
| 147 | +The HMAC is implemented in `src/sha256.c` — FIPS 180-4 and RFC 2104, pinned by the | |
| 148 | +published vectors in `tests/sha256_vectors.c`, because "our HMAC matches Python's" | |
| 149 | +proves only that both are wrong in the same way. | |
| 150 | + | |
| 151 | +--- | |
| 152 | + | |
| 153 | +## Configuration | |
| 154 | + | |
| 155 | +| where | what | | |
| 156 | +|---|---| | |
| 157 | +| `~/.scorpiox/connectors/plugin_webhook/hooks.json` | the store (mode **0600**). On a BotCloud container: `/workspace/.scorpiox/connectors/plugin_webhook/hooks.json`. Windows: `%LOCALAPPDATA%\scorpiox\connectors\plugin_webhook\hooks.json` | | |
| 158 | +| `WEBHOOK_STORE_PATH` | point the store somewhere else (used by the tests) | | |
| 159 | +| `WEBHOOK_ALLOW_PRIVATE=1` | lift the SSRF policy so loopback / RFC1918 endpoints are reachable. Never set it on a node you do not fully control | | |
| 160 | +| `WEBHOOK_TLS_CA_FILE` | extra PEM anchors for a self-signed endpoint. There is still no way to skip verification | | |
| 161 | +| `BOT_PASSWORD` | the node password the CGI routes require (already set by the bot) | | |
| 162 | + | |
| 163 | +Store file, written atomically through `<path>.tmp` + `rename()` so a crash cannot | |
| 164 | +truncate it: | |
| 165 | + | |
| 166 | +```json | |
| 167 | +{ | |
| 168 | + "version": 1, | |
| 169 | + "hooks": [ | |
| 170 | + { | |
| 171 | + "name": "deploy-note", | |
| 172 | + "url": "https://hooks.slack.com/services/T000/B000/XXXX", | |
| 173 | + "method": "POST", | |
| 174 | + "desc": "Deploy notification", | |
| 175 | + "sig": "github", | |
| 176 | + "secret": "<hmac key>", | |
| 177 | + "headers": [ | |
| 178 | + { "name": "Authorization", "value": "Bearer <token>" }, | |
| 179 | + { "name": "X-Custom", "value": "alpha" } | |
| 180 | + ] | |
| 181 | + } | |
| 182 | + ], | |
| 183 | + "log": [ | |
| 184 | + { "at": "2026-11-14T04:05:06Z", "name": "deploy-note", "status": 200, | |
| 185 | + "ok": true, "bytes": 11, "ms": 41, "error": "" } | |
| 186 | + ] | |
| 187 | +} | |
| 188 | +``` | |
| 189 | + | |
| 190 | +An edit that leaves a header's value or the HMAC secret blank **keeps** the stored | |
| 191 | +value: the UI never receives a secret, so it cannot send one back. Clearing a | |
| 192 | +signature is `"sig": ""`. | |
| 193 | + | |
| 194 | +--- | |
| 195 | + | |
| 196 | +## Limits and refusals | |
| 197 | + | |
| 198 | +| limit | value | | |
| 199 | +|---|---| | |
| 200 | +| outbound body | 1 MiB | | |
| 201 | +| response preview | 4 KiB (with `truncated: true` when larger) | | |
| 202 | +| response drained | 8 MiB | | |
| 203 | +| connect / read deadline | 10 s / 15 s | | |
| 204 | +| hooks | 64 | | |
| 205 | +| headers per hook | 16 | | |
| 206 | +| delivery log | 50 entries | | |
| 207 | +| redirects | **none** — a 3xx is reported as its status | | |
| 208 | + | |
| 209 | +Refused outright: `ftp://` and every non-http scheme, credentials in the URL | |
| 210 | +(`https://user:pw@…`), IPv6 literals, a header name containing a space or a control | |
| 211 | +character, a header value containing CR/LF (request splitting), a signature scheme | |
| 212 | +with no secret, a hook name with anything outside `[A-Za-z0-9._-]`, and a duplicate | |
| 213 | +name on create. | |
| 214 | + | |
| 215 | +Framing headers (`Host`, `Content-Length`, `Transfer-Encoding`, `Connection`) in a | |
| 216 | +hook's header list are ignored: they are the request's, not the user's. | |
| 217 | + | |
| 218 | +--- | |
| 219 | + | |
| 220 | +## Build | |
| 221 | + | |
| 222 | +```sh | |
| 223 | +make # native -> ./plugin_webhook | |
| 224 | +make musl # static musl x86_64 | |
| 225 | +make arm64 # static arm64 musl | |
| 226 | +make win64 # MinGW-w64 static PE (WinHTTP + Schannel, zero DLLs) | |
| 227 | +make macos # Apple clang (run on macOS) | |
| 228 | +make asan # ASan + UBSan + _FORTIFY_SOURCE=2 | |
| 229 | +make fortify # -D_FORTIFY_SOURCE=2 | |
| 230 | +make ui # regenerate src/ui_html.h from src/ui.html | |
| 231 | +make test # tests/run.sh (offline, 139 checks) | |
| 232 | +make e2e # tests/e2e.py (Playwright, 1440/1024/390 x dark/light) | |
| 233 | +``` | |
| 234 | + | |
| 235 | +The only third-party C is vendored under `vendor/`: **yyjson** (MIT) and | |
| 236 | +**Mbed TLS 3.6.7** (Apache-2.0). Everything compiles into the binary, so `ldd` says | |
| 237 | +*not a dynamic executable* on every Linux target and the PE needs no DLL. On Windows | |
| 238 | +the HTTP and TLS legs are WinHTTP instead, so no crypto object files are reached. | |
| 239 | + | |
| 240 | +``` | |
| 241 | +src/plugin_webhook.c the five modes, the two tools, the JSON API, the page | |
| 242 | +src/wh_http.{c,h} URL parse, SSRF deny list, one HTTP/1.1 request (+ WinHTTP) | |
| 243 | +src/wh_tls.{c,h} mbedTLS over an already-validated socket (POSIX) | |
| 244 | +src/wh_store.{c,h} the 0600 store, redacting serializers, the delivery log | |
| 245 | +src/sha256.{c,h} SHA-256 + HMAC-SHA256 (FIPS 180-4 / RFC 2104) | |
| 246 | +src/wh_buf.{c,h} one growable buffer + JSON/HTML escapes | |
| 247 | +src/ui.html the page source; tools/gen_ui.py splices the bot theme in | |
| 248 | +vendor/ yyjson, Mbed TLS, their licences | |
| 249 | +tests/ run.sh, mockrecv.py, e2e.py, sha256_vectors.c | |
| 250 | +``` | |
| 251 | + | |
| 252 | +--- | |
| 253 | + | |
| 254 | +## Testing | |
| 255 | + | |
| 256 | +`tests/run.sh` (139 checks) starts a **recording** receiver — not a "returns 200" | |
| 257 | +stub — which writes every request it gets, method, path, query and every header, to a | |
| 258 | +JSONL log. The suite then asserts the request that actually went on the wire: | |
| 259 | + | |
| 260 | +- method, path and query match the hook definition | |
| 261 | +- the stored `Authorization` header and custom headers arrived verbatim | |
| 262 | +- `X-Hub-Signature-256` equals `hmac(secret, body)` computed independently in Python | |
| 263 | +- `v2`'s signature covers `timestamp.body` and its timestamp is live | |
| 264 | +- the body arrived byte-identical, including from the MCP path | |
| 265 | +- 4xx is delivered and reported, a 302 is reported and **not** followed, a chunked | |
| 266 | + body is decoded, an oversized body is truncated and says so | |
| 267 | +- loopback is refused while the policy is closed and reachable with the opt-in | |
| 268 | +- the store is 0600, a corrupt store is reported and left untouched, a nested path is | |
| 269 | + created on demand | |
| 270 | +- every read path redacts — header values, the HMAC secret, the query string | |
| 271 | +- the MCP loop reads a body and its terminating newline written as **two** separate | |
| 272 | + writes (the connector router's `proc_send` shape), which a `fread`-based reader | |
| 273 | + would hang on | |
| 274 | +- ASan/UBSan is clean and `_FORTIFY_SOURCE=2` works | |
| 275 | +- no `system(`, no `popen(`, no `<script src=`, no private address, no secret in git | |
| 276 | + history | |
| 277 | + | |
| 278 | +`tests/e2e.py` drives the real page with Playwright: three viewports, both themes, no | |
| 279 | +console/page error, no horizontal overflow, hooks CRUD + fire + delete through the UI, | |
| 280 | +a stored secret kept when its field is left blank, and a screenshot per viewport. | |
| 281 | + | |
| 282 | +--- | |
| 283 | + | |
| 284 | +## Licence | |
| 285 | + | |
| 286 | +MIT — see `LICENSE`. Vendored components keep their own MIT/Apache-2.0 licences | |
| 287 | +(`vendor/`). |
| 1 | 1 | new file mode 100644 |
| index 0000000..2968b90 | ||
| --- /dev/null | ||
| +++ b/docs/SECURITY.md | ||
| @@ -0,0 +1,81 @@ | ||
| 1 | +# Security posture of `plugin_webhook` | |
| 2 | + | |
| 3 | +This plugin makes outbound HTTP requests whose URL, headers and secret come from a | |
| 4 | +user, and gives an agent a verb that fires them. That combination deserves an explicit | |
| 5 | +statement of what is and is not possible. | |
| 6 | + | |
| 7 | +## What the plugin can do | |
| 8 | + | |
| 9 | +| Capability | Detail | | |
| 10 | +|---|---| | |
| 11 | +| Outbound HTTP/HTTPS | one request per `webhook_trigger` (or test fire), method GET/POST/PUT/PATCH/DELETE/HEAD | | |
| 12 | +| Arbitrary request headers | except `Host`, `Content-Length`, `Transfer-Encoding`, `Connection` | | |
| 13 | +| HMAC-SHA256 signing | `github`, `gitlab` shared-token and timestamped `v2` | | |
| 14 | +| Read one file | its own store (`hooks.json`) | | |
| 15 | +| Write one file | the same store, plus its `.tmp` sibling, at mode 0600 | | |
| 16 | +| Read the node clock | only to stamp the `v2` signature and the delivery log | | |
| 17 | + | |
| 18 | +## What it cannot do | |
| 19 | + | |
| 20 | +- **Run a program.** There is no `system()`, no `popen()`, no `exec*()` anywhere in | |
| 21 | + the source; `tests/run.sh` greps for all three and fails the build. | |
| 22 | +- **Read another file.** The store path is the only path opened for write; the only | |
| 23 | + other paths read are the TLS CA bundles. | |
| 24 | +- **Reach a private address by accident.** Every address a hostname resolves to is | |
| 25 | + checked against loopback / RFC1918 / link-local / CGNAT / ULA / multicast / | |
| 26 | + documentation ranges *before* a socket is opened. `WEBHOOK_ALLOW_PRIVATE=1` is the | |
| 27 | + only way through, and it is a deliberate operator action on a node the operator | |
| 28 | + controls. | |
| 29 | +- **Follow a redirect.** A 3xx is reported as its status. Following one would mean a | |
| 30 | + hook definition silently becomes a request to somewhere the operator never | |
| 31 | + configured - and the second hop would be the one carrying the secrets. | |
| 32 | +- **Send over unverified TLS.** `MBEDTLS_SSL_VERIFY_REQUIRED`, TLS 1.2 minimum, | |
| 33 | + hostname checked against the certificate, anchors from `WEBHOOK_TLS_CA_FILE` or the | |
| 34 | + system bundle. There is no insecure flag in the source to turn on. | |
| 35 | +- **Leak a secret to the agent or the browser.** Every serializer that faces an MCP | |
| 36 | + client or a CGI response emits header *names* and `has_secret`; the HMAC emits its | |
| 37 | + scheme and `has_secret`. The store document itself is the only place a value | |
| 38 | + exists, and it is mode 0600. | |
| 39 | + | |
| 40 | +## Threats and the answer | |
| 41 | + | |
| 42 | +**Prompt injection turns the agent into an exfiltration tool.** The agent can only | |
| 43 | +name a hook (`webhook_list` reported the names). It cannot set a URL, a header or a | |
| 44 | +secret, and it cannot read them back. The worst it can do with a hostile instruction | |
| 45 | +is send a payload to an endpoint the operator already trusts. | |
| 46 | + | |
| 47 | +**A pasted URL contains a provider token.** `webhook_list` redacts the query string by | |
| 48 | +default (`?<redacted>`), so a Slack or Zapier URL pasted into the form does not put its | |
| 49 | +token into a transcript. `redact_url: false` is available and documented as the risky | |
| 50 | +choice. | |
| 51 | + | |
| 52 | +**DNS rebinding to a private address.** The check runs on the *numeric* answers of the | |
| 53 | +lookup, all of them, not on the hostname; the connection is then made to the validated | |
| 54 | +address, so a second lookup after the check cannot change where the bytes go. | |
| 55 | + | |
| 56 | +**Request splitting.** A header value containing CR or LF is refused at save time | |
| 57 | +(`value` validation) and again at request time (`wh_http.c` skips framing headers and | |
| 58 | +writes headers from validated names). | |
| 59 | + | |
| 60 | +**Replay of a captured request.** Body-only signatures are not offered. `v2` signs | |
| 61 | +`"<unix>." + body`, so a verifier that keeps a time window rejects a replayed request. | |
| 62 | + | |
| 63 | +**A corrupt store eating the secrets.** The document is written to `.tmp` and | |
| 64 | +`rename()`d, and a store that fails to parse is *reported and left untouched* - the | |
| 65 | +plugin never rewrites a file it could not read. | |
| 66 | + | |
| 67 | +**A runaway response.** Bodies are capped at 4 KiB of preview with an 8 MiB drain | |
| 68 | +ceiling, an outbound body at 1 MiB, and every connect/read phase has a deadline. | |
| 69 | + | |
| 70 | +## The auth gate | |
| 71 | + | |
| 72 | +The CGI page and every `?action=` route call `require_node_auth()` - the page lists | |
| 73 | +endpoint URLs, so it is node-private data. `--meta`, `--schema` and `--mcp` return | |
| 74 | +*before* the gate: discovery and the tool surface must work on a locked node, and | |
| 75 | +neither reveals a hook. | |
| 76 | + | |
| 77 | +## Reporting | |
| 78 | + | |
| 79 | +Open an issue at | |
| 80 | +`https://plugingit.scorpiox.net/repo?name=scorpiox-bot-plugin-webhook`, or contact | |
| 81 | +SCORPIOX INC directly for anything you would rather not describe in public. | |
| 0 | 82 |
| 1 | new file mode 100644 | 1 | new file mode 100644 |
| index 0000000..8ff1496 | index 0000000..8ff1496 | ||
| --- /dev/null | --- /dev/null | ||
| +++ b/README.md | +++ b/README.md | ||
| @@ -0,0 +1,287 @@ | @@ -0,0 +1,287 @@ | ||
| 1 | +# plugin_webhook — named webhooks & REST triggers for SCORPIOX BOT | ||
| 2 | + | ||
| 3 | +A zero-dependency pure-C99 **MCP connector** that gives your agent one safe verb: | ||
| 4 | +*fire the webhook called `deploy-note`, with this JSON body*. | ||
| 5 | + | ||
| 6 | +You define the endpoints. The node keeps the secrets. | ||
| 7 | + | ||
| 8 | +``` | ||
| 9 | + ┌──────────────┐ webhook_trigger("deploy-note", {…}) ┌────────────────┐ | ||
| 10 | + │ SCORPIOX │ ─────────────────────────────────────► │ plugin_webhook │ | ||
| 11 | + │ BOT agent │ │ on the node │ | ||
| 12 | + └──────────────┘ ◄───── "HTTP 200 in 41 ms" ─────────── └───────┬────────┘ | ||
| 13 | + │ POST, headers, | ||
| 14 | + │ HMAC signature | ||
| 15 | + ▼ | ||
| 16 | + Slack · Discord · Zapier · n8n · | ||
| 17 | + IFTTT · your own REST endpoint | ||
| 18 | +``` | ||
| 19 | + | ||
| 20 | +The agent never sees the bearer token or the signing secret. It sees | ||
| 21 | +`has_secret: true`. | ||
| 22 | + | ||
| 23 | +--- | ||
| 24 | + | ||
| 25 | +## Why this shape | ||
| 26 | + | ||
| 27 | +Hermes Agent's `gateway/platforms/webhook` and OpenClaw's `extensions/admin-http-rpc` | ||
| 28 | +both solve the same problem — *an operator's endpoint definitions, used by an agent* — | ||
| 29 | +and both make the same two decisions this plugin keeps: | ||
| 30 | + | ||
| 31 | +1. **A named registry, not a tool per endpoint.** Publishing every hook as its own | ||
| 32 | + MCP tool floods a model's context with names it will never call. Two tools | ||
| 33 | + (`webhook_list`, `webhook_trigger`) scale to any number of hooks, and adding one | ||
| 34 | + needs no restart. | ||
| 35 | +2. **The secret never enters the prompt.** A header value or an HMAC key that has | ||
| 36 | + ever appeared in a transcript is a compromised secret. Every read path here | ||
| 37 | + reports presence only. | ||
| 38 | + | ||
| 39 | +Two things this plugin adds, because a self-hosted node has a different threat | ||
| 40 | +model from a hosted gateway: | ||
| 41 | + | ||
| 42 | +3. **SSRF policy before the socket.** A user-supplied URL is a request to make the | ||
| 43 | + node fetch something on the user's behalf. Every address the hostname resolves | ||
| 44 | + to is checked against loopback / RFC1918 / link-local / CGNAT / ULA / | ||
| 45 | + multicast / documentation ranges *before* connecting, and the connection then | ||
| 46 | + goes to that validated numeric address — so a DNS answer that changes between | ||
| 47 | + check and connect cannot move the request onto a private network. | ||
| 48 | +4. **Verified TLS with no bypass.** There is no `--insecure` flag, no environment | ||
| 49 | + switch and no config key that turns verification off. A webhook carrying a | ||
| 50 | + token must not be sendable over a channel that cannot prove who it is talking to. | ||
| 51 | + | ||
| 52 | +--- | ||
| 53 | + | ||
| 54 | +## Install | ||
| 55 | + | ||
| 56 | +```sh | ||
| 57 | +# from the marketplace | ||
| 58 | +bot.scorpiox.net → Settings → Plugins → Marketplace → webhook → Install | ||
| 59 | + | ||
| 60 | +# or from source, on the node | ||
| 61 | +git clone https://plugingit.scorpiox.net/scorpiox-bot-plugin-webhook.git | ||
| 62 | +cd scorpiox-bot-plugin-webhook | ||
| 63 | +make && install -m 0755 plugin_webhook ~/.scorpiox/plugins/ | ||
| 64 | +``` | ||
| 65 | + | ||
| 66 | +The plugin is discovered by `GET /plugins` with no restart. On a BotCloud container | ||
| 67 | +it installs into `/workspace/.scorpiox/plugins` instead, which survives a | ||
| 68 | +`stop`/`start` cycle. | ||
| 69 | + | ||
| 70 | +--- | ||
| 71 | + | ||
| 72 | +## The tools | ||
| 73 | + | ||
| 74 | +### `webhook_list` | ||
| 75 | + | ||
| 76 | +```json | ||
| 77 | +{} | ||
| 78 | +``` | ||
| 79 | + | ||
| 80 | +``` | ||
| 81 | +2 configured webhooks | ||
| 82 | + | ||
| 83 | +- deploy-note POST https://hooks.slack.com/services/<redacted> [signed: github] [2 headers] | ||
| 84 | + Deploy notification | ||
| 85 | +- status-probe PUT https://api.example.com/echo?<redacted> | ||
| 86 | + Probe with a pasted token | ||
| 87 | +``` | ||
| 88 | + | ||
| 89 | +`redact_url` defaults to **true**: the path is kept (it identifies the endpoint) and | ||
| 90 | +the query string is replaced with `<redacted>`, because a pasted webhook URL usually | ||
| 91 | +carries its token there. Pass `{"redact_url": false}` when you genuinely need to see | ||
| 92 | +the whole URL — and remember the answer may then contain a credential. | ||
| 93 | + | ||
| 94 | +### `webhook_trigger` | ||
| 95 | + | ||
| 96 | +```json | ||
| 97 | +{ "name": "deploy-note", "payload": { "event": "deploy", "service": "api", "status": "ok" } } | ||
| 98 | +``` | ||
| 99 | + | ||
| 100 | +``` | ||
| 101 | +POST deploy-note -> HTTP 200 in 41 ms | ||
| 102 | +ok: yes | ||
| 103 | +body: | ||
| 104 | +ok | ||
| 105 | +``` | ||
| 106 | + | ||
| 107 | +| argument | meaning | | ||
| 108 | +|---|---| | ||
| 109 | +| `name` | a name `webhook_list` reported | | ||
| 110 | +| `payload` | the body. An object or array is serialised as JSON; a string is sent as a JSON string literal. Defaults to `{}` | | ||
| 111 | +| `query` | optional query string appended to the hook's URL, no leading `?` (`event=deploy&env=prod`) | | ||
| 112 | + | ||
| 113 | +The result carries the status, latency, byte count and the first 4 KiB of the | ||
| 114 | +response body. A non-2xx answer is data, not an error: `isError` is only set when the | ||
| 115 | +request could not be made at all (refused address, TLS failure, timeout, unknown | ||
| 116 | +hook name). | ||
| 117 | + | ||
| 118 | +--- | ||
| 119 | + | ||
| 120 | +## The page | ||
| 121 | + | ||
| 122 | +`GET /plugin_webhook` (node-auth required — it lists your endpoints) gives you: | ||
| 123 | + | ||
| 124 | +- the hook table: name, method, endpoint, signature scheme, how many secrets it carries | ||
| 125 | +- a fly-out editor for name / method / URL / description / signature / secret / headers | ||
| 126 | +- a test-fire panel that sends the same request the tool would, and shows the reply | ||
| 127 | +- the last 50 deliveries with status, latency, bytes and reason | ||
| 128 | + | ||
| 129 | +The page follows the bot's theme: `?theme=`, `localStorage.bot_theme`, the | ||
| 130 | +`{type:'sx-theme'}` postMessage handoff, `?embed=1` inside the Chat window, and no | ||
| 131 | +remote script or CDN of any kind. | ||
| 132 | + | ||
| 133 | +--- | ||
| 134 | + | ||
| 135 | +## Signatures | ||
| 136 | + | ||
| 137 | +| scheme | header | what is signed | | ||
| 138 | +|---|---|---| | ||
| 139 | +| `github` | `X-Hub-Signature-256: sha256=<hex>` | HMAC-SHA256 over the body | | ||
| 140 | +| `gitlab` | `X-Gitlab-Token: <secret>` | shared token (not a MAC) | | ||
| 141 | +| `v2` | `X-Webhook-Timestamp` + `X-Webhook-Signature: t=<unix>,v1=<hex>` | HMAC-SHA256 over `"<unix>." + body` | | ||
| 142 | + | ||
| 143 | +`v2` exists because a body-only signature never expires: a captured request can be | ||
| 144 | +replayed forever. With a timestamp the verifier can close a window. Body-only V1 is | ||
| 145 | +deliberately **not** offered. | ||
| 146 | + | ||
| 147 | +The HMAC is implemented in `src/sha256.c` — FIPS 180-4 and RFC 2104, pinned by the | ||
| 148 | +published vectors in `tests/sha256_vectors.c`, because "our HMAC matches Python's" | ||
| 149 | +proves only that both are wrong in the same way. | ||
| 150 | + | ||
| 151 | +--- | ||
| 152 | + | ||
| 153 | +## Configuration | ||
| 154 | + | ||
| 155 | +| where | what | | ||
| 156 | +|---|---| | ||
| 157 | +| `~/.scorpiox/connectors/plugin_webhook/hooks.json` | the store (mode **0600**). On a BotCloud container: `/workspace/.scorpiox/connectors/plugin_webhook/hooks.json`. Windows: `%LOCALAPPDATA%\scorpiox\connectors\plugin_webhook\hooks.json` | | ||
| 158 | +| `WEBHOOK_STORE_PATH` | point the store somewhere else (used by the tests) | | ||
| 159 | +| `WEBHOOK_ALLOW_PRIVATE=1` | lift the SSRF policy so loopback / RFC1918 endpoints are reachable. Never set it on a node you do not fully control | | ||
| 160 | +| `WEBHOOK_TLS_CA_FILE` | extra PEM anchors for a self-signed endpoint. There is still no way to skip verification | | ||
| 161 | +| `BOT_PASSWORD` | the node password the CGI routes require (already set by the bot) | | ||
| 162 | + | ||
| 163 | +Store file, written atomically through `<path>.tmp` + `rename()` so a crash cannot | ||
| 164 | +truncate it: | ||
| 165 | + | ||
| 166 | +```json | ||
| 167 | +{ | ||
| 168 | + "version": 1, | ||
| 169 | + "hooks": [ | ||
| 170 | + { | ||
| 171 | + "name": "deploy-note", | ||
| 172 | + "url": "https://hooks.slack.com/services/T000/B000/XXXX", | ||
| 173 | + "method": "POST", | ||
| 174 | + "desc": "Deploy notification", | ||
| 175 | + "sig": "github", | ||
| 176 | + "secret": "<hmac key>", | ||
| 177 | + "headers": [ | ||
| 178 | + { "name": "Authorization", "value": "Bearer <token>" }, | ||
| 179 | + { "name": "X-Custom", "value": "alpha" } | ||
| 180 | + ] | ||
| 181 | + } | ||
| 182 | + ], | ||
| 183 | + "log": [ | ||
| 184 | + { "at": "2026-11-14T04:05:06Z", "name": "deploy-note", "status": 200, | ||
| 185 | + "ok": true, "bytes": 11, "ms": 41, "error": "" } | ||
| 186 | + ] | ||
| 187 | +} | ||
| 188 | +``` | ||
| 189 | + | ||
| 190 | +An edit that leaves a header's value or the HMAC secret blank **keeps** the stored | ||
| 191 | +value: the UI never receives a secret, so it cannot send one back. Clearing a | ||
| 192 | +signature is `"sig": ""`. | ||
| 193 | + | ||
| 194 | +--- | ||
| 195 | + | ||
| 196 | +## Limits and refusals | ||
| 197 | + | ||
| 198 | +| limit | value | | ||
| 199 | +|---|---| | ||
| 200 | +| outbound body | 1 MiB | | ||
| 201 | +| response preview | 4 KiB (with `truncated: true` when larger) | | ||
| 202 | +| response drained | 8 MiB | | ||
| 203 | +| connect / read deadline | 10 s / 15 s | | ||
| 204 | +| hooks | 64 | | ||
| 205 | +| headers per hook | 16 | | ||
| 206 | +| delivery log | 50 entries | | ||
| 207 | +| redirects | **none** — a 3xx is reported as its status | | ||
| 208 | + | ||
| 209 | +Refused outright: `ftp://` and every non-http scheme, credentials in the URL | ||
| 210 | +(`https://user:pw@…`), IPv6 literals, a header name containing a space or a control | ||
| 211 | +character, a header value containing CR/LF (request splitting), a signature scheme | ||
| 212 | +with no secret, a hook name with anything outside `[A-Za-z0-9._-]`, and a duplicate | ||
| 213 | +name on create. | ||
| 214 | + | ||
| 215 | +Framing headers (`Host`, `Content-Length`, `Transfer-Encoding`, `Connection`) in a | ||
| 216 | +hook's header list are ignored: they are the request's, not the user's. | ||
| 217 | + | ||
| 218 | +--- | ||
| 219 | + | ||
| 220 | +## Build | ||
| 221 | + | ||
| 222 | +```sh | ||
| 223 | +make # native -> ./plugin_webhook | ||
| 224 | +make musl # static musl x86_64 | ||
| 225 | +make arm64 # static arm64 musl | ||
| 226 | +make win64 # MinGW-w64 static PE (WinHTTP + Schannel, zero DLLs) | ||
| 227 | +make macos # Apple clang (run on macOS) | ||
| 228 | +make asan # ASan + UBSan + _FORTIFY_SOURCE=2 | ||
| 229 | +make fortify # -D_FORTIFY_SOURCE=2 | ||
| 230 | +make ui # regenerate src/ui_html.h from src/ui.html | ||
| 231 | +make test # tests/run.sh (offline, 139 checks) | ||
| 232 | +make e2e # tests/e2e.py (Playwright, 1440/1024/390 x dark/light) | ||
| 233 | +``` | ||
| 234 | + | ||
| 235 | +The only third-party C is vendored under `vendor/`: **yyjson** (MIT) and | ||
| 236 | +**Mbed TLS 3.6.7** (Apache-2.0). Everything compiles into the binary, so `ldd` says | ||
| 237 | +*not a dynamic executable* on every Linux target and the PE needs no DLL. On Windows | ||
| 238 | +the HTTP and TLS legs are WinHTTP instead, so no crypto object files are reached. | ||
| 239 | + | ||
| 240 | +``` | ||
| 241 | +src/plugin_webhook.c the five modes, the two tools, the JSON API, the page | ||
| 242 | +src/wh_http.{c,h} URL parse, SSRF deny list, one HTTP/1.1 request (+ WinHTTP) | ||
| 243 | +src/wh_tls.{c,h} mbedTLS over an already-validated socket (POSIX) | ||
| 244 | +src/wh_store.{c,h} the 0600 store, redacting serializers, the delivery log | ||
| 245 | +src/sha256.{c,h} SHA-256 + HMAC-SHA256 (FIPS 180-4 / RFC 2104) | ||
| 246 | +src/wh_buf.{c,h} one growable buffer + JSON/HTML escapes | ||
| 247 | +src/ui.html the page source; tools/gen_ui.py splices the bot theme in | ||
| 248 | +vendor/ yyjson, Mbed TLS, their licences | ||
| 249 | +tests/ run.sh, mockrecv.py, e2e.py, sha256_vectors.c | ||
| 250 | +``` | ||
| 251 | + | ||
| 252 | +--- | ||
| 253 | + | ||
| 254 | +## Testing | ||
| 255 | + | ||
| 256 | +`tests/run.sh` (139 checks) starts a **recording** receiver — not a "returns 200" | ||
| 257 | +stub — which writes every request it gets, method, path, query and every header, to a | ||
| 258 | +JSONL log. The suite then asserts the request that actually went on the wire: | ||
| 259 | + | ||
| 260 | +- method, path and query match the hook definition | ||
| 261 | +- the stored `Authorization` header and custom headers arrived verbatim | ||
| 262 | +- `X-Hub-Signature-256` equals `hmac(secret, body)` computed independently in Python | ||
| 263 | +- `v2`'s signature covers `timestamp.body` and its timestamp is live | ||
| 264 | +- the body arrived byte-identical, including from the MCP path | ||
| 265 | +- 4xx is delivered and reported, a 302 is reported and **not** followed, a chunked | ||
| 266 | + body is decoded, an oversized body is truncated and says so | ||
| 267 | +- loopback is refused while the policy is closed and reachable with the opt-in | ||
| 268 | +- the store is 0600, a corrupt store is reported and left untouched, a nested path is | ||
| 269 | + created on demand | ||
| 270 | +- every read path redacts — header values, the HMAC secret, the query string | ||
| 271 | +- the MCP loop reads a body and its terminating newline written as **two** separate | ||
| 272 | + writes (the connector router's `proc_send` shape), which a `fread`-based reader | ||
| 273 | + would hang on | ||
| 274 | +- ASan/UBSan is clean and `_FORTIFY_SOURCE=2` works | ||
| 275 | +- no `system(`, no `popen(`, no `<script src=`, no private address, no secret in git | ||
| 276 | + history | ||
| 277 | + | ||
| 278 | +`tests/e2e.py` drives the real page with Playwright: three viewports, both themes, no | ||
| 279 | +console/page error, no horizontal overflow, hooks CRUD + fire + delete through the UI, | ||
| 280 | +a stored secret kept when its field is left blank, and a screenshot per viewport. | ||
| 281 | + | ||
| 282 | +--- | ||
| 283 | + | ||
| 284 | +## Licence | ||
| 285 | + | ||
| 286 | +MIT — see `LICENSE`. Vendored components keep their own MIT/Apache-2.0 licences | ||
| 287 | +(`vendor/`). |
| 1 | new file mode 100644 | 1 | new file mode 100644 |
| index 0000000..2968b90 | index 0000000..2968b90 | ||
| --- /dev/null | --- /dev/null | ||
| +++ b/docs/SECURITY.md | +++ b/docs/SECURITY.md | ||
| @@ -0,0 +1,81 @@ | @@ -0,0 +1,81 @@ | ||
| 1 | +# Security posture of `plugin_webhook` | ||
| 2 | + | ||
| 3 | +This plugin makes outbound HTTP requests whose URL, headers and secret come from a | ||
| 4 | +user, and gives an agent a verb that fires them. That combination deserves an explicit | ||
| 5 | +statement of what is and is not possible. | ||
| 6 | + | ||
| 7 | +## What the plugin can do | ||
| 8 | + | ||
| 9 | +| Capability | Detail | | ||
| 10 | +|---|---| | ||
| 11 | +| Outbound HTTP/HTTPS | one request per `webhook_trigger` (or test fire), method GET/POST/PUT/PATCH/DELETE/HEAD | | ||
| 12 | +| Arbitrary request headers | except `Host`, `Content-Length`, `Transfer-Encoding`, `Connection` | | ||
| 13 | +| HMAC-SHA256 signing | `github`, `gitlab` shared-token and timestamped `v2` | | ||
| 14 | +| Read one file | its own store (`hooks.json`) | | ||
| 15 | +| Write one file | the same store, plus its `.tmp` sibling, at mode 0600 | | ||
| 16 | +| Read the node clock | only to stamp the `v2` signature and the delivery log | | ||
| 17 | + | ||
| 18 | +## What it cannot do | ||
| 19 | + | ||
| 20 | +- **Run a program.** There is no `system()`, no `popen()`, no `exec*()` anywhere in | ||
| 21 | + the source; `tests/run.sh` greps for all three and fails the build. | ||
| 22 | +- **Read another file.** The store path is the only path opened for write; the only | ||
| 23 | + other paths read are the TLS CA bundles. | ||
| 24 | +- **Reach a private address by accident.** Every address a hostname resolves to is | ||
| 25 | + checked against loopback / RFC1918 / link-local / CGNAT / ULA / multicast / | ||
| 26 | + documentation ranges *before* a socket is opened. `WEBHOOK_ALLOW_PRIVATE=1` is the | ||
| 27 | + only way through, and it is a deliberate operator action on a node the operator | ||
| 28 | + controls. | ||
| 29 | +- **Follow a redirect.** A 3xx is reported as its status. Following one would mean a | ||
| 30 | + hook definition silently becomes a request to somewhere the operator never | ||
| 31 | + configured - and the second hop would be the one carrying the secrets. | ||
| 32 | +- **Send over unverified TLS.** `MBEDTLS_SSL_VERIFY_REQUIRED`, TLS 1.2 minimum, | ||
| 33 | + hostname checked against the certificate, anchors from `WEBHOOK_TLS_CA_FILE` or the | ||
| 34 | + system bundle. There is no insecure flag in the source to turn on. | ||
| 35 | +- **Leak a secret to the agent or the browser.** Every serializer that faces an MCP | ||
| 36 | + client or a CGI response emits header *names* and `has_secret`; the HMAC emits its | ||
| 37 | + scheme and `has_secret`. The store document itself is the only place a value | ||
| 38 | + exists, and it is mode 0600. | ||
| 39 | + | ||
| 40 | +## Threats and the answer | ||
| 41 | + | ||
| 42 | +**Prompt injection turns the agent into an exfiltration tool.** The agent can only | ||
| 43 | +name a hook (`webhook_list` reported the names). It cannot set a URL, a header or a | ||
| 44 | +secret, and it cannot read them back. The worst it can do with a hostile instruction | ||
| 45 | +is send a payload to an endpoint the operator already trusts. | ||
| 46 | + | ||
| 47 | +**A pasted URL contains a provider token.** `webhook_list` redacts the query string by | ||
| 48 | +default (`?<redacted>`), so a Slack or Zapier URL pasted into the form does not put its | ||
| 49 | +token into a transcript. `redact_url: false` is available and documented as the risky | ||
| 50 | +choice. | ||
| 51 | + | ||
| 52 | +**DNS rebinding to a private address.** The check runs on the *numeric* answers of the | ||
| 53 | +lookup, all of them, not on the hostname; the connection is then made to the validated | ||
| 54 | +address, so a second lookup after the check cannot change where the bytes go. | ||
| 55 | + | ||
| 56 | +**Request splitting.** A header value containing CR or LF is refused at save time | ||
| 57 | +(`value` validation) and again at request time (`wh_http.c` skips framing headers and | ||
| 58 | +writes headers from validated names). | ||
| 59 | + | ||
| 60 | +**Replay of a captured request.** Body-only signatures are not offered. `v2` signs | ||
| 61 | +`"<unix>." + body`, so a verifier that keeps a time window rejects a replayed request. | ||
| 62 | + | ||
| 63 | +**A corrupt store eating the secrets.** The document is written to `.tmp` and | ||
| 64 | +`rename()`d, and a store that fails to parse is *reported and left untouched* - the | ||
| 65 | +plugin never rewrites a file it could not read. | ||
| 66 | + | ||
| 67 | +**A runaway response.** Bodies are capped at 4 KiB of preview with an 8 MiB drain | ||
| 68 | +ceiling, an outbound body at 1 MiB, and every connect/read phase has a deadline. | ||
| 69 | + | ||
| 70 | +## The auth gate | ||
| 71 | + | ||
| 72 | +The CGI page and every `?action=` route call `require_node_auth()` - the page lists | ||
| 73 | +endpoint URLs, so it is node-private data. `--meta`, `--schema` and `--mcp` return | ||
| 74 | +*before* the gate: discovery and the tool surface must work on a locked node, and | ||
| 75 | +neither reveals a hook. | ||
| 76 | + | ||
| 77 | +## Reporting | ||
| 78 | + | ||
| 79 | +Open an issue at | ||
| 80 | +`https://plugingit.scorpiox.net/repo?name=scorpiox-bot-plugin-webhook`, or contact | ||
| 81 | +SCORPIOX INC directly for anything you would rather not describe in public. | ||
| 0 | 82 |