26

While surfing facebook and using the Firebug network debugger I noticed that facebook's AJAX responses all start with an empty for loop.

Example:

for(;;);{...}

Does anyone know why this is done? I assume it's to prevent some sort of XSS attack but I don't totally understand. Thanks!

celticpride
  • 506
  • 1
  • 5
  • 9
  • Looks like it tries to hang the JS engine if the response is eval'd. Probably to make users of the Facebook API use their JSON-parsing library instead of eval? – strager Jun 17 '10 at 01:51
  • 2
    Possible duplicate of [Why does Google prepend while(1); to their JSON responses?](http://stackoverflow.com/questions/2669690/why-does-google-prepend-while1-to-their-json-responses) – gengkev Feb 19 '16 at 02:32

1 Answers1

11

Like google's

while(1);

it done for preventing of including this in <script> with further using the data

zerkms
  • 230,357
  • 57
  • 408
  • 498