16 ms·
> Contrived example: say Google has a URL like mail.google.com/json?action=inbox which returns the first 50 messages of your inbox in JSON format. Evil websites
by rayiner 8y ago
> Contrived example: say Google has a URL like mail.google.com/json?action=inbox which returns the first 50 messages of your inbox in JSON format. Evil websites on other domains can't make AJAX requests to get this data due to the same-origin policy, but they can include the URL via a <script> tag. The URL is visited with your cookies, and by overriding the global array constructor or accessor methods they can have a method called whenever an object (array or hash) attribute is set, allowing them to read the JSON content.
What an absolutely ridiculous language and platform we decided to base the whole web on.
- jobigoud 8y agoIf they are that motivated wouldn't they catch the trick soon enough and remove it from the response?
- Jare 8y agoThe idea is that your browser is running their site, and their site is trying to be malicious and steal your data for a remote site. Your data there can only be accessed with your cookies/auth, so they can't just do it by themselves, they need your computer/browser. If they try to request the json via XHR, CORS will deny it. If they try to read it using a <script> tag, they can't access the response before the response runs as a script and hangs at the infinite loop.
- posterboy 8y agoThe catch is that attackers can redefine accessor methods globaly, because those are part of the object system, and do run modified on load, but they cannot redefine "while", which is a built-in, one of the few reserved language key words. At least I hope they can't. Of course that does depend on implementation details.
- robocat 8y ago> What an absolutely ridiculous language and platform we decided to base the whole web on. JavaScript is used for its virtues, and its flaws can be mitigated. Other languages might not have those flaws, but they have other downsides. It's not like English is the best choice for language either!
- gowld 8y agoJavaScript (and the way browsers use JavaScript poorly) is used because Brendan Eich went on a bender one weekend 20 years ago, and then path dependence. The virtues do not outweigh the vices, except for the sunk cost of all the infrastructure already built. It's not that different from English, in a sense.
- BrendanEich 8y agoA ten day bender!
- archgoon 8y agoThis isn't really a language issue. This is strictly at the level of browsers having a very complicated and ad-hoc concept of permissions deciding when a page should be allowed to make requests to, and to which, servers. We could have a richer permission model api exposed to whatever language we were using (so only certain white listed scripts tags would have the ability to make requests for example); but we don't. In any case, this is going to be at the DOM level, which isn't really part of javascript. Pages could have more control (via a header manifest or something) over tracking and permissioning based on where particular scripts come from; but that's not the model we went with. All scripts get put into a single executor and namespace. Now, this isn't an irrevocable choice, but a browser still has to support existing pages that would still be vulnerable to fun XSS attacks.
- eridius 8y agoIt is a language issue, because the security hole is the fact that you can redefine the Array constructor or accessor methods. On a similar note, it's also crazy that you can't just use `foo instanceof Array` to figure out if something is an Array because it could be an Array from a different namespace, instead you need `Array.isArray(foo)`.
- deleted 8y ago[deleted]
- tptacek 8y agoThat's not really a security hole except in the weird browser context of having to execute content-controlled code --- and then only due to the same-origin policy. Being able to redefine anything in the system is normally a virtue for a language.
- rsj_hn 8y agoBeing able to redefine everything is never a virtue as it introduces non-locality. You can't reason about what a particular piece of code is doing without understanding the full data flow that got you to this point and any re-definitions that might have happened along the way (with one re-definition overwriting the previous one). For example, look at the following code: function test(a) { if (a > 1) { console.log("bigger"); return; } else if (a <= 1) { console.log("smaller"); return; } else { console.log("Why is this happening to me?!"); } } var a = { x : 1, valueOf: function() { this.x -= 1; return this.x==0?1:2; } } test(a);
- jimbo1qaz 8y agoThe easy and obvious solution to info leakage and XSRF is for the web standards committee to ban third party cookies from being sent in cross-origin requests. But that would break Facebook Like buttons from tracking your browsing activity...
- tptacek 8y agoIt's probably not reasonable to assert that tracking is the reason we have cross-origin requests; that feature was avidly requested by developers across the spectrum for many years, and the fact of JSONP is a pretty good illustration of just how badly people wanted it.
- pcwalton 8y agoWell, JS was changed (backwards incompatibly!) in order to eliminate the problem. So yeah, it was bad, but it was arguably just a bug that got fixed.
- erikpukinskis 8y agoPlease don't post low effort comments like this on HN.
- martin_a 8y agoJust because you don't understand sarcasm and its implications doesn't mean that a comment is "low effort".
- erikpukinskis 8y agoThere's no need to insult my intelligence.