简体   繁体   English

JSON Hijacking在现代浏览器中仍然是一个问题吗?

[英]Is JSON Hijacking still an issue in modern browsers?

I am using Backbone.js and the Tornado web server. 我正在使用Backbone.js和Tornado Web服务器。 The standard behavior for receiving collection data in Backbone is to send as a JSON Array. 在Backbone中接收集合数据的标准行为是作为JSON数组发送。

On the other hand, Tornado's standard behavior is to not allow JSON Array's due to the following vulnerability: 另一方面,由于以下漏洞,Tornado的标准行为是不允许使用JSON Array:

http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx

A related one is: http://haacked.com/archive/2009/06/25/json-hijacking.aspx 相关的一个是: http//haacked.com/archive/2009/06/25/json-hijacking.aspx

It feels more natural for me to not have to wrap up my JSON in an object when it really is a list of objects. 当我真的是一个对象列表时,我不必在对象中包装我的JSON。

I was unable to reproduce these attacks in modern browsers (ie current Chrome, Firefox, Safari, and IE9). 我无法在现代浏览器中重现这些攻击(即当前的Chrome,Firefox,Safari和IE9)。 At the same time I was unable to confirm anywhere that modern browsers had addressed these issues. 与此同时,我无法确认现代浏览器解决这些问题的任何地方。

To ensure that I am mislead neither by any possible poor programming-skills nor poor googling-skills: 为了确保我既没有任何可能的糟糕的编程技能,也没有糟糕的谷歌搜索技能:

Are these JSON Hijacking attacks still an issue today in modern browsers? 在现代浏览器中,这些JSON劫持攻击现在仍然是一个问题吗?

(Note: Sorry for the possible duplicate to: Is it possible to do 'JSON hijacking' on modern browser? but since the accepted answer does not seem to answer the question - I thought it was time to ask it again and get some clearer explanations.) (注意:很抱歉可能重复: 在现代浏览器上可以进行'JSON劫持'吗?但由于接受的答案似乎没有回答这个问题 - 我认为现在是时候再问一遍并得到一些更明确的解释。)

No, it is no longer possible to capture values passed to the [] or {} constructors in Firefox 21, Chrome 27, or IE 10. Here's a little test page, based on the main attacks described in http://www.thespanner.co.uk/2011/05/30/json-hijacking/ : 不,不再可能捕获传递给Firefox 21,Chrome 27或IE 10中的[]{}构造函数的值。这是一个小测试页面,基于http://www.thespanner中描述的主要攻击.co.uk / 2011/05/30 / json-hijacking /

( http://jsfiddle.net/ph3Uv/2/ ) http://jsfiddle.net/ph3Uv/2/

 var capture = function() { var ta = document.querySelector('textarea') ta.innerHTML = ''; ta.appendChild(document.createTextNode("Captured: "+JSON.stringify(arguments))); return arguments; } var original = Array; var toggle = document.body.querySelector('input[type="checkbox"]'); var toggleCapture = function() { var isOn = toggle.checked; window.Array = isOn ? capture : original; if (isOn) { Object.defineProperty(Object.prototype, 'foo', {set: capture}); } else { delete Object.prototype.foo; } }; toggle.addEventListener('click', toggleCapture); toggleCapture(); [].forEach.call(document.body.querySelectorAll('input[type="button"]'), function(el) { el.addEventListener('click', function() { document.querySelector('textarea').innerHTML = 'Safe.'; eval(this.value); }); }); 
 <div><label><input type="checkbox" checked="checked"> Capture</label></div> <div><input type="button" value="[1, 2]" /> <input type="button" value="Array(1, 2);" /> <input type="button" value="{foo: 'bar'}" /> <input type="button" value="({}).foo = 'bar';" /></div> <div><textarea></textarea></div> 

It overrides window.Array and adds a setter to Object.prototype.foo and tests initializing arrays and objects via the short and long forms. 它覆盖window.Array并增加了一个设置器, Object.prototype.foo和试验通过短和长形式初始化数组和对象。

The ES4 spec , in section 1.5, "requires the global, standard bindings of Object and Array to be used to construct new objects for object and array initializers" and notes in Implementation Precedent that "Internet Explorer 6, Opera 9.20, and Safari 3 do not respect either local or global rebindings of Object and Array, but use the original Object and Array constructors." 第1.5节中的ES4规范 “需要使用Object和Array的全局标准绑定来构造对象和数组初始化器的新对象”,并在实现先例中指出“Internet Explorer 6,Opera 9.20和Safari 3”不尊重Object和Array的本地或全局重新绑定,而是使用原始的Object和Array构造函数。“ This is retained in ES5, section 11.1.4 . 这在第5.1节第11.1.4节中保留。

Allen Wirfs-Brock explained that ES5 also specifies that object initialization should not trigger setters, as it uses DefineOwnProperty. Allen Wirfs-Brock解释说ES5还指定对象初始化不应该触发setter,因为它使用DefineOwnProperty。 MDN: Working with Objects notes that "Starting in JavaScript 1.8.1, setters are no longer called when setting properties in object and array initializers." MDN:使用对象注意到“从JavaScript 1.8.1开始,在对象和数组初始值设定项中设置属性时不再调用setter。” This was addressed in V8 issue 1015 . 这在V8问题1015中得到了解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM