News for hackers. Stuff that matters.
Re:HTTP: , FTP:, and Dict:? by im3w1l on Sunday September 22, 2024 @08:27AM (#41616576)
I admire these old protocols that are intentionally built to be usable both by machines and humans. Like the combination of a response code, and a human readable explanation. A help command right in the protocol.

Makes me think it's a shame that making a json based protocol is so much easier to whip up than a textual ebnf-specified protocol.

Like imagine if in python there was some library that you gave an ebnf spec maybe with some extra features similar to regex (named groups?) and you could compile it to a state machine and use it to parse documents, getting a Dict out.

Re:HTTP: , FTP:, and Dict:? by dspillett on Sunday September 22, 2024 @09:47AM (#41617062)
> Makes me think it's a shame that making a json based protocol is so much…

Maybe I'm not the human you are thinking of, being a techie, but I find a well structured JSON response, as long as it isn't overly verbose and is presented in open form rather than minified, to be a good compromise of human readable and easy to digest programmatically.

Re:HTTP: , FTP:, and Dict:? by marcosdumay on Sunday September 22, 2024 @11:12AM (#41617611)
The legibility is probably one of the main reasons JSON got adopted. XML can be made to not look too bad, but in SOAP it must be unreadable, so everybody was looking into fixing this.
Re:HTTP: , FTP:, and Dict:? by xmlmann on Sunday September 22, 2024 @12:59PM (#41618288)
XML has a sweet advantage though. It can be styled in the browser. For example a sitemap that works for Google, OpenAI, &c. and is human readable looking like a web page.

Example:

https://www.wpbeginner.com/sitemap.xml

Re:HTTP: , FTP:, and Dict:? by immibis on Sunday September 22, 2024 @01:14PM (#41618396)
This is fun, but in reality, not all that useful.

Except you can impress other nerds when they "view source" and there's not an HTML tag in sight.

Re:HTTP: , FTP:, and Dict:? by immibis on Sunday September 22, 2024 @01:02PM (#41618319)
XML is a language designed for markup (i.e. text formatting), and fitting structured documents into it creates an impedance mismatch.

Dictionary definitions may be considered as marked-up documents, so it may work. The overall structure of the dictionary is not.

Re:HTTP: , FTP:, and Dict:? by keepamovin on Sunday September 22, 2024 @11:14PM (#41622122)
Yeah, but JSON has the vulnerability that it will tend to become like an overgrown garden over time, because it can. The type of TCP <code> <response> <text> protocols the GP talks about have the benefit of their restrictions and are definitely a better balance (human / machine), and more stable.
Re:HTTP: , FTP:, and Dict:? by kragen on Sunday September 22, 2024 @09:34AM (#41616964)
maybe we could have a format that was more human-readable than json (or especially xml) but still reliably emittable and parseable? yaml, maybe, or toml, although i'm not that enthusiastic about them. another proposal for such a thing was ogdl (https://ogdl.org/), a notation for what i think are called rose trees

> OGDL: Ordered Graph Data Language

> A simple and readable data format, for humans and machines alike.

> OGDL is a structured textual format that represents information in the form of graphs, where the nodes are strings and the arcs or edges are spaces or indentation.

their example:

    network
      eth0
        ip   192.168.0.10
        mask 255.255.255.0
        gw   192.168.0.1

    hostname crispin
another possibility is jevko; https://jevko.org/ describes it and http://canonical.org/~kragen/rose/ are some of my notes about the possibilities of similar rose-tree data formats
Re:HTTP: , FTP:, and Dict:? by hnlmorg on Sunday September 22, 2024 @09:45AM (#41617038)
Formats like TOML are horrible for heavily nested data (even XML does a better job here) and the last time I checked, TOML didn’t support arrays at the top level.

YAML is nicer than JSON to write, but I wouldn’t say it’s any nicer to read.

If you want something that’s less punctuation heavy, then I’d prefer we go full Wirth and have something more akin to Pascal.

Re:HTTP: , FTP:, and Dict:? by kragen on Sunday September 22, 2024 @09:51AM (#41617079)
arrays at the top level are probably a bad idea for protocols that need to evolve in a backward-compatible way

what do you mean about heavily nested data? do the other formats i linked do a better job there?

i'm not sure it's possible to come up with a data format that will work well for such a wide range of use cases, but it sure would be nice to have. json is pretty great in terms of being able to load it into the browser, or visidata, or python, or js, or whatever

Re:HTTP: , FTP:, and Dict:? by hnlmorg on Sunday September 22, 2024 @10:13AM (#41617213)
> arrays at the top level are probably a bad idea for protocols that need to evolve in a backward-compatible way

Depends on the protocol. It might be preferable to version the end point. Or if it’s a specific function, eg list-synonyms” then having a dictionary just to reference an array could be argued as unnecessary protocol bloat. Particularly given the aim of this exercise is readability.

> what do you mean about heavily nested data? do the other formats i linked do a better job there?

I mean a tree like structure.

JSON and YAML are probably the best in class here. XML, for all of its warts, is good at handling nested data in a readable way too.

TOML was more based around a flatter structure.

> i'm not sure it's possible to come up with a data format that will work well for such a wide range of use cases,

It’s not. The moment that happens, that format then becomes unwieldy and people then feel the urge to invent yet another new format to simplify things. It’s a vicious circle that happens over and over again in the tech sector.

Re:HTTP: , FTP:, and Dict:? by kragen on Sunday September 22, 2024 @11:20AM (#41617658)
it's a pretty big problem that connecting existing software together so often requires writing new parsers
Re:HTTP: , FTP:, and Dict:? by hnlmorg on Sunday September 22, 2024 @11:41AM (#41617816)
That suggests things are getting worse but personally I’ve seen the opposite trend.

These days developers rallying around a subset of established standards rather than inventing new protocols and grammar for each new service.

Take a look at the old protocols out there: finger, DNS, Gopher, HTTP, FTP, SMTP Dict, etc. they all have their own grammar and in many cases, even that grammar is very loosely defined or subject to dozens of different standards. Whereas these days it’s mostly JSON or XML over HTTPS. Or ProtoBuf if you need something more compact.

There’s definitely still room for improvement. For example the shift towards proprietary messaging protocols like Slack, Discord, etc. But that’s another topic entirely.

Re:HTTP: , FTP:, and Dict:? by kragen on Sunday September 22, 2024 @12:03PM (#41617955)
yeah, i appreciate the move to html, http, and json. although http/2 and http/3 arguably aren't really http
Re:HTTP: , FTP:, and Dict:? by orf on Sunday September 22, 2024 @09:01AM (#41616747)
Unfortunately, in practice they are a nightmare. Look at the WHOIS protocol for an example.

Humans don’t look at responses very much, so you should optimise for machines. If you want a human-readable view, then turn the JSON response into something readable.

Re:HTTP: , FTP:, and Dict:? by poincaredisk on Sunday September 22, 2024 @09:08AM (#41616792)
Whois protocol has no grammar to speak of (the response body is not defined at all, just a text blob) which makes it a nightmare to parse. Having a proper response format would solve this.

Though I agree, I prefer my responses in JSON.

Re:HTTP: , FTP:, and Dict:? by tephra on Monday September 23, 2024 @02:52AM (#41623063)
If you want WHOIS with a better defined format we have a protocol for that! It's called RDAP https://en.wikipedia.org/wiki/Registration_Data_Access_Proto...
Re:HTTP: , FTP:, and Dict:? by astrobe_ on Sunday September 22, 2024 @01:04PM (#41618331)
The next logical step is to use a machine-friendly format instead; that is a binary protocol.

Even HTML and XML which were designed for readability and manual writing eventually became 'not usable enough" ("became" because I think part of it is that their success made them exposed to less technical populations), and now we have markdown everywhere which most of the times is converted to HTML.

So if you are going to use a tool more sophisticated than Ed/Edlin to read and write (rich) text in a certain format, it could be more efficient to focus on making the job of the machine - and of the programmer, easier.

If you look at a binary protocol such as NTP, the binary format leaves very little room for Postel's principle [1], so it is straightforward to make a program that queries a server and display the result.

[1] https://en.wikipedia.org/wiki/Robustness_principle

Re:HTTP: , FTP:, and Dict:? by donatj on Sunday September 22, 2024 @09:45AM (#41617042)
In my department's (we were formerly our own company) internal framework throwing .html on the end of any JSON response outputs it in nested HTML tables. I personally find it very helpful.
Re:HTTP: , FTP:, and Dict:? by hnlmorg on Sunday September 22, 2024 @10:25AM (#41617292)
At that point you might as well drop JSON altogether and use an XHTML subset so your rendered output is also valid XML (instead of having two different and incompatible markups merged together)
Re:HTTP: , FTP:, and Dict:? by zeven7 on Sunday September 22, 2024 @10:38AM (#41617392)
I’m assuming they use the .html trick for human reading of the data by developers rather than it being used in production
Re:HTTP: , FTP:, and Dict:? by hnlmorg on Sunday September 22, 2024 @11:31AM (#41617736)
Ahhh that makes more sense.
Re:HTTP: , FTP:, and Dict:? by donatj on Sunday September 22, 2024 @11:02AM (#41617550)
That's exactly what it's for
Re:HTTP: , FTP:, and Dict:? by theamk on Sunday September 22, 2024 @01:50PM (#41618651)
That sounds like a bad idea. Unlike JSON, XML is (1) non-trivial to parse safely, (2) hard to reliably extract information and (3) verbose.

Leave the markup languages for intended purpose: text markup. Don't force them to carry data.

Re:HTTP: , FTP:, and Dict:? by hnlmorg on Sunday September 22, 2024 @02:58PM (#41619121)
I’m not generally a fan of XML either but what you posted there is just factually incorrect in just about every conceivable way.

1. There’s plenty of XML parsers already available for most languages. Yeah there have been high profile exploits based from XML but given the scale of XMLs usage, it’s fair to say those exploits are atypical usage where XML can be user supplied. And as long as you’re not allowing users to upload their own XML, then you get to control the schema so there isn’t any risks in using XML.

2. XMLs entire purpose is a data store. I’m not someone who likes to blame the developers for using their tools wrong but honestly, if you can’t unmarshal an XML schema you have control over then you’re not going to succeed with JSON either.

3. It is. But it’s also highly compressible because of its repetitive tags. So for HTTP endpoints, it actually doesn’t work out any different to JSON.

> Leave the markup languages for intended purpose: text markup. Don't force them to carry data.

You do realise the entire point of XML is to carry data? It might have fallen out of favour in recent years but those of us old enough to remember a time before JSON will talk about how JSON is just a simplified reimplementation of XML. And with things like JSON schemas, JSON is continuing to copy XML features.

Re:HTTP: , FTP:, and Dict:? by theamk on Sunday September 22, 2024 @11:44PM (#41622225)
Yes, XML is a better structured format than the things before it (random non-standardized text formats). But saying "it's just the same as JSON" misses how many dangerous parts and footguns it has.

There was a post less than two weeks ago on defusedxml [0] - XML parser with protection from various XML "features" - small files causing exponential blow-up, remote access from just trying to parse the xml... It's not related to "scale of XMLs usage", and those are not security bugs. It's "working as designed", because XML is full of weird features that maybe sounded great in 1998 but now just add vulnerabilities. JSON has eliminated the entire class of those. (and before you say: "it's just python!", check out the "other languages" section. It's also Perl, Ruby, PHP, .NET.

And I am not going to write anything about ambiguities - if you want to serialize an array of points with ("x", "y", "color") properties, and give it to few different XML programmers, each one of them will come up with a different schema. This does not make interoperability easier at all. Compare to JSON, where this can have only one canonical encoding, and the worst you might have to deal with would be some uppercased letters.

JSON is a simplified version of XML, and JSON has copied good XML features (it's not getting namespaces or external DTDs, and good riddance!). So there is no reason to stick to over-complicated technology whose security story is "don't parse user-supplied data".

[0] https://news.ycombinator.com/item?id=41523098

Re:HTTP: , FTP:, and Dict:? by hnlmorg on Monday September 23, 2024 @06:56AM (#41624662)
> But saying "it's just the same as JSON" misses how many dangerous parts and footguns it has.

I didn't say it's just the same as JSON. I said:

"And as long as you’re not allowing users to upload their own XML, then you get to control the schema so there isn’t any risks in using XML."

Every example you've given requires untrusted 3rd parties to craft the XML. But that wasn't what I was advocating here. I was talking specifically about the API returning XML.

> and give it to few different XML programmers, each one of them will come up with a different schema.

But again, the API is controlling the schema so this isn't an issue for the use case I discussed.

> Compare to JSON, where this can have only one canonical encoding, and the worst you might have to deal with would be some uppercased letters.

You've clearly not worked with enough JSON if that's all you think the issue with JSON is. I've written JSON parsers and used a fair few open source ones too. And there's a lot of places things can go wrong:

1. You have number serialization bugs between different JSON parsers.

2. No standard for dates. Causing everyone to do things slightly differently

3. Inconsistencies with top level arrays, some parsers require top level arrays to be `{[ ... ]}` whiles others are happy just with `[ ... ]`

4. Parsers don't all agree on how to represent non-alpha / numeric ASCII characters. And we're not just talking about unicode, Even some ASCII characters like `>` can be handled differently by different JSON libraries

5. Lots of different JSON supersets (because JSON itself doesn't support half the stuff that people need from it), like jsonlines, concatenated json, newline delimited json, JSON with date fields (as seen in popular JSON libraries in .NET), JSON schema, etc.

6. Even your key name example has numerous other inconsistencies you haven't touched on. Like UPPER, lower, dot.notation, hyphenated-keys, underscored_keys, UpperCamelCased, lowerCamelCased...and so many variations in between.

Ignoring JSON supersets, then I agree that JSON has fewer places for exploits in user generated documents. But the specification is also only 5 (FIVE!!!) pages long and thus it allows for a lot of undefined behaviour. And that's a problem for somethings who's entire purpose is a database.

This is why XML is so complex -- precisely because it's intended to solve these problems. But it was also intended to be served from trusted identities. Which is where the vulnerabilities lie.

> JSON is a simplified version of XML, and JSON has copied good XML features (it's not getting namespaces or external DTDs, and good riddance!).

I wouldn't be so sure about that: https://json-schema.org/specification

---

To go back to my earlier point: literally no-one is going to argue that XML doesn't have it's warts. But what you need to understand is that in the specific example that started this conversation, the API provider is the one defining the schema and crafting the XML. So literally none of your examples apply what-so-ever. In fact, this falls squarely under the correct usage of XML.

Context matters. User supplied XML is bad but that's not what is being proposed here. And that's why you're being called out of stating what you believed to be pretty obvious advice.

Re:HTTP: , FTP:, and Dict:? by fouc on Sunday September 22, 2024 @11:38AM (#41617795)
textual ebnf-specified protocol > json
Re:HTTP: , FTP:, and Dict:? by somat on Sunday September 22, 2024 @06:45PM (#41620733)
REST (REpresentational State Transfer) as a concept is very human orientated. The idea was a sort of academic abstraction of html. but it can be boiled down to: when you send a response, also send the entire application needed to handle that response. It is unfortunate that collectively we had a sort of brain fart and said "ok, REST == http, got it" and lost the rest of the interesting discussion about what it means to send the representational state of the process.
Re:HTTP: , FTP:, and Dict:? by zzo38computer on Sunday September 22, 2024 @06:56PM (#41620807)
> I admire these old protocols ...

The protocols that have a response code with an explanation is helpful. A help command is also helpful. So, I had written NNTP server that does that, and the IRC and NNTP client software I use can display them.

> Makes me think it's a shame that making a json based protocol is so much easier to whip up ...

I personally don't; I find I can easily work with text-based protocols if the format is easily enough.

I think there are problems with JSON. Some of the problems are: it requires parsing escapes and keys/values, does not properly support character sets other than Unicode, cannot work with binary data unless it is encoded using base64 or hex or something else (which makes it inefficient), etc. There are other problems too.

> Like imagine if in python there was some library that you gave an ebnf spec ...

Maybe it is possible to add such a library in Python, if there is not already such things.

Re:HTTP: , FTP:, and Dict:? by sixdimensional on Monday September 23, 2024 @12:32AM (#41622407)
May I humbly submit “parsing expression grammars”[1] for your consideration?

Fairly simple and somewhat fun.. Python has PEG parsing built in, but also the pyparsing or parsimonious modules too.

I have built EDI X12 parsers and toy languages with this.

[1] https://en.wikipedia.org/wiki/Parsing_expression_grammar

Re:HTTP: , FTP:, and Dict:? by sixdimensional on Monday September 23, 2024 @12:38AM (#41622425)
Also lark in Python too