Skip to content

Wrong SockJS Host validation with Reverse Proxy #13627

Closed
@mistic100

Description

@mistic100

🐞 Bug report

Angular CLI version : 7.2.3

Command (mark with an x)

- [ ] new
- [ ] build
- [x] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Is this a regression?

I don't know

Description

When using "ng serve" behind a reverse proxy on a sub-path, the SockJS Server throws 400 errors because it fails to validate the Host/Origin header.

🔬 Minimal Reproduction

I want to have my application served on my workstation at http://dev.local/common-demo

  1. Create a new Angular CLI project
  2. Configure the serve task in angular.json with
            "host": "localhost",
            "port": 9038,
            "publicHost": "dev.local/common-demo/sockjs-node",
            "baseHref": "/common-demo/",
            "servePath": "/"
  1. Configure you workstation reverse proxy with (here Apache is used)
ProxyPass /common-demo http://localhost:9038
ProxyPassReverse /common-demo http://localhost:9038

🔥 Exception or Error

Chrome console shows :

WebSocket connection to 'ws://dev.local/common-demo/sockjs-node/287/kbmqffv3/websocket' failed: Error during WebSocket handshake: Unexpected response code: 400

Invalid Host/Origin header

[WDS] Disconnected!

Notes

If I set disableHostCheck to true, it works, but I don't want to.

If I set publicHost to dev.local the app tries to connect to ws://dev.local/sockjs-node which is not valid as it ignores the baseHref.

The servePath needs to be / as the app is served at the root of localhost:9038 (by default servePath inherits from baseHref but the sub-path is handled by the Reverse Proxy in my setup).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions