Summary
Sequelize versions prior to 6.37.8 contain a SQL injection vulnerability in JSON/JSONB where-clause handling, where user-controlled JSON path keys can influence a CAST(... AS <type>) expression.
If an attacker can control JSON object keys passed into Sequelize queries, they can inject arbitrary SQL and read data from other tables in the same database.
Affected context
The issue arises in Node.js applications using Sequelize (before 6.37.8) when:
- The application uses JSON or JSONB columns in database queries
- JSON path expressions are constructed from dynamic or user-controlled keys
- The internal
_traverseJSON()helper derives a cast type by splitting keys on:: - The derived cast type is embedded directly into
CAST(... AS <type>)without proper escaping
This typically affects APIs that accept flexible JSON filters or field paths and pass them into Sequelize's JSON/JSONB querying helpers.
Exploit preconditions
- Attack surface: Application endpoints or code paths that accept JSON structures and use them to build Sequelize JSON/JSONB where clauses.
- Required access: Ability to supply or influence JSON object keys (not just values) used in query construction, often via HTTP request bodies, query parameters, or message payloads.
- Trigger point: Execution of a Sequelize query that invokes
_traverseJSON()and constructsCAST(... AS <type>)using the attacker-controlled JSON key segment after::. - Why exploitation is possible: The JSON path key is split on
::and the substring after::is treated as a SQL type name and interpolated directly into the CAST expression without parameterization or validation, enabling injection into the SQL query text.
Why this happens
This vulnerability stems from unsafe string interpolation when constructing SQL fragments based on parsed JSON path components.
The _traverseJSON() function interprets pathPart::typeName as a JSON path pathPart combined with a cast type typeName, but it treats typeName as trusted input and inserts it raw into the CAST(... AS <typeName>) clause.
This pattern maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command, where untrusted data is concatenated into SQL rather than bound as parameters or validated against a strict allowlist.
The underlying bug class is dynamic query generation that mixes user-controlled metadata (JSON keys) with SQL syntax without robust sanitization or type validation.
Potential impact
- An attacker may inject arbitrary SQL fragments into CAST expressions, potentially altering the structure of the generated query.
- An attacker could exfiltrate sensitive data from other tables accessible to the database user.
- An attacker can bypass logical filters or modify WHERE clauses to return broader or unintended result sets.
- Under certain schemas and permissions, an attacker might modify or delete data by leveraging stacked or nested injection patterns, depending on the database and query context.
General mitigation guidance
Effective mitigation focuses on treating all components of SQL, including type names and path expressions, as untrusted unless explicitly validated:
- Avoid building SQL fragments from raw string manipulation in ORM internals; prefer parameterized constructs or structured query APIs where possible.
- Validate any cast type or similar meta-parameters against a strict allowlist of expected SQL types before using them in a CAST expression.
- Disallow or normalize special delimiters (such as
::) in user-controlled JSON keys when they are used to form query paths. - Apply defense-in-depth by limiting database account privileges to only the tables and operations the application requires, so that injected queries have reduced impact.
- Prefer secure-by-default query builder patterns that separate data (parameters, keys) from SQL syntax, even for advanced features like JSON path navigation and casting.
How teams detect issues like this
Organizations can look for this class of issue through a combination of static analysis, code review, and runtime monitoring:
- Static analysis and review: Search for ORM helpers or utility functions that:
- Parse user-controlled strings to derive SQL types, operators, or column fragments.
- Use string concatenation to build
CAST,WHERE, or JSON path expressions rather than parameterized methods. - Interpret delimiters like
::in user input for special SQL behavior. - Policy enforcement: Establish coding guidelines that prohibit direct embedding of uncontrolled input into SQL type names, operators, or identifiers, and enforce them via lint rules or pre-merge checks.
- Runtime monitoring: Inspect database query logs for unusual or highly dynamic
CAST(... AS ...)patterns or unexpected type names originating from API inputs. - Automated security tooling, including SAST and ORM-specific linters, can be configured to flag dynamic SQL construction and use of unvalidated type casts.

