# plugin_webhook — named webhooks & REST triggers for SCORPIOX BOT A zero-dependency pure-C99 **MCP connector** that gives your agent one safe verb: *fire the webhook called `deploy-note`, with this JSON body*. You define the endpoints. The node keeps the secrets. ``` ┌──────────────┐ webhook_trigger("deploy-note", {…}) ┌────────────────┐ │ SCORPIOX │ ─────────────────────────────────────► │ plugin_webhook │ │ BOT agent │ │ on the node │ └──────────────┘ ◄───── "HTTP 200 in 41 ms" ─────────── └───────┬────────┘ │ POST, headers, │ HMAC signature ▼ Slack · Discord · Zapier · n8n · IFTTT · your own REST endpoint ``` The agent never sees the bearer token or the signing secret. It sees `has_secret: true`. --- ## Why this shape Hermes Agent's `gateway/platforms/webhook` and OpenClaw's `extensions/admin-http-rpc` both solve the same problem — *an operator's endpoint definitions, used by an agent* — and both make the same two decisions this plugin keeps: 1. **A named registry, not a tool per endpoint.** Publishing every hook as its own MCP tool floods a model's context with names it will never call. Two tools (`webhook_list`, `webhook_trigger`) scale to any number of hooks, and adding one needs no restart. 2. **The secret never enters the prompt.** A header value or an HMAC key that has ever appeared in a transcript is a compromised secret. Every read path here reports presence only. Two things this plugin adds, because a self-hosted node has a different threat model from a hosted gateway: 3. **SSRF policy before the socket.** A user-supplied URL is a request to make the node fetch something on the user's behalf. Every address the hostname resolves to is checked against loopback / RFC1918 / link-local / CGNAT / ULA / multicast / documentation ranges *before* connecting, and the connection then goes to that validated numeric address — so a DNS answer that changes between check and connect cannot move the request onto a private network. 4. **Verified TLS with no bypass.** There is no `--insecure` flag, no environment switch and no config key that turns verification off. A webhook carrying a token must not be sendable over a channel that cannot prove who it is talking to. --- ## Install ```sh # from the marketplace bot.scorpiox.net → Settings → Plugins → Marketplace → webhook → Install # or from source, on the node git clone https://plugingit.scorpiox.net/scorpiox-bot-plugin-webhook.git cd scorpiox-bot-plugin-webhook make && install -m 0755 plugin_webhook ~/.scorpiox/plugins/ ``` The plugin is discovered by `GET /plugins` with no restart. On a BotCloud container it installs into `/workspace/.scorpiox/plugins` instead, which survives a `stop`/`start` cycle. --- ## The tools ### `webhook_list` ```json {} ``` ``` 2 configured webhooks - deploy-note POST https://hooks.slack.com/services/ [signed: github] [2 headers] Deploy notification - status-probe PUT https://api.example.com/echo? Probe with a pasted token ``` `redact_url` defaults to **true**: the path is kept (it identifies the endpoint) and the query string is replaced with ``, because a pasted webhook URL usually carries its token there. Pass `{"redact_url": false}` when you genuinely need to see the whole URL — and remember the answer may then contain a credential. ### `webhook_trigger` ```json { "name": "deploy-note", "payload": { "event": "deploy", "service": "api", "status": "ok" } } ``` ``` POST deploy-note -> HTTP 200 in 41 ms ok: yes body: ok ``` | argument | meaning | |---|---| | `name` | a name `webhook_list` reported | | `payload` | the body. An object or array is serialised as JSON; a string is sent as a JSON string literal. Defaults to `{}` | | `query` | optional query string appended to the hook's URL, no leading `?` (`event=deploy&env=prod`) | The result carries the status, latency, byte count and the first 4 KiB of the response body. A non-2xx answer is data, not an error: `isError` is only set when the request could not be made at all (refused address, TLS failure, timeout, unknown hook name). --- ## The page `GET /plugin_webhook` (node-auth required — it lists your endpoints) gives you: - the hook table: name, method, endpoint, signature scheme, how many secrets it carries - a fly-out editor for name / method / URL / description / signature / secret / headers - a test-fire panel that sends the same request the tool would, and shows the reply - the last 50 deliveries with status, latency, bytes and reason The page follows the bot's theme: `?theme=`, `localStorage.bot_theme`, the `{type:'sx-theme'}` postMessage handoff, `?embed=1` inside the Chat window, and no remote script or CDN of any kind. --- ## Signatures | scheme | header | what is signed | |---|---|---| | `github` | `X-Hub-Signature-256: sha256=` | HMAC-SHA256 over the body | | `gitlab` | `X-Gitlab-Token: ` | shared token (not a MAC) | | `v2` | `X-Webhook-Timestamp` + `X-Webhook-Signature: t=,v1=` | HMAC-SHA256 over `"." + body` | `v2` exists because a body-only signature never expires: a captured request can be replayed forever. With a timestamp the verifier can close a window. Body-only V1 is deliberately **not** offered. The HMAC is implemented in `src/sha256.c` — FIPS 180-4 and RFC 2104, pinned by the published vectors in `tests/sha256_vectors.c`, because "our HMAC matches Python's" proves only that both are wrong in the same way. --- ## Configuration | where | what | |---|---| | `~/.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` | | `WEBHOOK_STORE_PATH` | point the store somewhere else (used by the tests) | | `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 | | `WEBHOOK_TLS_CA_FILE` | extra PEM anchors for a self-signed endpoint. There is still no way to skip verification | | `BOT_PASSWORD` | the node password the CGI routes require (already set by the bot) | Store file, written atomically through `.tmp` + `rename()` so a crash cannot truncate it: ```json { "version": 1, "hooks": [ { "name": "deploy-note", "url": "https://hooks.slack.com/services/T000/B000/XXXX", "method": "POST", "desc": "Deploy notification", "sig": "github", "secret": "", "headers": [ { "name": "Authorization", "value": "Bearer " }, { "name": "X-Custom", "value": "alpha" } ] } ], "log": [ { "at": "2026-11-14T04:05:06Z", "name": "deploy-note", "status": 200, "ok": true, "bytes": 11, "ms": 41, "error": "" } ] } ``` An edit that leaves a header's value or the HMAC secret blank **keeps** the stored value: the UI never receives a secret, so it cannot send one back. Clearing a signature is `"sig": ""`. --- ## Limits and refusals | limit | value | |---|---| | outbound body | 1 MiB | | response preview | 4 KiB (with `truncated: true` when larger) | | response drained | 8 MiB | | connect / read deadline | 10 s / 15 s | | hooks | 64 | | headers per hook | 16 | | delivery log | 50 entries | | redirects | **none** — a 3xx is reported as its status | Refused outright: `ftp://` and every non-http scheme, credentials in the URL (`https://user:pw@…`), IPv6 literals, a header name containing a space or a control character, a header value containing CR/LF (request splitting), a signature scheme with no secret, a hook name with anything outside `[A-Za-z0-9._-]`, and a duplicate name on create. Framing headers (`Host`, `Content-Length`, `Transfer-Encoding`, `Connection`) in a hook's header list are ignored: they are the request's, not the user's. --- ## Build ```sh make # native -> ./plugin_webhook make musl # static musl x86_64 make arm64 # static arm64 musl make win64 # MinGW-w64 static PE (WinHTTP + Schannel, zero DLLs) make macos # Apple clang (run on macOS) make asan # ASan + UBSan + _FORTIFY_SOURCE=2 make fortify # -D_FORTIFY_SOURCE=2 make ui # regenerate src/ui_html.h from src/ui.html make test # tests/run.sh (offline, 139 checks) make e2e # tests/e2e.py (Playwright, 1440/1024/390 x dark/light) ``` The only third-party C is vendored under `vendor/`: **yyjson** (MIT) and **Mbed TLS 3.6.7** (Apache-2.0). Everything compiles into the binary, so `ldd` says *not a dynamic executable* on every Linux target and the PE needs no DLL. On Windows the HTTP and TLS legs are WinHTTP instead, so no crypto object files are reached. ``` src/plugin_webhook.c the five modes, the two tools, the JSON API, the page src/wh_http.{c,h} URL parse, SSRF deny list, one HTTP/1.1 request (+ WinHTTP) src/wh_tls.{c,h} mbedTLS over an already-validated socket (POSIX) src/wh_store.{c,h} the 0600 store, redacting serializers, the delivery log src/sha256.{c,h} SHA-256 + HMAC-SHA256 (FIPS 180-4 / RFC 2104) src/wh_buf.{c,h} one growable buffer + JSON/HTML escapes src/ui.html the page source; tools/gen_ui.py splices the bot theme in vendor/ yyjson, Mbed TLS, their licences tests/ run.sh, mockrecv.py, e2e.py, sha256_vectors.c ``` --- ## Testing `tests/run.sh` (139 checks) starts a **recording** receiver — not a "returns 200" stub — which writes every request it gets, method, path, query and every header, to a JSONL log. The suite then asserts the request that actually went on the wire: - method, path and query match the hook definition - the stored `Authorization` header and custom headers arrived verbatim - `X-Hub-Signature-256` equals `hmac(secret, body)` computed independently in Python - `v2`'s signature covers `timestamp.body` and its timestamp is live - the body arrived byte-identical, including from the MCP path - 4xx is delivered and reported, a 302 is reported and **not** followed, a chunked body is decoded, an oversized body is truncated and says so - loopback is refused while the policy is closed and reachable with the opt-in - the store is 0600, a corrupt store is reported and left untouched, a nested path is created on demand - every read path redacts — header values, the HMAC secret, the query string - the MCP loop reads a body and its terminating newline written as **two** separate writes (the connector router's `proc_send` shape), which a `fread`-based reader would hang on - ASan/UBSan is clean and `_FORTIFY_SOURCE=2` works - no `system(`, no `popen(`, no `