Skip to content

Commit 5562258

Browse files
committed
Improve middleware for rejecting unknown Client-Server API versions
Related to: - https://matrix.org/blog/2021/11/09/matrix-v-1-1-release - matrix-org/synapse#11318 - spantaleev/matrix-docker-ansible-deploy#1404 Our `denyUnsupportedApiVersionsMiddleware` middleware was trying to match `rXXX` versions and reject unsupported ones (anything besides `r0`), but now that the prefix is changing (`vXXX`) we were not matching the new one correctly and were letting `vXXX` requests go through. This is not a security issue yet, as no stable version of a homeserver supports v3-prefixed APIs yet, but an upcoming Synapse v1.48.0 is slated to add support for those. An old matrix-corporal version (lacking this patch) combined with Synapse v1.48.0+ will let such v3 requests go through, effectively circuimventing matrix-corporal's protections.
1 parent 7aeffe3 commit 5562258

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

corporal/httpgateway/middleware.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ var regexApiVersionFromUri *regexp.Regexp
1313
var supportedApiVersions []string
1414

1515
func init() {
16-
regexApiVersionFromUri = regexp.MustCompile("/_matrix/client/r([^/]+)")
16+
// We'd like to match things like:
17+
// - `/_matrix/client/r0`
18+
// - `/_matrix/client/v3` (and other v-prefixed versions in the future)
19+
// but not match things like: `/_matrix/client/versions`
20+
regexApiVersionFromUri = regexp.MustCompile(`/_matrix/client/((?:r|v)\d+)`)
1721

1822
supportedApiVersions = []string{
19-
//We only support r0 for the time being.
20-
"0",
23+
"r0",
2124
}
2225
}
2326

@@ -30,7 +33,7 @@ func denyUnsupportedApiVersionsMiddleware(next http.Handler) http.Handler {
3033
return
3134
}
3235

33-
releaseVersion := matches[1] // Something like `0`
36+
releaseVersion := matches[1] // Something like `r0`
3437

3538
if util.IsStringInArray(releaseVersion, supportedApiVersions) {
3639
// We do support this version and can safely let our gateway

0 commit comments

Comments
 (0)