Skip to content

fix: key every per-deployment store by origin - #1176

Merged
EhabY merged 2 commits into
mainfrom
fix/origin-keyed-stores
Nov 11, 2026
Merged

EhabY merged 2 commits into
mainfrom
fix/origin-keyed-stores

Conversation

@EhabY

@EhabY EhabY commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Every per-deployment store was keyed by hostname, so two deployments on one host with a different scheme or port shared sessions, OAuth client registrations, CLI config directories, SSH hosts, and the CLI binary cache. Signing in or out of one overwrote the other, and a window could connect to the wrong deployment. This builds on #1173, which made the origin the deployment's identity.

toSafeHost(url) now returns an origin label that every store already keys on:

Origin Label
https://host, https://host:443 host (unchanged)
https://host:8443 https_host_8443
http://host, http://host:80 http_host_
http://host:8080 http_host_8080
https://my_host https_my_host_

Labels read scheme_host_port in URL order, with an empty default port. Explicit default ports are dropped by URL parsing. Only the bare host lacks _, schemes contain none, and the port after the last _ is digits or empty, so labels are unambiguous. A test checks every pair across schemes, ports, and look-alike hostnames: two URLs share a label exactly when they share an origin. Window addresses parse as before. The sign-in dialog refuses a URL for another origin, and getSessionAuth stays only for label-only callers. Deployment URLs other than http(s) are rejected by validateDeploymentUrl.

Migration: HTTPS on port 443 is unchanged. Other origins sign in once more and download the CLI again. Old recent workspaces and links for them now point at the HTTPS origin; reopen them from the Coder sidebar.

Comment thread src/common/url.ts Resolved
Comment thread src/common/url.ts Resolved
Comment thread src/common/url.ts Resolved
@EhabY
EhabY force-pushed the fix/origin-keyed-stores branch from 8e14148 to 2a1d3c2 Compare November 9, 2026 09:38
@EhabY
EhabY requested a review from code-asher November 9, 2026 09:59
EhabY added 2 commits November 9, 2026 13:17
toSafeHost returns an origin label (host for HTTPS on 443, else
host_<scheme><port>), so sessions, OAuth client registrations, CLI
config directories, SSH hosts, and the binary cache are per origin.

- Ignore entries an older version stored under the bare hostname for
  another origin; re-derive the saved deployment's label from its URL.
- Refuse another origin in the sign-in dialog before signing in.
- Keep getSessionAuth for label-only callers; the rest look up by URL.
- Label non-default origins as `scheme_host_port` (`https_host_8443`,
  `http_host_`); HTTPS on its default port keeps the bare hostname.
- Validate only the hostname, so errors name the user's hostname.
- Reject non-http(s) deployment URLs in validateDeploymentUrl instead of
  toSafeHost.
@EhabY
EhabY force-pushed the fix/origin-keyed-stores branch from 51cc10f to 363e7c1 Compare November 9, 2026 10:21
@linear-code

linear-code Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

@EhabY
EhabY merged commit 17e1d9a into main Nov 11, 2026
11 of 12 checks passed
@EhabY
EhabY deleted the fix/origin-keyed-stores branch November 11, 2026 11:45
@EhabY EhabY mentioned this pull request Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants