r/programming • • Feb 25 '21

An Exploration of JSON Interoperability Vulnerabilities

https://labs.bishopfox.com/tech-blog/an-exploration-of-json-interoperability-vulnerabilities
128 Upvotes

39 comments sorted by

View all comments

Show parent comments

-3

u/caleeky Feb 25 '21 edited Feb 26 '21

Depends what you mean by JSON. That's the crux of the issue. It's a format that's a side effect of junior devs trying to use interpreted code as a data format and then trying to clean up the mess and pretend it was all a plan.

edit: thanks /u/masklinn for offering the explanation :)

6

u/SwiftOneSpeaks Feb 26 '21

Do you...know the history of JSON at all? Because this is not it.

3

u/binford2k Feb 26 '21

I mean, they’re not entirely wrong. The first JSON parser was eval()….

2

u/SwiftOneSpeaks Feb 26 '21

My memories may fail me, but this feels wrong. Crockford defined the spec, and it specifically didn't match JS. SOME parsers may have used eval(), heck Crockford's first library may have used eval(), but that's not the same as BEING eval().

3

u/masklinn Feb 26 '21 edited Feb 26 '21

it specifically didn't match JS.

That was not intentional and the incompatibility is in an edge case: two “line terminator” code points were treated as thus in JS tokenisation (thus invalid in literal form), while they were not in JSON.

In fact Crockford claims that he discovered it, not invented it. And that he was not even the first discoverer of the idea. And specifically calls it a subset of JS in multiple talks. That was always the intention.

This has since been fixed, by not treating these two code points as line terminator in JS either. In recent browsers JavaScript should be a strict superset of json, which was the intent all along. That you could eval() a json string was rather the point before bat I’ve support appeared, even more so as this long predates advanced JS JITs so json parsers in JavaScript were really slow even compared to all the unnecessary work of eval.