Skip to content

Commit 842bcd6

Browse files
committed
fix: remove zod from server bundle
1 parent 5b35124 commit 842bcd6

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

src/runtime/api/query.post.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { eventHandler, getRouterParam, readValidatedBody } from 'h3'
2-
import * as z from 'zod'
1+
import { eventHandler, getRouterParam, readBody } from 'h3'
32
import type { RuntimeConfig } from '@nuxt/content'
43
import loadDatabaseAdapter, { checkAndImportDatabaseIntegrity } from '../internal/database.server'
54
import { assertSafeQuery } from '../internal/security'
65
import { useRuntimeConfig } from '#imports'
76

87
export default eventHandler(async (event) => {
9-
const { sql } = await readValidatedBody(event, z.object({ sql: z.string() }).parse)
8+
const { sql } = await readBody(event)
109
const collection = getRouterParam(event, 'collection')!
1110

1211
assertSafeQuery(sql, collection)

src/runtime/internal/security.ts

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ const SQL_SELECT_REGEX = /^SELECT (.*) FROM (\w+)( WHERE .*)? ORDER BY (["\w,\s]
1212
* @returns True if the query is safe, false otherwise
1313
*/
1414
export function assertSafeQuery(sql: string, collection: string) {
15+
if (!sql) {
16+
throw new Error('Invalid query')
17+
}
18+
1519
const cleanedupQuery = cleanupQuery(sql)
1620

1721
// Query is invalid if the cleaned up query is not the same as the original query (it contains comments)

test/unit/assertSafeQuery.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ describe('decompressSQLDump', () => {
1717
})
1818

1919
const queries = {
20+
'': false,
2021
'SELECT * FROM sqlite_master': false,
2122
'INSERT INTO _test VALUES (\'abc\')': false,
2223
'CREATE TABLE _test (id TEXT PRIMARY KEY)': false,

0 commit comments

Comments
 (0)