New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

node-sql-parser

Package Overview
Dependencies
Maintainers
1
Versions
172
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-sql-parser - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

23

lib/parser.js

@@ -15,2 +15,25 @@ 'use strict'

whiteListCheck(sql, whiteList) {
if (!whiteList || whiteList.length === 0) return
const tableAuthorityList = this.tableList(sql)
let hasAuthority = true
let denyTable = ''
for (const tableAuthority of tableAuthorityList) {
let hasTableAuthority = false
for (const whiteAuthority of whiteList) {
const regex = new RegExp(whiteAuthority)
if (regex.test(tableAuthority)) {
hasTableAuthority = true
break
}
}
if (!hasTableAuthority) {
denyTable = tableAuthority
hasAuthority = false
break
}
}
if (!hasAuthority) throw new Error(`SQL = '${sql}' is operating data on table with authority = '${denyTable}' that do not exist in whiteList`)
}
tableList(sql) {

@@ -17,0 +40,0 @@ const astInfo = this.parse(sql)

2

package.json
{
"name": "node-sql-parser",
"version": "0.0.5",
"version": "0.0.6",
"description": "simple node sql parser",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -35,3 +35,3 @@ # GanJiang SQL Parser

- get the table list the sql visit
- get the table list that the sql visited
- the format is **{type}::{dbName}::{tableName}** // type could be select, update, delete or insert

@@ -47,2 +47,12 @@

### Check the SQL with Authority List
```javascript
const { Parser } = require('node-sql-parser');
const parser = new Parser();
const sql = 'UPDATE a SET id = 1 WHERE name IN (SELECT name FROM b)'
const whiteList = ['(select|update)::(.*)::(a|b)'] // array that contain multiple authorities
parser.whiteListCheck(sql, whiteList) // if check failed, an error would be thrown with relevant error message, if passed it would return undefined
```
### Convert AST back to SQL

@@ -49,0 +59,0 @@

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