Other response checks are good, but not strictly related to your site. So, for example, the referent with the value http://attacker.com/www.example.com/ will pass almost all the checks. And itβs very easy to make such a site and just send a request for cross-domain communication.
There is a reliable and safe way to check if the referent is valid . Of course, the referent can be faked, but the victim of the attacker will send the correct referent.
The trick is in ^ special character. Here is a magical regex:
^https?://(([a-z0-9-]+)\.)*example\.com/
^ - ensures that we are at the beginning
https? - protocol - http or https
(([a-z0-9-]+)\.)* - corresponds to subdomains, as well as to higher levels, if any example\.com - corresponds to the main domain
/ - ensures that the path starts, so the domain name cannot continue
Zaffy source share