Studio Code Server not loading

Hi, Studio Code Server seemed to suddenly stop loading when I try to start it through a remote connection. I’m using Nginx and DuckDNS for SSL. It works when I connect internally using the IP Address but I get a forbidden error in the log when going through DuckDNS. Any ideas? Thanks.

at Function.handle (/usr/local/lib/code-server/node_modules/router/index.js:184:3)
    at router (/usr/local/lib/code-server/node_modules/router/index.js:59:12)
    at Layer.handle [as handle_request] (/usr/local/lib/code-server/node_modules/router/lib/layer.js:102:15)
    at trim_prefix (/usr/local/lib/code-server/node_modules/router/index.js:330:13)
    at /usr/local/lib/code-server/node_modules/router/index.js:294:7
    at Function.process_params (/usr/local/lib/code-server/node_modules/router/index.js:349:12)
    at Immediate.next (/usr/local/lib/code-server/node_modules/router/index.js:285:10)
    at Immediate.<anonymous> (/usr/local/lib/code-server/node_modules/router/index.js:671:15)
    at processImmediate (node:internal/timers:466:21)
[2023-03-08T19:41:30.713Z] error Forbidden HttpError: Forbidden
    at ensureOrigin (/usr/local/lib/code-server/out/node/http.js:288:15)
    at wrapped (/usr/local/lib/code-server/out/node/wsRouter.js:64:24)
    at Layer.handle [as handle_request] (/usr/local/lib/code-server/node_modules/router/lib/layer.js:102:15)
    at next (/usr/local/lib/code-server/node_modules/router/lib/route.js:144:13)
    at Route.dispatch (/usr/local/lib/code-server/node_modules/router/lib/route.js:109:3)
    at handle (/usr/local/lib/code-server/node_modules/router/index.js:515:11)
    at Layer.handle [as handle_request] (/usr/local/lib/code-server/node_modules/router/lib/layer.js:102:15)
    at /usr/local/lib/code-server/node_modules/router/index.js:291:22
    at param (/usr/local/lib/code-server/node_modules/router/index.js:368:14)
    at param (/usr/local/lib/code-server/node_modules/router/index.js:379:14)
    at Function.process_params (/usr/local/lib/code-server/node_modules/router/index.js:424:3)
    at next (/usr/local/lib/code-server/node_modules/router/index.js:285:10)
    at Function.handle (/usr/local/lib/code-server/node_modules/router/index.js:184:3)
    at router (/usr/local/lib/code-server/node_modules/router/index.js:59:12)
    at Layer.handle [as handle_request] (/usr/local/lib/code-server/node_modules/router/lib/layer.js:102:15)
    at trim_prefix (/usr/local/lib/code-server/node_modules/router/index.js:330:13)
    at /usr/local/lib/code-server/node_modules/router/index.js:294:7
    at Function.process_params (/usr/local/lib/code-server/node_modules/router/index.js:349:12)
    at Immediate.next (/usr/local/lib/code-server/node_modules/router/index.js:285:10)
    at Immediate.<anonymous> (/usr/local/lib/code-server/node_modules/router/index.js:671:15)
    at processImmediate (node:internal/timers:466:21)
File not found: /usr/local/lib/code-server/lib/vscode/extensions/git-base/dist/browser/extension.js
File not found: /usr/local/lib/code-server/lib/vscode/extensions/emmet/dist/browser/emmetBrowserMain.js
File not found: /usr/local/lib/code-server/lib/vscode/extensions/merge-conflict/dist/browser/mergeConflictMain.js
[2023-03-08T19:41:42.061Z] error Forbidden HttpError: Forbidden
1 Like

The issue is documented on the GitHub page for the addon:

As the last reply (as of now) states, adding “proxy_set_header X-Forwarded-Host $http_host;” to the NginX configuration resolves the issue.

1 Like

i have the same problem, strage thing is that i run 2 ha instences and only one has the problem.
They are both configured the same.

Sure they’re both on exactly the same version? That is strange…

If you have the problem please add support on the github issue/PR :wink:

both have the same add-on version, only one is debian 11 supervised installation and the one that is not working is ha os.
Should i reply in your PR?

comment/thumbs up whatever you want

the supervised install must have something different going on with nginxsending the required header somehow

The issue doesn’t have any comments at the mo Nginx proxy addon: No config option for `X-Forwarded-Host` · Issue #2912 · home-assistant/addons · GitHub

Gave it some thumbs up

1 Like

@TheMystery @stevelatimer think one of you (or anyone but me) needs to bump the github issue because it’s been marked as stale

This is now fixed :slight_smile:

Yes thx issue is fixed.

Just a heads up: a while ago after I started using the HA NGINX Home Assistant SSL proxy addon I ran into some problems opening some Ingress addons. After some research I found a fix that made me create a file in the folder \\<IP HERE>\share with the name nginx_proxy_default_fix_ingress.conf the content of the file was:

location /api {
    proxy_connect_timeout 60;
    proxy_read_timeout 60;
    proxy_send_timeout 60;
    proxy_intercept_errors off;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_set_header Host $host:8126;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_pass http://<IP HERE>:8123/api;
}

while that fixed the problem back then it now made Studio Code Server not work.
Just delete the file and restart HA NGINX Home Assistant SSL proxy addon. The new X-Forwarded-Host addition in the addon does the trick. Atm it seems all Ingress related stuff still works.

Thanks 2 the people who made this possible!

1 Like

This did it. Thanks

Hello,

how to fix it i lost :laughing:

Just update your nginx addon

1 Like

@TheHolyRoger Thanks

1 Like

For the Traefik reverse proxy users, adding this to my dyanamic file provider .yaml file fixed it:

contentSecurityPolicy: "script-src 'self' 'unsafe-inline'"

It’d be great to not use unsafe-inline, but I’m a bit out of my depth and this is what Chrome Dev Tools Console recommended from the error log.

The simple workaround is to go to your server’s IP without reverse proxy and use Code Server there.

Thank you!

Dang, I already have the setting and it still crashes.
I’m running NGINX Proxy Manager and have

location /authelia {
    internal;
    set $upstream_authelia http://redacted/api/verify; #ADD YOUR IP AND PORT OF AUTHELIA
    proxy_pass_request_body off;
    proxy_pass $upstream_authelia;    
    proxy_set_header Content-Length "";
 
    # Timeout if the real server is dead
    proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
    client_body_buffer_size 128k;
    proxy_set_header Host $host;
    proxy_set_header X-Original-URL $scheme://$http_host$request_uri;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr; 
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Host $http_host;
    proxy_set_header X-Forwarded-Uri $request_uri;
    proxy_set_header X-Forwarded-Ssl on;
    proxy_redirect  http://  $scheme://;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
    proxy_cache_bypass $cookie_session;
    proxy_no_cache $cookie_session;
    proxy_buffers 4 32k;
 
    send_timeout 5m;
    proxy_read_timeout 240;
    proxy_send_timeout 240;
    proxy_connect_timeout 240;
}
 
    location / {
        set $upstream_hass http://redacted;  #CHANGE NAME AND IP AND PORT
        proxy_pass $upstream_hass;  #change name of the service
 
		auth_request /authelia;
		auth_request_set $target_url $scheme://$http_host$request_uri;
		auth_request_set $user $upstream_http_remote_user;
		auth_request_set $groups $upstream_http_remote_groups;
		proxy_set_header Remote-User $user;
		proxy_set_header Remote-Groups $groups;
		error_page 401 =302 https://auth.goochdom.com/?rd=$target_url; #change YOURDOMAIN.COM to your domain
 
		client_body_buffer_size 128k;
 
		proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
 
		send_timeout 5m;
		proxy_read_timeout 360;
		proxy_send_timeout 360;
		proxy_connect_timeout 360;
                proxy_set_header Upgrade $http_upgrade; 
                proxy_set_header Connection “upgrade”;
		proxy_set_header Host $host;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header X-Forwarded-Proto $scheme;
		proxy_set_header X-Forwarded-Host $http_host;
		proxy_set_header X-Forwarded-Uri $request_uri;
		proxy_set_header X-Forwarded-Ssl on;
		proxy_redirect  http://  $scheme://;
		proxy_http_version 1.1;
		proxy_set_header Connection "";
		proxy_cache_bypass $cookie_session;
		proxy_no_cache $cookie_session;
		proxy_buffers 64 256k;
 
		set_real_ip_from 192.168.1.0/16;
		real_ip_header X-Forwarded-For;
		real_ip_recursive on;
 
    }