Skip to content

Comment on Why does Google prepend while(1); to their JSON responses?

Comments

Why not "while(0)"? Then an eval wouldn't do anything.

Because it's not about eval(), as the link you're commenting on explains in detail?

If I'm understanding it correctly, though, prepending while(0) or even if(0) to the JSON would prevent the attack, because the JSON object would not actually be executed. I think they were asking if there was any particular reason to prefer the infinite loop over that.

The answer that comes to mind for me is that having the script hang is a more obvious failure state than simply skipping over the statement, and makes it more immediate that something has gone wrong.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.