Skip to content

Commit 68a08a3

Browse files
committed
fix: handle invalid json in openapi query params gracefully
1 parent 5378d51 commit 68a08a3

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

packages/server/src/openapi/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,11 @@ export async function handleRequest({
138138
if (method !== 'GET') {
139139
return { status: 400, body: { message: 'invalid request method, only GET is supported' } };
140140
}
141-
args = query?.q ? unmarshal(query.q as string) : {};
141+
try {
142+
args = query?.q ? unmarshal(query.q as string) : {};
143+
} catch {
144+
return { status: 400, body: { message: 'query param must contain valid JSON' } };
145+
}
142146
break;
143147

144148
case 'update':
@@ -158,7 +162,11 @@ export async function handleRequest({
158162
if (method !== 'DELETE') {
159163
return { status: 400, body: { message: 'invalid request method, only DELETE is supported' } };
160164
}
161-
args = query?.q ? unmarshal(query.q as string) : {};
165+
try {
166+
args = query?.q ? unmarshal(query.q as string) : {};
167+
} catch {
168+
return { status: 400, body: { message: 'query param must contain valid JSON' } };
169+
}
162170
break;
163171

164172
default:

0 commit comments

Comments
 (0)