Am trying to redirect user to requested_page
after login, After googling i tried this code
link to login page
echo "<a href='/login.php?ref=". urlencode($_SERVER['REQUEST_URI']) ."'>login</a>";
and in login.php
if ($_GET['ref'] != '') {
$url = $_GET['ref'];
} else {
$url = "/";
}
if ($user->login($username, $password)) {
$_SESSION['username'] = $username;
header("location:http://" . $_SERVER['HTTP_HOST'].$url);
exit();
}
Above method works fine, But it is vulnerable to XSS
login.php?ref=<script>alert(%27Malicious%20content%27)</script>
so i added htmlspecialchars()
like this
if ($_GET['ref'] != '') {
$url = htmlspecialchars($_GET['ref']);
} else {
$url = "/";
}
but it is not redirected, rather it shows 404 error
any help how do i protect from XSS attack
Log in with social media account or email
www.safebrowser.tk ` and nothing to do with the link you have in the question. – Quentin Jan 30 '20 at 10:20`. You have to fix the code where it is vulnerable.
– Quentin Jan 30 '20 at 10:23Log in with social media account or email
= $_SERVER['HTTP_HOST'].$url ?>` – sanoj lawrence Jan 30 '20 at 10:26` then the XSS vulnerability is gone and you don't need to do anything more.
– Quentin Jan 30 '20 at 10:28