Title: Fix CSP behind reverse proxy · Issue #4476 · coder/code-server · GitHub
Open Graph Title: Fix CSP behind reverse proxy · Issue #4476 · coder/code-server
X Title: Fix CSP behind reverse proxy · Issue #4476 · coder/code-server
Description: What's the problem I'm solving? With the latest changes to use the upstream server in code-server, we're now running into Content-Security-Policy issues with our reverse proxy. The specific code we're talking about lives here. When using...
Open Graph Description: What's the problem I'm solving? With the latest changes to use the upstream server in code-server, we're now running into Content-Security-Policy issues with our reverse proxy. The specific code we...
X Description: What's the problem I'm solving? With the latest changes to use the upstream server in code-server, we're now running into Content-Security-Policy issues with our reverse proxy. The spec...
Opengraph URL: https://github.com/coder/code-server/issues/4476
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Fix CSP behind reverse proxy","articleBody":"## What's the problem I'm solving?\r\n\r\nWith the [latest changes](https://github.com/cdr/code-server/pull/4414) to use the upstream server in code-server, we're now running into Content-Security-Policy issues with our reverse proxy. The specific code we're talking about lives [here](https://github.com/cdr/vscode/blob/code-server-v2/src/vs/workbench/browser/client.ts#L125).\r\n\r\nWhen using a reverse proxy (i.e. [Caddy](https://caddyserver.com/)/[NGINX](https://nginx.org/en/)), the update endpoint is incorrect because it has the wrong base path and protocol.\r\n\r\n## What are some ways to go about it?\r\n\r\nThe most ideal way to solve this is to use _relative endpoints_. This way, code-server doesn't care about the base path or protocol. It only knows and uses relative paths.\r\n\r\n## How will things change/what is the need for maintenance?\r\n\r\nI am not sure if there is historical context I may be missing which would explain why we didn't use a relative path from the start (or rather why upstream didn't). Patching this in `vscode` means it's something we'll need to keep an eye on as we continue staying in line with upstream.\r\n\r\nI can't imagine this introducing any breaking changes but it could potentially break in specific environments if they don't support using relative paths for some reason 🤔 (though none specifically come to mind).\r\n\r\n## How to reproduce\r\n\r\nAsher outlined steps below to reproduce this issue locally. To do so, follow these steps:\r\n1. install [Caddy](https://caddyserver.com/) (`brew install caddy`)\r\n2. start code-server locally with `yarn watch`\r\n3. serve it at as base path like `/code` with Caddy\r\n```Caddyfile\r\nhttp://localhost:8082/code/* {\r\n\turi strip_prefix /code\r\n\treverse_proxy 127.0.0.1:8080\r\n}\r\n```\r\n4. navigate to [http://localhost:8082/code/](http://localhost:8082/code/) (trailing slash is important!) \r\n5. observe the update endpoint error in the browser console OR see the Request URL in the network tab (look for a request to `http://localhost:8082/update/check`)\r\n```javascript\r\nContent Security Policy: The page’s settings blocked the loading of a resource at http://localhost:8080/update/check (“connect-src”).\r\n```\r\n\r\n### Expected\r\n\r\nIt makes a request to the correct URL: `http://localhost:8082/code/update/check`\r\n\r\n### Actual \r\n\r\nIt makes a request to the wrong URL: `http://localhost:8082/update/check` (missing `/code`)\r\n\r\n\r\n### Investigation Notes\r\n\r\nBased on what I can tell, this is the line we need to change:\r\n```typescript\r\nreturn new URL(path.join('/', pathPrefix, pathname), remoteAuthority);\r\n```\r\nNotice the hard-coded `'/'`: that assumes we're always serving from the root but if we're using a reverse proxy and serving from a path like `/code` then this doesn't return the correct URL.","author":{"url":"https://github.com/jsjoeio","@type":"Person","name":"jsjoeio"},"datePublished":"2021-11-10T18:18:26Z","url":"https://github.com/coder/code-server/issues/4476"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b9ccd5f6-4d78-f5c7-b659-da54871fd577 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B04C:2C69FC:C704A5:109A8BC:6B01C9BE |
| html-safe-nonce | e6ce176daf1711c5304726d84d4a5d26629384c11d5662142c5669d5de18597b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMDRDOjJDNjlGQzpDNzA0QTU6MTA5QThCQzo2QjAxQzlCRSIsInZpc2l0b3JfaWQiOiIxODk3NDM2NjgyOTMzODg3MzQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 36054d6859d85962dc8213fc6efcbfb2cf006e57e8d9504591652d3932f6d6f0 |
| hovercard-subject-tag | issue:1050158317 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/coder/code-server/4476/issue_layout |
| twitter:image | https://opengraph.githubassets.com/bcbc4aa9a295c3502a625c2ab97e2b6b4561816a89710161d88f8240670acf85/coder/code-server/issues/4476 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/bcbc4aa9a295c3502a625c2ab97e2b6b4561816a89710161d88f8240670acf85/coder/code-server/issues/4476 |
| og:image:alt | What's the problem I'm solving? With the latest changes to use the upstream server in code-server, we're now running into Content-Security-Policy issues with our reverse proxy. The specific code we... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jsjoeio |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/coder/code-server git https://github.com/coder/code-server.git |
| octolytics-dimension-user_id | 95932066 |
| octolytics-dimension-user_login | coder |
| octolytics-dimension-repository_id | 172953845 |
| octolytics-dimension-repository_nwo | coder/code-server |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 172953845 |
| octolytics-dimension-repository_network_root_nwo | coder/code-server |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width