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

33

u/headhunglow Feb 25 '21

Finally some real programming content on /r/programming! Great writeup! However, I'm wondering why any JSON parser would support comments?

26

u/evaned Feb 25 '21

Lots of things use JSON for configuration files and other things intended to be hand-written, as I'm sure you've noticed. Tools have been "updated" to support that use, which hugely benefits from comments, to the point of it turning a terrible language for that purpose into one that's usually merely mediocre.

As for why JSON is used there instead of INI or TOML something... well that I think mostly falls into "everything is terrible" category.

13

u/[deleted] Feb 25 '21

I think JSON is better than TOML for configuration purposes except for the fact that it often doesn't support comments and trailing commas (cough package.json) and it isn't clear when it does and when it doesn't. JSON5 solves that problem but isn't as widely supported.

TOML is ok, but it still has more weird quirks and is less obvious than JSON (but way better than YAML).

In particular the [[table]] syntax is very unintuitive, to the point that I still don't understand it. JSON arrays are blindingly obvious.

Another weirdness is that you can put a table in braces, but only if it is all on one line! Another thing JSON got right.

For all its limitations JSON is probably the best thing to come out of JavaScript. It got a lot right.

9

u/evaned Feb 25 '21

I think JSON is better than TOML for configuration purposes except for the fact that it often doesn't support comments and trailing commas (cough package.json) and it isn't clear when it does and when it doesn't. JSON5 solves that problem but isn't as widely supported.

I'd add a couple more: no multi-line literals, it is silent on the representation of numbers and so there's no distinction for example between ints and floats, no hex ints (I'm probably biased here; this is probably much more of a problem when you want program-generated but human-readable interchange). Compared to TOML, TOML also allows you to write numbers like 1_234_567 for 1234567, and that kind of thing always super nice.

From a configuration file perspective, I also think JSON is very syntax-heavy -- the need for commas between items, the quotes you need everywhere, you will basically always need a top-level {} and so your editor probably indents everything in the file which should already tell you that the format is stupid for that use case...

And it also has the advantage of being pretty completely specified, unlike JSON.

In particular the [[table]] syntax is very unintuitive, to the point that I still don't understand it. JSON arrays are blindingly obvious.

I'll grant you that -- but I think this is getting into "most conf files don't need this" territory.

6

u/[deleted] Feb 26 '21

Valid point about top-level {} but I disagree about commas and quoting. They help make it really really unambiguous, unlike YAML for example, and TOML's tables.

Like, you don't really have to learn JSON. If you've done any programming at all it's obvious from a tiny example how it works. That definitely isn't true for YAML or for TOML's table syntax.