Title: Workspace applications CORS handling prevents external requests to apps · Issue #15096 · coder/coder · GitHub
Open Graph Title: Workspace applications CORS handling prevents external requests to apps · Issue #15096 · coder/coder
X Title: Workspace applications CORS handling prevents external requests to apps · Issue #15096 · coder/coder
Description: Problem External requests to a Coder app will always fail. Workspace apps cannot make requests to each other if they are owned by different users. Explanation of why As coder stands today (v2.15.3), we allow cross domain requests between...
Open Graph Description: Problem External requests to a Coder app will always fail. Workspace apps cannot make requests to each other if they are owned by different users. Explanation of why As coder stands today (v2.15.3)...
X Description: Problem External requests to a Coder app will always fail. Workspace apps cannot make requests to each other if they are owned by different users. Explanation of why As coder stands today (v2.15.3)...
Opengraph URL: https://github.com/coder/coder/issues/15096
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Workspace applications CORS handling prevents external requests to apps","articleBody":"# Problem\n\n- External requests to a Coder app will always fail. \n- Workspace apps cannot make requests to each other if they are owned by different users.\n\n# Explanation of why\n\nAs coder stands today (v2.15.3), we allow cross domain requests between workspace apps of the same user. Meaning you could host a backend webserver on workspace A, and host the frontend on workspace B. As long as the workspaces are owned by the same user, all web requests will function correctly (assuming `credentials: \"include\"`).\n\nThis is all handled magically here https://github.com/coder/coder/blob/eb1602bba472f2cb4eff9c8cac58c5b69356052c/coderd/httpmw/cors.go#L47-L75\n\n\nThis allows basic intuitive functionality. By handling this for the user's, we can address some of the nuanced CORS behaviors within Coder. For example, the most common answer on solving CORS is `Access-Control-Allow-Origin: *`. This **will not work** for an application in Coder. All Coder apps require Coder authentication via a cookie, and [credentials are not supported if CORS is set to `*`](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors/CORSNotSupportingCredentials).\n\n\u003ctable class=\"tg\">\n\u003cthead>\n \u003ctr>\n \u003cth class=\"tg-0pky\" rowspan=\"2\">\u003c/th>\n \u003cth class=\"tg-0pky\" rowspan=\"3\">\u003c/th>\n \u003cth class=\"tg-0pky\">From\u003c/th>\n \u003cth class=\"tg-0pky\" colspan=\"3\">Alice\u003c/th>\n \u003cth class=\"tg-0pky\">Bob\u003c/th>\n \u003c/tr>\n \u003ctr>\n \u003cth class=\"tg-0pky\" rowspan=\"2\">\u003c/th>\n \u003cth class=\"tg-0pky\">Workspace 1\u003c/th>\n \u003cth class=\"tg-0pky\" colspan=\"2\">Workspace 2\u003c/th>\n \u003cth class=\"tg-0pky\">Workspace 3\u003c/th>\n \u003c/tr>\n \u003ctr>\n \u003cth class=\"tg-0pky\">To\u003c/th>\n \u003cth class=\"tg-0pky\">App A\u003c/th>\n \u003cth class=\"tg-0pky\">App B\u003c/th>\n \u003cth class=\"tg-0pky\">App C\u003c/th>\n \u003cth class=\"tg-0pky\">App D\u003c/th>\n \u003c/tr>\n\u003c/thead>\n\u003ctbody>\n \u003ctr>\n \u003ctd class=\"tg-0pky\" rowspan=\"3\">Alice\u003c/td>\n \u003ctd class=\"tg-0pky\" rowspan=\"2\">Workspace 1\u003c/td>\n \u003ctd class=\"tg-0pky\">App A\u003c/td>\n \u003ctd class=\"tg-0pky\">✅\u003c/td>\n \u003ctd class=\"tg-0pky\">✅\u003cspan style=\"font-weight:400;font-style:normal\">*\u003c/span>\u003c/td>\n \u003ctd class=\"tg-0pky\">✅\u003cspan style=\"font-weight:400;font-style:normal\">*\u003c/span>\u003c/td>\n \u003ctd class=\"tg-0pky\">❌\u003c/td>\n \u003c/tr>\n \u003ctr>\n \u003ctd class=\"tg-0pky\">App B\u003c/td>\n \u003ctd class=\"tg-0pky\">✅*\u003c/td>\n \u003ctd class=\"tg-0pky\">✅\u003c/td>\n \u003ctd class=\"tg-0pky\">✅\u003cspan style=\"font-weight:400;font-style:normal\">*\u003c/span>\u003c/td>\n \u003ctd class=\"tg-0pky\">❌\u003c/td>\n \u003c/tr>\n \u003ctr>\n \u003ctd class=\"tg-0pky\">Workspace 2\u003c/td>\n \u003ctd class=\"tg-0pky\">App C\u003c/td>\n \u003ctd class=\"tg-0pky\">✅\u003cspan style=\"font-weight:400;font-style:normal\">*\u003c/span>\u003c/td>\n \u003ctd class=\"tg-0pky\">✅\u003cspan style=\"font-weight:400;font-style:normal\">*\u003c/span>\u003c/td>\n \u003ctd class=\"tg-0pky\">✅\u003c/td>\n \u003ctd class=\"tg-0pky\">❌\u003c/td>\n \u003c/tr>\n \u003ctr>\n \u003ctd class=\"tg-0pky\">Bob\u003c/td>\n \u003ctd class=\"tg-0pky\">Workspace 3\u003c/td>\n \u003ctd class=\"tg-0pky\">App D\u003c/td>\n \u003ctd class=\"tg-0pky\">❌\u003c/td>\n \u003ctd class=\"tg-0pky\">❌\u003c/td>\n \u003ctd class=\"tg-0pky\">❌\u003c/td>\n \u003ctd class=\"tg-0pky\">✅\u003c/td>\n \u003c/tr>\n\u003c/tbody>\n\u003c/table>\n\n\n## 🚫 What is the status quo?\n\nThe status quo is that **Coder manages CORS requests between apps**. This approach has generally lead to less customer support tickets on how to handle CORS.\n\nWe currently do not allow requests between different users. This does not appear to be because of huge security risk. Subdomain apps are given very limited session tokens that only allow workspace app connections. There is a risk that someone could steal this token and go to other apps by the user, but they cannot interact with other Coder resources.\n\n### Solution #1 Solve it in Coder (INCOMPLETE SOLUTION)\n\nWe can adjust the table above to include cross user requests. This would expand the security surface by default, which although attacks are limited in escalation, providing this by default seems insecure.\n\nIt also does not handle requests external to Coder. External requests **must** be supported by public shared apps to handle the use cases requested.\n\n### 🚫 Solution #2 Suggest workarounds (Not always possible)\n\nInstead of allowing cross site requests, the user could deploy a local webserver to proxy requests to the second user's app.\n\nMany frontend servers have this as a feature:\n- [Vite `server.proxy`](https://vite.dev/config/server-options#server-proxy)\n- [NextJS rewrites](https://nextjs.org/docs/pages/api-reference/next-config-js/rewrites)\n\nIf the web app in question has a backend server, then the backend server can proxy traffic to avoid CORS issues.\n\n### ❓ Solution #3 Disable CORS handling by Coder\n\nThe best option is to disable our custom CORS handling and defer to the workspace app. There is a few ways we could maybe do this:\n\n**Disable at the deployment level.** \n - Adds another server flag 👎 \n - Breaks the QOL behavior for likely 1 use case 👎 \n - Easy to switch behavior without any state (db) lookups 👍 \n \n**Disable at the app level**\n - Could configure in terraform per app 👍 \n - Have to do a db lookup on requests or maintain a cache 👎 \n \n**Disable based on response headers.**\nGiven CORS requests are preflight requests, can we do this? Can we pass the preflight to the workspace app, get the headers. If CORS headers are present, return as is. If they are not, add them to the response? Then we just defer to the app if they configure it themselves. No Coder config necessary.\n\n## Final thoughts\n\nWhen workspace sharing becomes a feature, this use case might show up more.\n\n## Implementation notes\n\nThe implementation cannot be configured at the workspace, template, or user level. To be configured there, an in memory cache would be required.\n\nThe requirements to a solution cannot require a database lookup on each request. That would cause too many database calls for web apps with hundreds of static resources.\n\nThe only input information on each request you get from making a request from app A to app B.\n- The origin, `https://8002--\u003cagent>--\u003cworkspace>--\u003cuser_A>--apps.coder.com/`\n- The request to B, `https://8002--\u003cagent>--\u003cworkspace>--\u003cuser_B>--apps.coder.com/` with cookies for the app B\n\n---\n\nRelated Links: \n- https://github.com/coder/coder/pull/7688\n- https://github.com/coder/coder/issues/5706\n- https://github.com/coder/coder/pull/8057","author":{"url":"https://github.com/Emyrk","@type":"Person","name":"Emyrk"},"datePublished":"2024-10-15T20:40:45Z","url":"https://github.com/coder/coder/issues/15096"}
| 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:af4edfc1-50f6-7662-b038-d14bf6587cba |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E2A0:3A4875:1B3051B:2433587:6B015C3A |
| html-safe-nonce | 6f0775edbadf38d84ee4f5fdccc92d5ab864df7c3cfe487e1c5a08bf32164a91 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMkEwOjNBNDg3NToxQjMwNTFCOjI0MzM1ODc6NkIwMTVDM0EiLCJ2aXNpdG9yX2lkIjoiMzU3MzY1NDY5NzUxMDI2Mzg2NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 16da81f73f8a87a89df0316ebf98cc1e34e556f110f58ed243101781ed7a8876 |
| hovercard-subject-tag | issue:2589850983 |
| 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/coder/15096/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2599b7ef8eec9b124f598daf078c5715d8de9b23df875a9e542c3467055aa466/coder/coder/issues/15096 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2599b7ef8eec9b124f598daf078c5715d8de9b23df875a9e542c3467055aa466/coder/coder/issues/15096 |
| og:image:alt | Problem External requests to a Coder app will always fail. Workspace apps cannot make requests to each other if they are owned by different users. Explanation of why As coder stands today (v2.15.3)... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Emyrk |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/coder/coder git https://github.com/coder/coder.git |
| octolytics-dimension-user_id | 95932066 |
| octolytics-dimension-user_login | coder |
| octolytics-dimension-repository_id | 440752086 |
| octolytics-dimension-repository_nwo | coder/coder |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 440752086 |
| octolytics-dimension-repository_network_root_nwo | coder/coder |
| 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