Skip to content

Commit 598dd13

Browse files
authored
fix(query): allow uppercase in column names (#3100)
1 parent 549ccc9 commit 598dd13

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/runtime/internal/security.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function assertSafeQuery(sql: string, collection: string) {
3232
if (
3333
columns[0] !== '*'
3434
&& !columns[0].match(SQL_COUNT_REGEX)
35-
&& !columns[0].match(/^"[a-z_]\w+"$/)
35+
&& !columns[0].match(/^"[a-z_]\w+"$/i)
3636
) {
3737
throw new Error('Invalid query')
3838
}
@@ -59,7 +59,7 @@ export function assertSafeQuery(sql: string, collection: string) {
5959

6060
// ORDER BY
6161
const _order = (orderBy + ' ' + order).split(', ')
62-
if (!_order.every(column => column.match(/^("[a-z_]+"|[a-z_]+) (ASC|DESC)$/))) {
62+
if (!_order.every(column => column.match(/^("[a-zA-Z_]+"|[a-zA-Z_]+) (ASC|DESC)$/))) {
6363
throw new Error('Invalid query')
6464
}
6565

test/unit/assertSafeQuery.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ describe('decompressSQLDump', () => {
2626
'SELECT * FROM _content_test ORDER BY id DESC': true,
2727
'SELECT * FROM _content_test ORDER BY id ASC,stem DESC': false,
2828
'SELECT * FROM _content_test ORDER BY id ASC, stem DESC': true,
29+
'SELECT * FROM _content_test ORDER BY id ASC, publishedAt DESC': true,
30+
'SELECT "PublishedAt" FROM _content_test ORDER BY id ASC, PublishedAt DESC': true,
2931
'SELECT * FROM _content_test ORDER BY id DESC -- comment is not allowed': false,
3032
'SELECT * FROM _content_test ORDER BY id DESC; SELECT * FROM _content_test ORDER BY id DESC': false,
3133
'SELECT * FROM _content_test ORDER BY id DESC LIMIT 10': true,

0 commit comments

Comments
 (0)