-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The gate the whole API depends on\n\nEvery authenticated endpoint in Budibase's server runs behind `packages/server/src/middleware/authorized.ts`. The first executable line of that middleware, on line 94 of the file as shipped in 3.31.4, is:\n\n```typescript\nif (isWebhookEndpoint(ctx) || ctx.internal) {\n return next()\n}\n```\n\n`return next()` in koa is \"advance to the next middleware in the chain.\" Nothing else inside `authorized()` runs: not the user lookup, not the resource-permission resolver, not the role-hierarchy traversal, not the base-permission check, not the CSRF gate. The request arrives at its handler as if `authorized()` were not installed. The decision rests on a single boolean.\n\nThe decision has to exist. Budibase webhook endpoints have their own auth model: the webhook URL embeds an app id and a webhook id, and the handler validates both against the stored record. A site-wide authentication check ahead of those handlers would block the legitimate caller. The structural question is real: is this request actually for a webhook endpoint?\n\n`isWebhookEndpoint(ctx)` is what answered it.\n\n## `isWebhookEndpoint` asked a different question\n\nIn `packages/server/src/middleware/utils.ts`, in the version 3.31.4 shipped, `isWebhookEndpoint` read:\n\n```typescript\nconst WEBHOOK_ENDPOINTS = new RegExp(\n [\n \"webhooks/trigger\",\n \"webhooks/schema\",\n \"webhooks/discord\",\n \"webhooks/ms-teams\",\n \"webhooks/slack\",\n ].join(\"|\")\n)\n\nexport function isWebhookEndpoint(ctx: UserCtx) {\n return WEBHOOK_ENDPOINTS.test(ctx.request.url)\n}\n```\n\nThe regex compiles to the alternation `webhooks/trigger|webhooks/schema|webhooks/discord|webhooks/ms-teams|webhooks/slack`. No `^`. No `$`. No word boundary. `RegExp.test()` returns true on any substring match.\n\nThe target is `ctx.request.url`. In koa, `ctx.request.url` is the request line's URL: path and query string concatenated, exactly as the client sent them. The same Koa request object exposes `ctx.request.path`, the path component segment-parsed. The middleware reached for the unparsed form.\n\nEither decision in isolation would have produced a working gate. An anchored regex applied to the full URL still tests the path, because the URL begins with `/api/` and the alternation can only land on a position that begins with `webhooks/`. A substring regex applied to `ctx.request.path` still tests only path bytes. The combination is the bypass: an unanchored regex that takes substring matches, run against a string that includes the query, where the query is the caller's.\n\nThe function was named `isWebhookEndpoint`. A webhook endpoint is a structural property of the request: the path component begins with one of five strings. The implementation does not test that property. It tests whether a substring matches anywhere in the URL the client sent. Anywhere includes the query string.\n\n## The curl\n\nThe nuclei template at `projectdiscovery/nuclei-templates/http/cves/2026/CVE-2026-31816.yaml` encodes the chain in one request:\n\n```http\nPOST /api/ta_users/search?/webhooks/trigger HTTP/1.1\nHost: \nContent-Type: application/json\nx-budibase-app-id: \n\n{\"query\":{},\"limit\":1000}\n```\n\nThe HTTP path is `/api/ta_users/search`. The query string is `/webhooks/trigger`. Koa's router dispatches by path: it parses the URL, takes the path component, walks the route trie. The route trie matches `POST /api/:tableId/search`, the row-search endpoint for an in-app table. Path-side, the request is going to row-search, not to a webhook.\n\n`authorized()` runs first. `isWebhookEndpoint(ctx)` evaluates the unanchored alternation against `ctx.request.url`, which is the full string `/api/ta_users/search?/webhooks/trigger`. The substring `webhooks/trigger` appears at position 22. The regex matches. The function returns true. The middleware returns `next()`. The request reaches the row-search handler with no caller identity attached.\n\n`ta_users` is Budibase's table-id convention for the default Users table that every Budibase app ships pre-populated. The `ta_` prefix marks a table document in CouchDB. The handler reads the request body's empty filter (`{\"query\":{},\"limit\":1000}`) as \"return up to 1000 rows,\" queries the table, returns the rows as JSON. The nuclei template's matcher confirms the bypass by checking the response body for `email`, `roleId`, and `status`, the three columns Budibase's default Users table ships with.\n\nThe GHSA advisory's own PoC list goes further than the nuclei template. `POST /api/tables?/webhooks/trigger` creates tables. `DELETE /api/tables//?/webhooks/trigger` deletes them. Datasources, automations, roles, integrations, and views are all reachable the same way. The CVSS vector reads `A:N`. The advisory's PoC list includes \"delete tables.\" Both statements are about the same bug.\n\nThe only precondition is a valid `x-budibase-app-id`. App IDs are not secrets; the published URL of any Budibase app contains its app id in plain text.\n\n## Two errors, two fixes\n\nThe fix landed on the branch named `bypass-via-webhook-query-param`, merged as commit `d657d82b` on March 5, 2026. The diff against `utils.ts` is:\n\n```diff\n const WEBHOOK_ENDPOINTS = new RegExp(\n- [\n- \"webhooks/trigger\",\n- \"webhooks/schema\",\n- \"webhooks/discord\",\n- \"webhooks/ms-teams\",\n- \"webhooks/slack\",\n- ].join(\"|\")\n+ \"^/api/webhooks/(trigger|schema|discord|ms-teams|slack)(/|$)\"\n )\n\n export function isWebhookEndpoint(ctx: UserCtx) {\n- return WEBHOOK_ENDPOINTS.test(ctx.request.url)\n+ const path = ctx.path || ctx.request.url.split(\"?\")[0]\n+ return WEBHOOK_ENDPOINTS.test(path)\n }\n```\n\nThe regex is anchored at `^/api/webhooks/` and bounded at the trailing `(/|$)`. Even if the haystack were the full URL, the alternation can no longer land on a substring buried in a query string; the only position that satisfies the new pattern is the start of the request path. Separately, the haystack is no longer the full URL: the function takes `ctx.path` when koa has populated it, falling back to the path-only prefix of `ctx.request.url`. Even if the regex were still unanchored, the bypass would have nowhere to write.\n\nEither change closes CVE-2026-31816. The developer shipped both. That is the developer's admission that either alone was not trusted.\n\nThe test the same PR added reads:\n\n```typescript\nit(\"does not bypass auth when webhook path appears in query string\", async () => {\n config.setRequestUrl(\"/api/tables?/webhooks/trigger\")\n await config.executeMiddleware()\n expect(config.throw).toHaveBeenCalledWith(401, \"No user info found\")\n expect(config.next).not.toHaveBeenCalled()\n})\n```\n\nThe branch is `bypass-via-webhook-query-param`. The PR title is `Bypass via webhook query param`. The test method is `does not bypass auth when webhook path appears in query string`. Every artifact the vendor's own developer touched while landing the fix names the bug class.\n\n## Predicate stringifies the object, again\n\nThis is the [predicate-stringifies-the-object](https://nefariousplan.com/patterns/predicate-stringifies-the-object) shape. A security predicate intends to test one field of a structured value. The implementation tests a substring or equality match against the value's stringified form. The string representation includes other attacker-controlled fields the predicate did not mean to read. The bypass writes the gate's allow-string into one of those fields.\n\nBudibase is the fourth exhibit of the pattern in the catalog. [ChurchCRM's `AuthMiddleware`](https://nefariousplan.com/posts/churchcrm-auth-checks-the-whole-uri) ran `str_contains($request->getUri(), 'api/public')` against PSR-7's `__toString()` and accepted the allow-string from a query parameter. [PaperCut's `SecurityRequestFilter`](https://nefariousplan.com/posts/papercut-2023-27351-keepalive-after-the-semicolon) ran an allowlist match against `HttpServletRequest::getRequestURI()` and accepted the allow-string from a Servlet path parameter. [HPE Aruba's AOS-CX nginx gate](https://nefariousplan.com/posts/aos-cx-cve-2026-23813-the-dot-matched-slash) ran the regex `^/rest/(|v.*/)login` against the URI as a flat string and accepted `login` because PCRE's `.` ignored segment boundaries.\n\nEach is the same shape in a different framework's clothes. ChurchCRM was PHP / PSR-7 and the stringification was `__toString()`. PaperCut was Java / Servlets and the stringification was `getRequestURI()`. AOS-CX was nginx / PCRE and the stringification was a hand-written regex whose dot consumed `/`. Budibase is JavaScript / Koa and the stringification is `ctx.request.url`. The structural fact reads the same in all four: any security predicate that uses a string operator against an object with more than one property worth reading admits the gate's allow-string from any of those properties.\n\nKoa exposed the structurally correct accessor the entire time. It is called `ctx.path`. The patched code reaches for it.\n\nPoC: [projectdiscovery/nuclei-templates](https://github.com/projectdiscovery/nuclei-templates/blob/main/http/cves/2026/CVE-2026-31816.yaml)","closing_line":"The function was named `isWebhookEndpoint`. The function returned true on `/api/ta_users/search?/webhooks/trigger`.","hook_md":"Budibase's `authorized()` middleware has a single short-circuit ahead of every authentication check: if the request is for a webhook endpoint, skip auth. The function answering \"is this a webhook endpoint?\" was an unanchored regex run against the full request URL. The query string is part of the URL. The query string is whatever the caller writes.\n\nCVE-2026-31816 is the auth gate of every server-side endpoint in Budibase asking whether a substring appears anywhere in a string the caller controls.","post_id":574,"slug":"budibase-cve-2026-31816-iswebhookendpoint-tested-the-stringified-url","title":"CVE-2026-31816: Budibase's `isWebhookEndpoint` Tested The Stringified URL. The Query String Was The Bypass.","type":"initial","unreadable_sentence":"The function was named `isWebhookEndpoint`. The function returned true on `/api/ta_users/search?/webhooks/trigger`."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCarQwQQAKCRDeZjl4jgkQ Jg/AAQDzGeoQfpFL3dvN8cC+lGrdsX3rlMz2mZTcJPTCeqlSnwEAsE3OIIVbi7aT MTkLdgoKRAURc/lJrHOLMaasBCh1GgM= =kNUv -----END PGP SIGNATURE-----