What is the most reliable way to hide / spoof the referrer in JavaScript?

前端 未结 10 1639
挽巷
挽巷 2020-11-28 03:13

Normally, the referrer is traceable through:

  • JavaScript\'s document.referrer
  • The request headers, e.g. PHP\'s $_SERVER[\'HTTP_REFER
10条回答
  •  一向
    一向 (楼主)
    2020-11-28 03:25

    You could use the new Referrer Policy standard draft to prevent that the referer header is sent to the request origin. Example:

    
    

    Although Chrome and Firefox have already implemented a draft version of the Referrer Policy, you should be careful with it because for example Chrome expects no-referrer instead of none (and I have also seen never somewhere). I don't know the behaviour if you just add three separate meta tags, but in case that does not work you could still just implement a short script which iterates over all three values and checks if the value was really set after setting the attribute/property of the meta tag.

    This meta tag applies to all requests on the current page (ajax, images, scripts, other resources...) and navigation to another page.

提交回复
热议问题