Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

There's an invisible-to-the eye unicode character in the string "owned," if you copy and paste the text from the website.

JSON is fine with these characters, but JavaScript is not.

For plain-jane JSON this is usually fine, since you're not just evaluating the JSON as JavaScript, but are running the returned data through a JSON parser. A properly-designed JSON parser will escape any JSON-valid-but-JavaScript-invalid characters.

JSONP, however, works differently and will use use the JavaScript parser. Womp womp.

The blog post also lists two other cases, although the first case -- parsing JSON using eval -- is both insecure and incorrect. I haven't seen people do that in ages and ages.



That makes sense. I was confused because I was also getting the error when I typed the line into the interpreter by hand. The issue being that I forgot to assign it to a variable (facepalm). Thanks for the explanation.


Just an fyi, jQuery's core JSON parser actually uses eval (well, new Function(), which is almost the same, but with scope protection).

https://github.com/jquery/jquery/blob/master/src/core.js#L52...


Looks like someone should send a pull request then.


To be fair, it does escape characters and verify with a regex that the data is actually JSON before eval-ing it.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: