Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spoof Origin header in Node.js

I have a node.js server running express. I'm trying to write several tests for it in order to confirm standard behavior in the future when someone else may work on it. The server processes the request's header, the referrer and origin fields specifically. Using Jquery's ajax method, I was able to send ajax requests to the server. I found that I was able to set the referrer field. However, I can't seem to set the origin. Is there any way to spoof the origin in node.js?

Edit: For clarification, I'm not running this code through a browser, but from the command line. Normally the ajax call would be run from a webpage, but as I'm writing tests to be run from Mocha, the origin isn't set.

like image 456
Adno Avatar asked Sep 05 '26 02:09

Adno


1 Answers

Due to security reasons, the browser will not allow you to manually set your request origins. To spoof your request origin, you will have to make the request server-side:

var http = require('http');

var opt = {
    host: 'yoursite.com',
    path: '/test',
    headers: { origin: 'http://spoofedorigin.com'}
};

http.get( opt );
like image 100
levi Avatar answered Sep 07 '26 19:09

levi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!