Skip to content

Commit 123b4bf

Browse files
committed
Handle invalid URL requests with error response
1 parent 7390231 commit 123b4bf

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

index.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,19 @@ if (useHttp) {
285285
return
286286
}
287287

288-
const url = new URL(req.url!, `http://localhost:${port}`)
288+
let url: URL
289+
try {
290+
url = new URL(req.url!, `http://localhost:${port}`)
291+
} catch (error) {
292+
logger.warn(`Invalid URL in request: ${req.url} - ${error}`)
293+
res.writeHead(400, { 'Content-Type': 'application/json' })
294+
res.end(JSON.stringify({
295+
jsonrpc: '2.0',
296+
error: { code: -32000, message: 'Bad Request: Invalid URL' },
297+
id: null
298+
}))
299+
return
300+
}
289301

290302
// Health check endpoint for K8s/Docker
291303
if (url.pathname === '/health') {

0 commit comments

Comments
 (0)