Is the SQL Injection Optional?
A Node.js application using Sequelize with the quoteIdentifiers option disabled allowed user-controlled input in attributes and sort parameters to be injected directly into SQL queries. An attacker could perform blind SQL injection, including time-based and boolean-based techniques, and potentially exfiltrate data via UNION queries.
Published on osec.com
SQL injection remains one of the sharpest threats to web applications. This is a walkthrough of a blind SQL injection vulnerability in a Node.js application, caused by one insecure configuration option in Sequelize, a popular Object-Relational Mapping library.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the application disabled Sequelize's quoteIdentifiers option and passed user-controlled attribute names and sort expressions directly to findAll(), allowing SQL syntax to be injected.
Impact
An attacker could read arbitrary data from the database, including the current user, and potentially bypass a WAF using obfuscation.
What the attacker needed
Sequelize with quoteIdentifiers disabled; User-controlled attributes or sort parameters
The fix
The application should validate user-supplied column names and sort expressions against an allowlist derived from the model's attributes, rather than relying on the ORM alone.
How it was found
- Set up a Node.js application with Sequelize and an endpoint that accepts attributes and sort parameters from user input.
- Disable the quoteIdentifiers option in Sequelize configuration.
- Send a POST request with a crafted attributes array containing SQL expressions to observe injection.
- Use time-based payloads with pg_sleep to confirm blind injection.
- Use UNION-based payloads to extract data such as the current database user.
- Use the sort parameter with conditional expressions to extract data via ordering differences.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
This report shows how a small configuration change in a database library can open the door to SQL injection. SQL injection lets an attacker sneak database commands into places where the application expects only data, like a sort order or a list of columns. Here, turning off a quoting feature meant the application stopped wrapping names in protective quotes, so malicious input became part of the database query.
What is SQL injection?
Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.