Skip to content

Commit daf0814

Browse files
committed
Change Origin header on proxied WebSocket requests
Similar to CORS controls, WebSocket servers are often (see below) configured to check the Origin header of incoming requests. The config for the HTTP proxy overwrites requests' Origin header to prevent issues with CORS, but didn't previously do the same thing for WebSockets, as they are controlled by a different config key. Fixes #10878
1 parent 0a827f6 commit daf0814

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

packages/react-dev-utils/WebpackDevServerUtils.js

+9
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,15 @@ function prepareProxy(proxy, appPublicFolder, servedPathname) {
379379
proxyReq.setHeader('origin', target);
380380
}
381381
},
382+
onProxyReqWs: proxyReq => {
383+
// Browsers may send Origin headers even with same-origin
384+
// requests. It is common for WebSocket servers to check the Origin
385+
// header, so we have to change the Origin to match
386+
// the target URL.
387+
if (proxyReq.getHeader('origin')) {
388+
proxyReq.setHeader('origin', target);
389+
}
390+
},
382391
onError: onProxyError(target),
383392
secure: false,
384393
changeOrigin: true,

0 commit comments

Comments
 (0)