Skip to content

Commit f8710b1

Browse files
committed
Handle URL decoding errors in morgan logging middleware
Closes #915
1 parent ceb934f commit f8710b1

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

server/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,13 @@ app.get(['/img/*', '/favicons/*'], (_req, res) => {
8888
return res.status(404).send('Not found')
8989
})
9090

91-
morgan.token('url', (req) => decodeURIComponent(req.url ?? ''))
91+
morgan.token('url', (req) => {
92+
try {
93+
return decodeURIComponent(req.url ?? '')
94+
} catch {
95+
return req.url ?? ''
96+
}
97+
})
9298
app.use(
9399
morgan('tiny', {
94100
skip: (req, res) =>

0 commit comments

Comments
 (0)