Skip to content

Commit 054e801

Browse files
committed
test: add sql.lit(string) test case following #1754.
1 parent e63ceb9 commit 054e801

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

test/node/src/sql-injection.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,21 @@ for (const dialect of DIALECTS) {
105105
await ctx.db.executeQuery(query)
106106
await assertDidNotDropTable(ctx, 'person')
107107
})
108+
109+
it('should not allow SQL injection via backslash escape in string literals', async () => {
110+
const injection = `\\'; drop table ${identifierWrapper}person${identifierWrapper}; -- `
111+
112+
const query = ctx.db
113+
.selectFrom('person')
114+
.where('first_name', '=', sql.lit(injection))
115+
.selectAll()
116+
117+
expect(query.compile().sql).to.equal(
118+
`select * from ${identifierWrapper}person${identifierWrapper} where ${identifierWrapper}first_name${identifierWrapper} = '\\\\''; drop table ${identifierWrapper}person${identifierWrapper}; -- '`,
119+
)
120+
await ctx.db.executeQuery(query)
121+
await assertDidNotDropTable(ctx, 'person')
122+
})
108123
}
109124
})
110125
}

0 commit comments

Comments
 (0)