Does anyone know what browsers allow you to override the Array constructor? I was under the impression that modern browsers don't.
<script type="text/javascript">
Object.prototype.__defineSetter__('Id', function(obj){alert(obj);});
</script>
<script src="http://example.com/Home/AdminBalances">/*Boom*/</script>
[0]: http://haacked.com/archive/2009/06/25/json-hijacking.aspx/Example http://jsfiddle.net/V53BL
<script>
Object.prototype.__defineSetter__('user', function(obj){alert('Hijacked!');console.log('Hijacked!', obj)});
var trigger = [{"user":{}}];
</script>
<script id='current-user' src="http://my.secretapi.com/users/current"></script>
Where the API returns something like [{'user':{'name':'Joe Bloggs'}}]
(Un)Fortunately (depending on which side of this you're on...) they've plugged the holes?var x = [{"user":"dude"}]; This won't trigger, and this is what the script include tag executes via the response.
x.user = "wow"; This will trigger, however.
However, the while (1); (or similar tricks) is an easy defense-in-depth measure in case browsers regress in this area or new attacks are found.