Skip to content

Commit 269c4df

Browse files
committed
fix: whiteList should be exact match
1 parent 7bec7f1 commit 269c4df

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Parser {
4646
for (const authority of authorityList) {
4747
let hasCorrespondingAuthority = false
4848
for (const whiteAuthority of whiteList) {
49-
const regex = new RegExp(whiteAuthority, 'i')
49+
const regex = new RegExp(`^${whiteAuthority}$`, 'i')
5050
if (regex.test(authority)) {
5151
hasCorrespondingAuthority = true
5252
break

test/select.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,12 @@ describe('select', () => {
12441244
const fun = parser.whiteListCheck.bind(parser, sql, whiteList, mode)
12451245
expect(fun).to.throw(`authority = 'select::b::name' is required in ${mode.type} whiteList to execute SQL = '${sql}'`)
12461246
})
1247+
it('should fail for prefix check', () => {
1248+
const sql = 'SELECT u.usernameXXX FROM user u;'
1249+
const whiteList = ['select::user::username']
1250+
const fun = parser.whiteListCheck.bind(parser, sql, whiteList, { ...mode, database: 'postgresql' })
1251+
expect(fun).to.throw(`authority = 'select::user::usernameXXX' is required in ${mode.type} whiteList to execute SQL = '${sql}'`)
1252+
})
12471253
it('should fail the complex sql and regex check', () => {
12481254
const sql = 'UPDATE a SET id = 1 WHERE name IN (SELECT name FROM b)'
12491255
const whiteList = ['select::(.*)::(id|name)']

0 commit comments

Comments
 (0)