Summary
A high-severity SQL injection vulnerability in node-sql-query can allow attacker-controlled request parameters to alter database queries. The issue becomes risky when values handled by the Request Parameter Handler reach SelectQuery.from or SelectQuery.build without reliable parameterization or input constraints.
Affected context
The vulnerability occurs in applications using affected node-sql-query releases where request-derived values are processed by the Request Parameter Handler and passed into the SelectQuery implementation in lib/Select.js. Risk depends on whether external input can reach these query-building functions and whether the resulting database account has access to sensitive data or modification capabilities.
Exploit preconditions
- Attack surface: Application endpoints or services that construct queries through the Request Parameter Handler
- Required access: Ability to submit or influence request parameters processed by the affected query-building path
- Trigger point: Invocation of
SelectQuery.fromorSelectQuery.build - Why exploitation is possible: Attacker-controlled values may be incorporated into SQL query structure without sufficient parameterization or context-aware validation
Why this happens
The underlying bug is an unsafe boundary between externally influenced request parameters and SQL query construction. When input is treated as query syntax rather than as data bound through parameters, an attacker may influence the meaning of the generated statement. This maps primarily to CWE-89: Improper Neutralization of Special Elements used in an SQL Command (SQL Injection) and is also related to CWE-74: Improper Neutralization of Special Elements in Output Used by a Downstream Component.
Potential impact
- Sensitive database records may be disclosed
- Database records may be modified or deleted
- Authentication or authorization data may be compromised
- Application behavior may be altered through manipulated query results
- The database service may be used to affect connected systems, depending on privileges
General mitigation guidance
Mitigation generally focuses on ensuring that request data remains data throughout query construction.
Common defensive patterns include:
- Using parameterized queries or prepared statements for values
- Restricting dynamic identifiers, operators, and sort expressions to explicit allowlists
- Separating query structure from user-controlled values
- Applying schema-based validation at request boundaries
- Using database accounts with only the permissions required by the application
- Avoiding direct concatenation or interpolation of request values into SQL text
- Centralizing query construction so secure patterns are applied consistently
How teams detect issues like this
Organizations commonly detect SQL injection risks through:
- Static analysis rules for string concatenation or interpolation in SQL construction
- Code review checks for request parameters passed into query-builder methods
- Dynamic testing with safe, non-destructive injection probes in controlled environments
- Database activity monitoring for anomalous query structure, errors, or access patterns
- Dependency and software composition analysis for affected library usage
- Policy enforcement requiring parameterized database access APIs
Automated code review and security scanning tools may help identify unsafe query-building patterns early.

