-
-
Notifications
You must be signed in to change notification settings - Fork 679
Make OPTIONS method on MSC3916 endpoints available without auth #3431
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this works, I'd prefer having the OPTIONS
check in the MakeHTTPAPI
function, i.e.
// MakeHTTPAPI adds Span metrics to the HTML Handler function
// This is used to serve HTML alongside JSON error messages
func MakeHTTPAPI(metricsName string, userAPI userapi.QueryAcccessTokenAPI, enableMetrics bool, f func(http.ResponseWriter, *http.Request), checks ...AuthAPIOption) http.Handler {
withSpan := func(w http.ResponseWriter, req *http.Request) {
if req.Method == http.MethodOptions {
util.SetCORSHeaders(w)
w.WriteHeader(http.StatusOK)
return
}
...
…tion. 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. Signed-off-by: arenekosreal <17194552+arenekosreal@users.noreply.github.com>
I have changed the code to check |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@@ -210,6 +210,12 @@ func MakeExternalAPI(metricsName string, f func(*http.Request) util.JSONResponse | |||
// This is used to serve HTML alongside JSON error messages | |||
func MakeHTTPAPI(metricsName string, userAPI userapi.QueryAcccessTokenAPI, enableMetrics bool, f func(http.ResponseWriter, *http.Request), checks ...AuthAPIOption) http.Handler { | |||
withSpan := func(w http.ResponseWriter, req *http.Request) { | |||
if req.Method == http.MethodOptions { | |||
util.SetCORSHeaders(w) | |||
w.WriteHeader(http.StatusOK) // Maybe http.StatusNoContent? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're using http.StatusOK
in MakeJSONAPI, so I'd keep that the same.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3431 +/- ##
==========================================
+ Coverage 68.34% 68.36% +0.02%
==========================================
Files 513 513
Lines 47026 47030 +4
==========================================
+ Hits 32138 32153 +15
+ Misses 10896 10886 -10
+ Partials 3992 3991 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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
Signed-off-by:
arenekosreal <17194552+arenekosreal@users.noreply.github.com>