views:

571

answers:

1

I'm playing firebug with Google Calendar. I happens to find that some XHR request has response like below:

while(1);[['us','bW9yZ2FuLmNoZW5nbW9AZ21haWwuY29t 20090320/20090904 63378122163']]

It looks like a JSON with prefix dead-loop javascript statements.

I'm not sure why Google Calendar has such kind of XHR response. Is there any known AJAX practice about this?

+14  A: 

This is to ensure some other site can't do nasty tricks to try to steal your data. For example, by replacing the array constructor, then including this JSON URL via a <script> tag, a malicious third-party site could steal the data from the JSON response. By putting a while(1); at the start, the script will crash instead.

A same-site request using XHR and a seperate JSON parser, on the other hand, can easily ignore the while(1); prefix.

bdonlan
I suppose the XHR can only be issued to same domain server with authentication. How can "other site" intercept the response?Can you give more details on how "other site" steal our data?
Morgan Cheng
Technically, a "normal" JSON parser should give an error if you have a prefix.
Matthew Crumley
Attackers would just use a plain old `<script>` element, not an XHR.
Laurence Gonsalves