Skip to content

Open Redirect

What does this mean ?

When an application combines user-controllable data into the target of a redirection in an unsafe manner, an open redirection vulnerability occurs. Within the program, an attacker can create a URL that redirects to an arbitrary external website. This behavior can be used to aid phishing attacks against application users.

What can happen ?

The consequences can be wide-ranging, ranging from data theft and credential theft to redirection to malicious websites with attacker-controlled content, which can result in XSS attacks in some circumstances. So, while an open redirection may appear to be harmless at first, if it is exploitable, the consequences can be serious.


  • By inspecting the URL supplied to the redirect method, you may avoid redirects to other domains.
  • Ensure that all redirect URLs are relative routes, meaning that they begin with a single / character.

Sample Code

Vulnerable :

string url = request.QueryString["url"];

Non Vulnerable :


Vulnerable :


Non Vulnerable :


Vulnerable :

$redirect_url = $_GET['url'];
header("Location: " . $redirect_url);

Non Vulnerable :

/* Redirect browser */
/* Exit to prevent the rest of the code from executing */

Non Vulnerable :'/login', (req, res) => {
    const {username, password} = req.body;
    if (username === 'john' && password === '789') {
        req.session.isLoggedIn = true;
    } else {
        res.render('login', {error: 'Username or password is incorrect'});

Vulnerable :

document.location = document.location.hash.slice(1);

Non Vulnerable :

const isValidUrl = (url) => {
    return url.startsWith("") ? true : false

if(isValidUrl(document.location.hash.slice(1))) {
    document.location = document.location.hash.slice(1);