Skip to content

Commit 7a3891a

Browse files
authored
Merge pull request #8 from octodemo/copilot/apply-autofixes-939
Add type validation for search query parameter
2 parents 918b9c9 + 4f02e04 commit 7a3891a

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

routes/search.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ class ErrorWithParent extends Error {
1919
export function searchProducts () {
2020
return (req: Request, res: Response, next: NextFunction) => {
2121
let criteria: any = req.query.q === 'undefined' ? '' : req.query.q ?? ''
22+
if (typeof criteria !== 'string') {
23+
res.status(400).send('Bad request')
24+
return
25+
}
2226
criteria = (criteria.length <= 200) ? criteria : criteria.substring(0, 200)
2327
models.sequelize.query(`SELECT * FROM Products WHERE ((name LIKE '%${criteria}%' OR description LIKE '%${criteria}%') AND deletedAt IS NULL) ORDER BY name`) // vuln-code-snippet vuln-line unionSqlInjectionChallenge dbSchemaChallenge
2428
.then(([products]: any) => {

0 commit comments

Comments
 (0)