Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to manually set REFERER header in Javascript?

Tags:

javascript

I want to set Referer header of my webpage. Currently it displays "xyz" and I want to set it to "abc".

Viewed referer using javascript:alert(document.referer)

like image 245
Abhinav Garg Avatar asked Mar 06 '12 09:03

Abhinav Garg


People also ask

Can you set Referer header?

You cannot set Referer header manually but you can use location. href to set the referer header to the link used in href but it will cause reloading of the page.

What is Referer header in HTTP request?

The Referer HTTP request header contains an absolute or partial address of the page that makes the request. The Referer header allows a server to identify a page where people are visiting it from. This data can be used for analytics, logging, optimized caching, and more.

How do you validate the value of a Referer header?

To help mitigate CSRF attacks, you can configure WebSEAL to validate the referer header in incoming HTTP requests. WebSEAL compares this referer header with a list of configured allowed-referers to determine whether the request is valid. Referrer validation affects the following WebSEAL management pages: /pkmslogout.

How do I change referrer policy strict origin when cross origin?

You can already try out the change starting from Chrome 81: visit chrome://flags/#reduced-referrer-granularity in Chrome and enable the flag. When this flag is enabled, all websites without a policy will use the new strict-origin-when-cross-origin default. Enabling the flag.


1 Answers

You can use Object.defineProperty on the document object for the referrer property:

Object.defineProperty(document, "referrer", {get : function(){ return "my new referrer"; }}); 

Unfortunately this will not work on any version of safari <=5, Firefox < 4, Chrome < 5 and Internet Explorer < 9 as it doesn't allow defineProperty to be used on dom objects.

like image 51
Jason Fertel Avatar answered Sep 19 '22 00:09

Jason Fertel