Async auth middleware returns before completing — request proceeds unauthenticated.
Authentication middleware that doesn’t call `next()` or doesn’t return early leaves the request unauthenticated. In Express, if the auth check is async and the route handler fires before the middleware resolves, the request proceeds as if unauthenticated. Next.js middleware’s early-return behavior (CVE-2025-29927) caused `req.auth` to be `undefined` on certain requests, bypassing auth on affected routes.
// VULNERABLE — missing return/next()
app.use(async (req, res, next) => {
const token = req.headers.authorization;
if (!token) {
// forgot to return/next() — request continues without auth
return res.status(401).send('Unauthorized');
}
req.user = await verifyToken(token);
// forgot next() — route handler never fires
next();
});
// FIXED — explicit return on all paths
app.use(async (req, res, next) => {
const token = req.headers.authorization;
if (!token) {
return res.status(401).send('Unauthorized');
}
try {
req.user = await verifyToken(token);
next();
} catch (e) {
return res.status(401).send('Unauthorized');
}
});
pool.query(`SELECT * FROM users WHERE id = ${req.params.id}`)