最近我读了一些关于'JSON劫持'的文章,其中一些是在这里.
所以,我尝试在我的浏览器,Chrome 17(dev),Firefox 8和IE8上进行以下操作.
但我无法对(文字)JSON数据做任何事情.
"JSON劫持"问题是否都在现代浏览器上解决了?或者我该如何重现它?
说我有以下代码:
var secrets;
Array = function() {
secrets = this;
};
Run Code Online (Sandbox Code Playgroud)
上面的示例的作者说,代码正在重新定义Array构造函数.首先,我不确定所指的this是什么.任何人都可以建议吗?
第二:以下代码是否相同?
var secrets;
function Array() {
secrets = this;
}
Run Code Online (Sandbox Code Playgroud)
顺便提一下,上面的代码来自以下关于Json漏洞的文章:请参阅此处
有没有任何实质性的理由为什么修改Array.push()返回推送的对象而不是新数组的长度可能是一个坏主意?
我不知道这是否已经提出或被问过; Google搜索仅返回了与当前功能相关的大量问题Array.push().
以下是此功能的示例实现,请随时更正:
;(function() {
var _push = Array.prototype.push;
Array.prototype.push = function() {
return this[_push.apply(this, arguments) - 1];
}
}());
Run Code Online (Sandbox Code Playgroud)
然后你就可以做这样的事情:
var someArray = [],
value = "hello world";
function someFunction(value, obj) {
obj["someKey"] = value;
}
someFunction(value, someArray.push({}));
Run Code Online (Sandbox Code Playgroud)
例如,someFunction修改传入的对象作为第二个参数.现在的内容someArray是[{"someKey": "hello world"}].
这种方法有什么缺点吗?