Skip to content
This repository was archived by the owner on Nov 25, 2024. It is now read-only.

Commit df770da

Browse files
authored
Make OPTIONS method on MSC3916 endpoints available without auth (#3431)
OPTIONS method is usually sent by browser in preflight requests, most of the time we cannot control preflight request to add auth header. Synapse will return a 204 response directly without authentication for those OPTIONS method. According to firefox's documentation, both 200 and 204 are acceptable so I think there is no need to change handler in dendrite. This closes #3424 No need to add a test because this is just a fix and I have tested on my Cinny Web client personally. ### Pull Request Checklist <!-- Please read https://matrix-org.github.io/dendrite/development/contributing before submitting your pull request --> * [x] I have added Go unit tests or [Complement integration tests](https://github.com/matrix-org/complement) for this PR _or_ I have justified why this PR doesn't need tests * [x] Pull request includes a [sign off below using a legally identifiable name](https://matrix-org.github.io/dendrite/development/contributing#sign-off) _or_ I have already signed off privately Signed-off-by: `arenekosreal <[email protected]>` Signed-off-by: arenekosreal <[email protected]>
1 parent 07e59d0 commit df770da

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

internal/httputil/httpapi.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,12 @@ func MakeExternalAPI(metricsName string, f func(*http.Request) util.JSONResponse
210210
// This is used to serve HTML alongside JSON error messages
211211
func MakeHTTPAPI(metricsName string, userAPI userapi.QueryAcccessTokenAPI, enableMetrics bool, f func(http.ResponseWriter, *http.Request), checks ...AuthAPIOption) http.Handler {
212212
withSpan := func(w http.ResponseWriter, req *http.Request) {
213+
if req.Method == http.MethodOptions {
214+
util.SetCORSHeaders(w)
215+
w.WriteHeader(http.StatusOK) // Maybe http.StatusNoContent?
216+
return
217+
}
218+
213219
trace, ctx := internal.StartTask(req.Context(), metricsName)
214220
defer trace.EndTask()
215221
req = req.WithContext(ctx)

0 commit comments

Comments
 (0)