microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.38k stars 28.61k forks source link

Honor `X-Forwarded-Port` header #225706

Open mering opened 4 weeks ago

mering commented 4 weeks ago

Steps to Reproduce:

  1. Run ./scripts/code-server.sh --port 3000
  2. Run an nginx proxy with the following config:

    server {
        listen 8080;
        listen [::]:8080;
    
        location / {
            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-Port $server_port;
            proxy_set_header Host $host;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $http_connection;
            # Destination
            proxy_pass http://localhost:3000/;
        }
    }
  3. When accessing http://localhost:8080/, it cannot connect the WebSocket

When using proxy_set_header X-Forwarded-Host $host:$server_port; instead of the separte host and port headers, everything works fine.

mering commented 4 weeks ago

I fixed this in ee80e47f084e4cab294fe15fa5ec15b7b5fc9f6c as part of #210455. If you prefer, I can move this to a separate PR.