Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nodejs express request headers - get the referrer, etc.

I get a post form a payment gateway https to verify a payment etc. I need to verify that the post was infact from the domain.

Im trying to verify that the referrer is from a certain list of domains but in my req.headers I dont see a referrer|referer options:

{ 'x-real-ip': '123.34.45.176',
  'x-forwarded-for': '123.34.45.176',
  host: 'my.foo.com',
  'x-nginx-proxy': 'true',
  connection: 'close',
  'user-agent': 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)',
  accept: '*/*',
  'content-length': '441',
  'content-type': 'application/x-www-form-urlencoded' }

Why is my headers empty of those fields such as referer, origin etc ?

This is inside a post:

app.post('/payment/notify/', function(req, res){
   req.headers
})
like image 388
Harry Avatar asked Apr 05 '13 07:04

Harry


1 Answers

Not all requests have a referer header.

If the last page a browser was on is a secure server (https) then it does not transmit a referer to you.

Also, if your user types your address into their address bar you don't get a referer as well.

like image 66
Daniel Avatar answered Oct 27 '22 09:10

Daniel