I have created a vulnerable Code for Open redirect vulnerability, but now I want to secure it. But unfortunately, I didn't find on google so decide to come here.,
So, this is my html file code, in which I provide the next parameter.
<html>
<form action="/demo/userin2.php?next=http://somedomain.com" method="POST"></tr>
<tr><center><b><td>Username</b> <td><input type="text" name="username" value=""></td><br></tr>
<tr><b><td>Password </b> <td><input type="password" name="password" value=""></td><br></tr>
</td>
</tbody>
</table>
<input type="submit" name="go" value="go"></fieldset>
</center>
</form>
</html>
Now my userin2.php file is below:-
<?php
session_start();
?>
<html>
<style>body {
background-color: #C0C0C0;
}
</style>
<center><img src="/dashboard/demo.jpg" width="500" height="100"></center>
<?php
$conn=mysqli_connect('localhost', 'sqltest', 'sqltest', 'sqltest') or die ("failed to connect to db". mysql_
$query = "SELECT Username, Password, userid FROM userinfo WHERE username=? AND password=?";
// MY PHP CODE RELATED TO DATABASE QUERY
echo "Good to see you again Mr. ".$Username; // finally we are successfully fetch the row now its time to call its value like this.
}
else{
echo "user not found";
}
?>
**<?php
$redirect = $_GET['next'];
header("Location: " . $redirect);
?>**
</html>
I have highlighted the main part of my PHP file.
So that's all I have. Now How do I get secure it?
I hope I successfully explain my question NOW.