Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@capriza/safe-sql

Package Overview
Dependencies
Maintainers
14
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@capriza/safe-sql

'SQL' template tag for supporting safe Sequelize queries

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
14
Weekly downloads
 
Created
Source

safe-sql

Protect your code from accidental SQL injection vulnerabilities by using the SQL template tag on raw SQL queries with Sequelize.

Provides the best protection against accidental SQL injection when combined with the use of https://github.com/capriza/eslint-plugin-safe-sql.

Installation

$ npm install @capriza/safe-sql

Usage

// the wrong way - potential vulnerability
sequelize.query(`SELECT * FROM users WHERE name = ${req.query.username}`);

// the right way - using bind
sequelize.query(`SELECT * FROM users WHERE name = $1`, {bind: [req.query.username]});

// the best way - using safe-sql
const SQL = require("safe-sql");
sequelize.query(SQL`SELECT * FROM users WHERE name = ${req.query.username}`);

concat

The concat method enables building a single SQL query from a concatenation of several sql query parts

let query = SQL`SELECT * FROM users WHERE name = ${req.query.username}`;
if (req.query.location) {
  query.concat(SQL` AND location = ${req.query.location}`);
}
query.concat(SQL` LIMIT ${req.query.limit}`);
sequelize.query(query);
// -> SELECT * FROM users WHERE name = $1 AND location = $2 LIMIT $3`

FAQs

Package last updated on 28 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc