Code RoomOpen redirect via protocol-relative URL
MediumPrep Room Coding #1878

Open redirect via protocol-relative URL

Code reviewCode quality & reviewMid–Senior~20 min

Review this post-login redirect handler.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.

0:00 of about 20 min
Mark a line and say what kind of problem it is.0 findings
1app.post('/login', async (req, res) => {
2 const ok = await authenticate(req.body.user, req.body.pass);
3 if (!ok) return res.status(401).send('bad creds');
4 const next = req.query.next || '/';
5 // Only allow redirects that start with a slash, to stay on our site
6 if (next.startsWith('/')) {
7 return res.redirect(next);
8 }
9 return res.redirect('/');
10});
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.