Spoof Origin header in Node.js

▼魔方 西西 提交于 2019-12-13 12:15:51

问题


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.


回答1:


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 );


来源:https://stackoverflow.com/questions/18135508/spoof-origin-header-in-node-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!