HTTP_REFERER
does not guarantee any safety, it is very easy to overwrite and defraud the origin since it is a header.
The best to do in question to ensure the origin of the form could be using the reCAPTCHA
Also experiment techniques such as protection anti-CSRF (CSRF means Cross-Site Request Forgery), is not 100% efficient, but works better than HTTP_REFERER
, an example of Soen (I just don’t know if md5 is really something necessary)
I think it would be something like:
All pages who receive a request or have a Form or an Ajax must (you can put in a global or a function):
Function GetGUID()
GetGUID = CreateObject("Scriptlet.TypeLib").GUID
End Function
Dim token
' Só atualiza o valor da sessão se não vier de um POST
' com `<input name=csrftoken>`
If Request.Form("csrftoken") = "" Then
token = md5(GetGUID())
Session("token")=token
Session("token_time")=Time()
End If
On the page that receives the POST/request should have this:
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
' Compara o Form com a sessão
If Request.Form("csrftoken") = Session("token") Then
' Executa o seu código aqui !!!
End If
End If
In the form you should also add the Session("token")
<form method="post" action="pagina.asp">
<input type="text" name="foo" placeholder="Exemplo">
<input type="submit" value="submit">
<input type="hidden" value="<%= Session("token") %>" name="csrftoken">
</form>
It has been a long time since I work with classic Asp, if you have any typing error are free to fix them
How to Fool Referer and Origin
With Postman or Wget it is easy to fool the site, see just play it on the terminal (be for Linux, although it is possible to install on Windows):
wget
--user-agent="Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0"
--header="Host: seusite.com"
--header="Origin: http://seusite.com"
--header="Referer: http://seusite.com/pasta/formulario.asp"
--header="Connection: keep-alive"
--header="Accept-Language: en-US,en;q=0.5"
--post-data="campo1=foo&campo2=bar"
http://seusite.com/pasta/pagina.asp
Okay, I’ve tricked your system.