-
Notifications
You must be signed in to change notification settings - Fork 433
MSC2540: Stricter event validation: JSON compliance #2540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7797c18
Add MSC2540 for stricter validation of event JSON.
clokep 11587a5
Small clarification.
clokep bbbd9c4
Update wording to avoid demand-style language.
clokep 03588cb
Be clearer about errors and what to do with current room versions.
clokep 6757c60
Specify the current stable room versions.
clokep 0b6301a
Fix grammar and typos from review.
clokep 007c8b5
Clarify the range of valid values.
clokep e5fa76c
Clarify range a bit more.
clokep f5ebe33
Reword how bad values are handled.
clokep 0771671
Give more guidance on how invalid events should be handled.
clokep File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # MSC2540: Stricter event validation: JSON compliance | ||
|
|
||
| ## Background | ||
|
|
||
| There has been [prior discussions](https://github.com/matrix-org/matrix-doc/issues/1646) | ||
| about validating events more strictly. This MSC proposes fixing a small piece of | ||
| this: JSON compliance. | ||
|
|
||
| The [Canonical JSON](https://matrix.org/docs/spec/appendices#canonical-json) | ||
| specification requires that numbers that are serialized in JSON are integers in | ||
| the inclusive range of `[-(2^53) + 1, (2^53) - 1]`, which matches the requirements of | ||
| [section 6 of RFC 7159](https://tools.ietf.org/html/rfc7159). Note that it is | ||
| not explicit, but all floats are invalid. | ||
|
|
||
| It is worth mentioning that there are common extensions to JSON which produce | ||
| invalid JSON according to the Matrix specification; some programming langauges | ||
| even support these by default. One common additional feature is handling | ||
| "special" float values: `Infinity`, `-Infinity`, and `NaN`. | ||
|
|
||
|
|
||
| ## Proposal | ||
|
|
||
| In a future room version, homeserver implementations are to strictly enforce | ||
| the JSON compliance of the Canonical JSON specification for events. Events that | ||
| do not abide by these rules should be rejected with the error code `M_NOT_JSON`. | ||
clokep marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
clokep marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| The rationale for doing this in a future room version is to avoid a split brain | ||
| room -- where some federated servers believe an event is valid and others reject | ||
| it as invalid. Rooms will be able to opt into this behavior as part of a room | ||
| version upgrade. | ||
|
|
||
| Homeserver implementations are not to strictly enforce this JSON compliance in | ||
| [room versions 1, 2, 3, 4, and 5](https://matrix.org/docs/spec/#complete-list-of-room-versions). | ||
| The rationale is essentially the same as why a future room version is necessary: | ||
| this ensures that all federated servers treat the same events as valid. | ||
|
|
||
|
|
||
| ## Potential issues | ||
|
|
||
| Homeserver implementations might include JSON parsers which are stricter than | ||
| others. It may not be worthwhile or reasonable to loosen those restrictions for | ||
| stable room versions. | ||
|
|
||
|
|
||
| ## Alternatives | ||
|
|
||
| It could be argued that this MSC is unnecessary since it does not add any new | ||
| requirements for handling of JSON data. Unfortunately starting to enforce these | ||
| requirements in current rooms could cause federation to break as homeservers | ||
| will disagree on whether events are valid. | ||
|
|
||
|
|
||
| ## Security considerations | ||
|
|
||
| N/A | ||
|
|
||
|
|
||
| ## Unstable prefix | ||
|
|
||
| A room version of `org.matrix.strict_canonicaljson` until a future room version | ||
| is available. This room version will use | ||
| [room version 5](https://matrix.org/docs/spec/rooms/v5) as base and include the | ||
| above modifications. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.