matrix-org / matrix-org/matrix-spec
Unclear requirements of where canonical JSON must be enforced
Nobody has claimed this yet.
- Dominant language
- HTML
- Stars
- 330
- Forks
- 150
- Avg merge
- 2h 21m
- Merged PRs (30d)
- 3
Description
Link to problem area:
Servers MUST strictly enforce the JSON format specified in the appendices. This translates to a 400
M_BAD_JSONerror on most endpoints, or discarding of events over federation. For example, the Federation API’s/sendendpoint would discard the event whereas the Client Server API’s/send/{eventType}endpoint would return aM_BAD_JSONerror.
— https://spec.matrix.org/v1.11/rooms/v11/#canonical-json
Issue
This is phrasing is very hard to understand and has had multiple interpretations such as:
- JSON over the wire must be in canonical form, except for an undefined set of endpoints
@ity:itycodes.org(paraphrased)
- It's unclear what layer this enforcement is occurring at, e.g. on the data over the wire or on data before it is signed/verified, and that most endpoints return that error but other endpoints return a different error (or fail silently)
@charles:computer.surgery(me)
- Clients obviously don't need to canonicalize request content, but if they send non-canonicalizable JSON then they get a
M_BAD_JSON@tulir:maunium.net
Some additional context:
Solution
IMO this section of the spec needs to be reworded so that it doesn't sound like it's making any requirements on the wire format and that it only applies to some endpoints, as these details are currently causing confusion. Perhaps something like this:
Before signing or verifying JSON data, servers MUST strictly enforce that the JSON data can be canonicalized. For example, data received by servers that cannot be canonicalized can result in 400
M_BAD_JSONfor some client endpoints or in events over federation being discarded.
"Before signing or verifying JSON data" clarifies that this only applies to signing/verifying and not data over the wire, and the modified placement of "For example" clarifies that the following text is informative rather than normative, and is expected to only apply in a few places, and allows the rest of the spec to describe those places.
Relatedly, I think it would be very helpful to explicitly state somewhere in the spec that data over the wire is never required to be in canonical format. Currently, this is merely implied by the spec never stating that data over the wire must be canonicalized, which makes it hard to know for sure since it doesn't say the opposite either and there is no section in the spec to point to as a reference. I think this would help mitigate confusion when reading/interpreting other parts of the spec as well.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the canonical JSON sections in the v1.11 appendices and rooms/v11, then review the cited discussion about signing, verification, and wire format. Rework the normative wording so its scope and endpoint behavior are unambiguous, and state whether wire data must be canonical; done means the revised text clearly distinguishes canonicalization from transmission format.
Written by the indexing model from the issue text.
Assessment
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100