【问题标题】:cross domain origin security in NWJSNWJS 中的跨域源安全性
【发布时间】:2017-05-06 19:18:04
【问题描述】:

我正在尝试连接到我的 ISP 调制解调器以获取一些隐藏数据,因此我创建了一个包含一些 javascript 的 html 页面。我使用 xmlhttprequest 登录该页面,它可以工作,但我无法获取发出我的请求和获取那些隐藏数据所必需的 cookie。 我用 NWJS 读到我可以绕过 CORS 限制......但我不知道我做错了什么...... 我实际上正在使用最新的 SDK NWJS 0.22.1

这是我的 package.json:

{
 "main": "index.html",
 "name": "Liveboxinfos",
 "description": "test app",
 "version": "1.0.0",
 "nodejs": true,
 "node-remote": "http://192.168.1.1/*",
 "permissions": ["*://*/*"],
 "chromium-args": "--disable-web-security --user-data-dir",
 "window": {
 "title": "node-webkit demo",
 "icon": "link.png",
 "toolbar": true,
 "frame": true,
 "width": 1200,
 "height": 600,
 "position": "center",
 "min_width": 600,
 "min_height": 400,
 "max_width": 1200,
 "max_height": 600
 }
}

这是我的 index.html 的 javascript 部分:

var ip = "192.168.1.1";
var password = "password";

var HTTP = new XMLHttpRequest();
var url = "http://" + ip;
var params = '{"service":"sah.Device.Information","method":"createContext","parameters":{"applicationName":"so_sdkut","username":"admin","password":"' + password + '"}}';

HTTP.open("POST", url, false);
HTTP.setRequestHeader("Content-Type", "application/x-sah-ws-4-call+json");
HTTP.setRequestHeader("Authorization", "X-Sah-Login");
HTTP.withCredentials = true;
HTTP.onreadystatechange = function() {//Call a function when the state changes.
    if(HTTP.readyState == 4 && HTTP.status == 200) {
        //alert(HTTP.responseText);
    }
}

HTTP.send(params);

const regex = /contextID":"(.*?)"/;
const Received = HTTP.responseText;
const cookie = HTTP.getResponseHeader("set-cookie");

这是我的测试应用,你可以看到 cookie = null...

【问题讨论】:

    标签: javascript node.js cross-domain nwjs


    【解决方案1】:

    这不是 CORS。基本上,您无法使用 XHR 从其他域获取 cookie。

    使用 NWJS,您可以简单地使用 http.request/http.get 来获取 cookie。

    @见https://nodejs.org/api/http.html

    【讨论】:

    • 如果这是真的,那么这里有一些我不明白的地方:docs.nwjs.io/en/v0.13.0/For%20Users/Advanced/… 他们说:节点框架比普通框架具有以下额外功能: •绕过所有安全限制,例如沙盒,同源策略等。例如,您可以跨源 XHR 到任何远程站点
    猜你喜欢
    • 2012-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-29
    • 2011-10-19
    • 2016-11-04
    • 2010-10-25
    • 2010-09-30
    相关资源
    最近更新 更多