Loading...
Loading...
Unvalidated redirect vulnerability allowing phishing attacks through malicious URLs.
1app.get('/login', (req, res) => {2 const { returnUrl } = req.query;34 if (req.session.user) {5 // Redirect to returnUrl after login6 return res.redirect(returnUrl || '/dashboard');7 }89 res.render('login', { returnUrl });10});1112app.post('/login', (req, res) => {13 const { username, password, returnUrl } = req.body;1415 if (validateCredentials(username, password)) {16 req.session.user = username;17 res.redirect(returnUrl || '/dashboard');18 } else {19 res.render('login', { error: 'Invalid credentials' });20 }21});
The vulnerable code blindly redirects to user-controlled URLs, enabling phishing attacks. Attackers craft login links that redirect to fake sites after authentication. The secure version validates returnUrl to only allow relative paths within the application.
Redirect users to attacker site that looks like legitimate login
https://legitimate.com/login?returnUrl=https://evil.com/steal-credsUser logs in successfully then gets redirected to evil.com