create-react-app icon indicating copy to clipboard operation
create-react-app copied to clipboard

Proxying WebSocket requests is broken

Open minus7 opened this issue 3 years ago • 1 comments

Describe the bug

Setting the proxy field in package.json proxies normal HTTP requests and WebSocket requests.

For normal requests, the Origin header is patched to equal the target host (added in #1212).

For websocket requests, the onProxyReq hook is not executed and thus the original Origin is sent to the target server. The target server will likely reject the request because Host and Origin mismatch (Gorilla websockts in my case). To also patch Origin for websocket requests, the onProxyReqWs hook has to be specified additionally.

Steps to reproduce

  1. Add a breakpoint or console.log in the onProxyReq callback mentioned above.
  2. yarn start any created project with a configured proxy
  3. Open a websocket connection
  4. See nothing getting logged because only onProxyReqWs is called for websocket connections.

Expected behavior

Origin and Host are equal for proxied websocket requests (e.g. http://localhost:8080).

Actual behavior

Origin is the original header sent by the browser (e.g. http://localhost:3000) while Host is changed (e.g. http://localhost:8080).

--

Note: I'd have sent a patch, but I refuse to sign the CLA.

minus7 avatar Apr 25 '21 12:04 minus7

Related to #5280

dedo1911 avatar Jul 13 '22 16:07 dedo1911