Skip to content

Commit

Permalink
check for array query parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryHengZJ committed Dec 11, 2023
1 parent 254a77c commit bd4fb2c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/server/src/utils/XSS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@ export function sanitizeMiddleware(req: Request, res: Response, next: NextFuncti
const decodedURI = decodeURI(req.url)
req.url = sanitizeHtml(decodedURI)
for (let p in req.query) {
req.query[p] = sanitizeHtml(req.query[p] as string)
if (Array.isArray(req.query[p])) {
const sanitizedQ = []
for (const q of req.query[p] as string[]) {
sanitizedQ.push(sanitizeHtml(q))
}
req.query[p] = sanitizedQ
} else {
req.query[p] = sanitizeHtml(req.query[p] as string)
}
}

next()
}

0 comments on commit bd4fb2c

Please sign in to comment.