feat: Assert content type on federation responses #2475
No reviewers
Labels
No labels
Abandoned
Blocked
Bug
Changelog
Added
Changelog
Missing
Changelog
None
Cherry-picking
Compliance
Continuwuity/Web Interface
Database
Dependencies
Dependencies/Renovate
Difficulty
Easy
Difficulty
Hard
Difficulty
Medium
Documentation
Enhancement
Good first issue
Help wanted
Inherited
Matrix/Administration
Matrix/Appservices
Matrix/Auth
Matrix/Client
Matrix/Core
Matrix/E2EE
Matrix/Federation
Matrix/Hydra
Matrix/MSC
Matrix/Media
Matrix/T&S
Merge
Merge/Manual
Merge/Squash
Meta
Meta/CI
Meta/Packaging
Priority
Blocking
Priority
High
Priority
Low
Security
Status
Confirmed
Status
Duplicate
Status
Invalid
Status
Needs Investigation
Support
bob the builder
No assignees
5 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
continuwuation/continuwuity!2475
Loading…
Reference in a new issue
No description provided.
Delete branch "nex/feat/enforce-federation-content-type"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I realised Synapse does this and it's actually written in the spec as a MUST, so we should probably enforce this check too.
Pull request checklist:
mainbranch, and the branch is named something other thanmain.myself, if applicable. This includes ensuring code compiles.
@ -303,0 +304,4 @@// For some reason, the spec starts off saying federation responses MUST// include a `Content-Type` header of `application/json` on all// responses. Then, the definition for the well-known server endpoint// says that it's a SHOULD and that servers SHOULD just assume that thewell-known is an exception because people are misconfiguring it and also it's unlikely to get turned to cbor or something
@ -303,0 +308,4 @@// response is JSON regardless... And then there's media wayyyy down in// the spec doc that just throws a `multipart/mixed` in there.enforce_content_type(&response,Could we check the status before requiring multipart/mixed? Media errors are JSON, so this replaces responses like 404 M_UNRECOGNIZED with a 415.
Addressed in
2892e4c9bd@ -303,0 +310,4 @@enforce_content_type(&response,if url.path().starts_with("/_matrix/federation/v1/media/") {"multipart/mixed"Could we exclude successful legacy media responses here? They return the file’s content type, so this would reject downloads like image/jpeg
no
Longer answer: legacy media should be considered unsupported nowadays and is slated for removal altogether in the not too distant future
we can only hope
@ -356,0 +383,4 @@.get(&http::header::CONTENT_TYPE).and_then(|h| h.to_str().ok()).map(|h| h.split_once(';').unwrap_or((h, "")).0){Could we compare the media type case-insensitively? HTTP allows values such as Application/Json.
The Matrix spec doesn't
that's not very RFC compliant i will talk to the direction
Well, I suppose the spec doesn't say not to casefold, and in the face of ambiguity the RFC(s) would become relevant. It looks like synapse doesn't do that but I guess that'd be a synapse bug if anything
Addressed in
2892e4c9bdwait no i meant the red button
I preferred the green button :(