I use Javascript to redirect to a file called handle.php
which create a session for a user then redirect (this time with header()
function of php) to the main page (where the user is then identified).
Here is the Javascript:
window.location.replace("handle.php");
In order, to prevent a hacker to execute directly handle.php
I use this configuration in .htaccess:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost.*$ [NC]
RewriteRule ^handle.php$ - [F]
But this code does not prevent the hacker to replay the request to handle.php
and to add Referer: http://localhost
in the headers, allowing him to execute handle.php
.
So, I need a way to allow the execution of handle.php
only when it's in the proper workflow of my application, i.e when it comes from a redirection that is written in my code.
Thank you