Skip to content
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

gomatrixserverlib rejects Authorization: X-Matrix ... headers that include optional whitespace around parameter pairs #434

Closed
anoadragon453 opened this issue May 8, 2024 · 0 comments · Fixed by #436

Comments

@anoadragon453
Copy link
Member

anoadragon453 commented May 8, 2024

The spec states that the format of the Authorization header on the Federation API is given by RFC 7235. Part of that specification allows for zero or more spaces or tabs around the commas in the parameter list. For example, the following should be a valid Authorization header:

Authorization: X-Matrix origin=foo , key="ed25519:1",  sig="sig",		destination="bar"

Yet upon looking at gomatrixserverlib's source code, I believe it would reject this header:

func ParseAuthorization(header string) (scheme string, origin, destination spec.ServerName, key gomatrixserverlib.KeyID, sig string) {
parts := strings.SplitN(header, " ", 2)
scheme = parts[0]
if scheme != "X-Matrix" {
return
}
if len(parts) != 2 {
return
}
for _, data := range strings.Split(parts[1], ",") {
pair := strings.SplitN(data, "=", 2)
if len(pair) != 2 {
continue
}
name := pair[0]
value := strings.Trim(pair[1], "\"")
if name == "origin" {
origin = spec.ServerName(value)
}
if name == "key" {
key = gomatrixserverlib.KeyID(value)
}
if name == "sig" {
sig = value
}
if name == "destination" {
destination = spec.ServerName(value)
}
}
return
}

This fact was omitted from the summary of RFC 7235 in the spec, which is likely why it didn't make it into gomatrixserverlib as well. That is now being corrected: matrix-org/matrix-spec#1818

The code should be updated to allow whitespace in the parameter list in the header, such that any homeserver implementations following the spec would not have their federation requests rejected by homeservers that rely on gomatrixserverlib.

See matrix-org/matrix-spec#1817 for more context.

@anoadragon453 anoadragon453 changed the title Dendrite rejects Authorization: X-Matrix ... headers that include optional whitespace around parameter pairs gomatrixserverlib rejects Authorization: X-Matrix ... headers that include optional whitespace around parameter pairs May 8, 2024
S7evinK added a commit that referenced this issue Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant