Skip to content

Commit e94ef0f

Browse files
committed
fix validation in backend
1 parent 943f3e5 commit e94ef0f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

routes/redirect.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ module.exports = Router()
99
res.set('Cache-Control', `public, max-age=${cacheAge}`)
1010
res.redirect(301, process.env.HOMEPAGE)
1111
})
12-
.get(`/:hash(${schema.Link.properties.hash.pattern})`, async (req, res) => {
12+
.get(`/:hash`, async (req, res) => {
13+
// Just do the validation in the route; ^pattern$ doesn't work well with express routes.
1314
if (
1415
req.params.hash.length < schema.Link.properties.hash.minLength ||
15-
req.params.hash.length > schema.Link.properties.hash.maxLength
16+
req.params.hash.length > schema.Link.properties.hash.maxLength ||
17+
!new RegExp(schema.Link.properties.hash.pattern, 'u').test(req.params)
1618
)
1719
return res.sendStatus(404)
1820

0 commit comments

Comments
 (0)