Json/jsonp How To Use For(;;); In The Respose Body
Solution 1:
Ok I think I figured it out. The reason why the for(;;); is there is to prevent cross-domain data requests of certain information. So basically if you have information you are trying to protect you go through a normal Ajax JSON channel and if you are storing data on multiple servers you deal with it on server level.
JSONP requests are actually a remote script inclusion, which means whatever the server outputs is actual Javascript code, so if you have a for(;;);
before your _callbacks_.callback();
the code will be executed on the origin domain on request success. If it's an infinite for loop, it will obviously jam the page.
So the normal implementation method is the following:
- Send a normal Ajax request to a file located on the same server.
- Perform the server level stuff and send requests to external servers via encrypted CURL.
- Add security to the server response(a
for(;;);
orwhile(1);
orthrow(1);
followed by a<prevent eval statements>
string. - Get the response as a text string.
- Remove your security implementations from the string. Convert the string(which is now a "JSON string") to a JS Object/Array etc with a standard JSON parser.
- Do whatever you want to do with the data.
Just thought I should put this out here in case someone else will Google it in the future, as I didn't find proper information by Google-ing. This should help prevent cross domain request forgery.
Post a Comment for "Json/jsonp How To Use For(;;); In The Respose Body"