Skip to content

Commit

Permalink
Added log to show which URL is blocked by CORS. (mattermost#26347)
Browse files Browse the repository at this point in the history

---------

Co-authored-by: Mattermost Build <[email protected]>
  • Loading branch information
Aryakoste and mattermost-build authored Apr 6, 2024
1 parent 71e26b8 commit a040618
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion server/channels/api4/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ func connectWebSocket(c *Context, w http.ResponseWriter, r *http.Request) {

ws, err := upgrader.Upgrade(w, r, nil)
if err != nil {
c.Err = model.NewAppError("connect", "api.web_socket.connect.upgrade.app_error", nil, err.Error(), http.StatusBadRequest)
params := map[string]any{
"BlockedOrigin": r.Header.Get("Origin"),
}
c.Err = model.NewAppError("connect", "api.web_socket.connect.upgrade.app_error", params, err.Error(), http.StatusBadRequest)
return
}

Expand Down
2 changes: 1 addition & 1 deletion server/channels/api4/websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,5 +465,5 @@ func TestWebSocketUpgrade(t *testing.T) {
require.NoError(t, err)
require.Equal(t, resp.StatusCode, http.StatusBadRequest)
require.NoError(t, th.TestLogger.Flush())
testlib.AssertLog(t, buffer, mlog.LvlDebug.Name, "Failed to upgrade websocket connection.")
testlib.AssertLog(t, buffer, mlog.LvlDebug.Name, "URL Blocked because of CORS. Url: ")
}
2 changes: 1 addition & 1 deletion server/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4552,7 +4552,7 @@
},
{
"id": "api.web_socket.connect.upgrade.app_error",
"translation": "Failed to upgrade websocket connection."
"translation": "URL Blocked because of CORS. Url: {{.BlockedOrigin}}"
},
{
"id": "api.web_socket_router.bad_action.app_error",
Expand Down

0 comments on commit a040618

Please sign in to comment.