Repository navigation
feat: sign previews in from the dashboard with a host-bound token - #32522
DanielleMaywood wants to merge 1 commit into
Conversation
9b92249 to
24b45ed
Compare
|
/coder-agents-review |
|
Chat: Spend limit reached | View chat Review history
deep-review v0.13.1 | Round 10 | Last posted: Round 10, 64 findings (2 P2, 19 P3, 29 P4, 14 Nit), COMMENT. Review Finding inventoryFinding inventory: PR #32522Findings
Contested and acknowledgedCRF-70 (Nit, previews_test.go:196) and CRF-72 (P4, previews_test.go:262)
CRF-66 (P4, proxy.go:43) and CRF-67 (P4, previews.go:221)
CRF-45 (P3, previews.go:74) - whole-user key scope
CRF-46 (P4, preview.go:126) - port in exact host compare
CRF-56 (P3, previews.go:224) - same-site rule in handler
CRF-57 (Nit, previews.go:209) - "response title"
CRF-60 (P4, previews.go:224) - refusal under SameSite=None
CRF-61, CRF-62 (P4, tests) - CrossSite row and proxy refusal assertion
CRF-64 (P4, previews.go:163) - cross-site refusal Detail
CRF-40 (P3, codersdk/previews.go:12) - sign-in types reused by address endpoint
CRF-41 (P4, previewhost.go:192) - unreachable url.Parse branch
CRF-42 (P4, preview.go:139) - originLocalURL copy
CRF-43 (P4, previews_test.go:305) - inline key counts
CRF-45 (P3, previews.go:74) - whole-user key scope
CRF-46 (P4, preview.go:126) - port in exact host compare
CRF-50 (P4, previews.go:109) - ActionCreate on address endpoint
CRF-53 (Nit, codersdk/previews.go:49) - previewFrame name collision
CRF-5 (Nit, codersdk/previews.go:23) - omitempty on uuid.UUID RegionID
CRF-6 (Nit, previewhost.go:136) - "__Host-" literal duplication
CRF-13 (P3, preview.go:71) - expired sign-in param ignores valid cookie
CRF-17 (Nit, token.go:100) - Validate doc restates body
CRF-18 (P3, previewhost.go:132) - __Host- comment mechanism
CRF-19 (P4, workspaceapps.go:138) - createAppConnectKey doc lifetime
CRF-21 (P4, token.go:96) - inline time.Minute
CRF-22 (P4, token.go:102) - redundant Expiry nil check
CRF-23 (Nit, provider.go:42) - PreviewSessionCookie field name
CRF-25 (P4, provider.go:42) - empty cookie name in other callers
CRF-30 (P4, preview_test.go:473) and CRF-31 (P4, previews_test.go:108) - fake http.Response
CRF-33 (P4, previews.go:143) and CRF-34 (P4, previews.go:180) - error message wording
Law analysisR1: not run. Effective additions 805, below the 1000 threshold. Round logRound 1Netero first pass: 4 P3/P4, 2 Nit, 2 Note. No P0; panel proceeded. Round type: round 1, full panel. Multi-domain (security-sensitive token and cookie code): target 9-12. Cross-check:
Round 2 updateBLOCKED. Churn guard: 19 addressed (claimed, unverified by panel), 14 silent (CRF-5, CRF-6, CRF-13, CRF-17, CRF-18, CRF-19, CRF-21, CRF-22, CRF-23, CRF-25, CRF-30, CRF-31, CRF-33, CRF-34). No author replies. No review. Reviewed against 69ee6a9..3cbebe3. Effective additions grew 805 to 1560; Law and a full restructure panel are due on the next unblocked round. Round 3Panel (restructure: new address endpoint, effective additions 805 to 1560). Churn guard PROCEED: 14 findings contested by author replies. Round 4Fix round (no added files or new goal; effective additions 1560 to 1581). Churn guard PROCEED: 6 addressed, 1 acknowledged (CRF-46), 7 contested. Round 5Fix round (doc and errors.AsType changes only). Churn guard PROCEED: CRF-45 and CRF-46 accepted by the author as an operator decision; 5 contested; 4 addressed. Round 6Fix round (comment-only commit 588ce57). Churn guard PROCEED: 2 addressed, 2 contested. Round 7Fix round (comment-only commit 7cf249d). Churn guard PROCEED: 2 addressed, nothing contested. Round 8Fix round (rebase onto 4cae110; only coderd/previews_test.go changed: refusal rows call both endpoints, three tests merged into TestPreviewRegions). Churn guard PROCEED with no open findings. Round 9Fix round (rebase onto 327e5ed; previewHostingFor reads the proxy with the caller's context instead of AsSystemRestricted; tests run as a member and add a scoped-token proxy case; CRF-73 comment). Churn guard PROCEED: 1 addressed, 2 contested. Round 10Fix round (previewHostingFor back to AsSystemRestricted with sql.ErrNoRows; scoped-token proxy case expects success; CRF-73 and CRF-75 comments; RegionID omitzero). Churn guard PROCEED: 4 addressed. About deep-reviewCRF = Coder Review Finding (P0-P4, Nit, Note)
|
There was a problem hiding this comment.
This PR adds a dashboard sign-in endpoint that mints a host-bound, encrypted preview sign-in token, and a preview-host handler that trades it for a host-only session cookie. Findings: 2 P2, 14 P3, 12 P4, 5 Nit.
The two P2 findings are the host binding, which another user's token can pass, and the cookie's SameSite value, which breaks sign-in when the preview host is a different site from the dashboard.
Out of scope (needs a ticket or explicit acceptance by a human):
coderd/workspaceapps/provider.go:95: the signed app token cookie set on preview hosts also takes the deployment SameSite value, so a cross-site preview host would miss it on every request and re-issue a token each time.coderd/workspaceapps/proxy.go:326:handleAPIKeySmugglingalso redirects throughoriginLocalURL(r.URL.Path), so subdomain apps opened at a path with%2Fload a different path after app sign-in.coderd/workspaceapps/token.go:58:EncryptedAPIKeyPayloadis accepted for up to two minutes after minting (one-minute expiry plusjwt.DefaultLeeway), and nothing documents that window.coderd/workspaceapps/previewhost/previewhost.go:191:applyPolicydropsSet-Cookieheaders with aDomain, but preview scripts run withallow-same-originand can setdocument.cookiewithdomain=the app wildcard parent, including acoder_subdomain_app_session_token_*cookie on the user's other apps.coderd/workspaceapps.go:140:createAppConnectKeycomputes expiry withtime.Untilanddbtime.Now, notapi.Clock, so mock-clock tests cannot control the key lifetime.
Notes:
coderd/previews.go:126:payload.Subjectis set, butsignInPreviewandPreviewSignInPayload.Validatenever read it, while theAPIKeyfield doc says the key belongs to "the user in Subject".
coderd/httpapi/cookie.go:32
P3 [CRF-3] This PR makes the comment's reason false: the preview cookie's __Host- prefix now follows the hosting scheme, not the deployment host-prefix setting. (Netero)
With PreviewSessionTokenCookie removed from cookiesToPrefix, EnableHostPrefix has no effect on it. Stripping both names is still correct because both can exist after the access URL scheme changes; say that in the comment.
🤖
🤖 This review was automatically generated with Coder Agents.
| } | ||
| previewURL, err := hosting.URL(appurl.ApplicationURL{ | ||
| AppSlugOrPort: req.PreviewSlug, | ||
| AgentName: req.AgentName, |
There was a problem hiding this comment.
P2 [CRF-8] A token minted by one user passes the host check on another user's preview host. (Kurapika, Netero)
req.AgentName reaches hosting.URL unvalidated for file slugs, so AgentName = "dev--site--testuser.a.co:1" builds payload.Host = "preview--0123abcd--dev--site--testuser.a.co:1--w--atk.a.co", and appurl.HostnamesMatch runs net.SplitHostPort and drops everything after the last colon. Reproduced with a scratch test: user atk minted a token for workspace w, sent it to testuser's preview host, and got 303 with Set-Cookie: coder_preview_session_token=<atk's key>. Issue still refuses atk's key there, but a page that frames the victim's preview host with this token replaces the victim's preview cookie, and the preview returns errors until reopened. Check AgentName against the workspace's agents for every slug (or require hosting.Parse(previewURL.Host) to return the same ApplicationURL), and compare payload.Host to the request host exactly in signInPreview.
🤖
There was a problem hiding this comment.
Verified fixed in 3cbebe3321.
🤖
| // of h with apiKey. It has no Domain, so it stays on that host. Over plain | ||
| // HTTP, where browsers reject Secure from most hosts, Secure follows cfg. | ||
| func (h *Hosting) SessionCookie(apiKey string, cfg codersdk.HTTPCookieConfig) *http.Cookie { | ||
| cookie := cfg.Apply(&http.Cookie{ |
There was a problem hiding this comment.
P2 [CRF-9] The preview session cookie takes SameSite from --samesite-auth-cookie (default lax), so browsers neither store nor send it when the preview host is a different site from the dashboard. (Razor, Ryosuke, Melody, Pariston, Mafuuu, Bisky, Meruem, Hisoka)
The sign-in and every later preview request run inside the dashboard iframe (servePreview refuses Sec-Fetch-Dest: document), and previewHostingFor accepts a primary wildcard or a proxy WildcardHostname on another registrable domain. Reproduced with Playwright Chromium: a page on coder.a.test framing a host that sets a SameSite=Lax cookie and 303s gets the cookie back on p.apps.a.test and not on p.apps-b.test, so on such a deployment every preview ends at the 401 "Reopen this preview" page. The tests use Go HTTP clients and a zero cookie config, so they cannot catch this. Either refuse non-same-site regions in previewHostingFor with an error that names the requirement, or set SameSite=None; Secure; Partitioned on HTTPS and document that browsers blocking third-party cookies still fail.
🤖
There was a problem hiding this comment.
The same-site check covers workspace proxies only. The primary branch of previewHostingFor (coderd/previews.go:208) returns api.previewHosting without the registrableDomain comparison, and coderd.go:748 builds it with no site check. A scratch test with access URL https://dashboard.test.coder.com and AppHostname: *.apps.example.net got 200 from PreviewSignIn and minted a key; in the browser the cookie is dropped, the 401 page asks the dashboard to sign in again, and each retry mints another key. Run the comparison in previewhost.Strict (all three callers pass dashboardURL) so the primary records it in previewsUnavailable, and add a primary cross-site test row. (Ryosuke, Melody, Pariston, Bisky, Razor, Mafu-san, Knov, Kite, Mafuuu, Meruem, Hisoka)
🤖
There was a problem hiding this comment.
Fixed in 5421940: sign-in now refuses a primary region whose wildcard access URL is on another site with 400 "Previews need a wildcard access URL on the same site as the dashboard." from both endpoints and mints no key, and a cross-site proxy gets its own 400 "Previews need a workspace proxy on the same site as the dashboard."; TestPreviewSignInUnavailable/CrossSite and TestPreviewSignInRegions cover both.
There was a problem hiding this comment.
Verified fixed in 5421940ac8.
🤖
| return | ||
| } | ||
|
|
||
| key, err := api.createAppConnectKey(ctx, apiKey) |
There was a problem hiding this comment.
P3 [CRF-10] Every sign-in mints a new application_connect key with whole-user scope and up to Sessions.DefaultDuration lifetime, and the key it replaces in the preview cookie stays valid. (Pariston, Kurapika, Ryosuke, Mafuuu)
The dashboard cannot read the preview host's HttpOnly cookie, so it must call this endpoint each time it frames a preview, and preview hosts are per preview ID; workspaceApplicationAuth mints a key only when an app host has no session. Each open therefore adds an api_keys row that lives up to 24h by default and opens every app the owner can reach, and the one-minute token can be replayed within its window to obtain it. Give this key a lifetime bounded to preview use, or skip minting when the host already holds a valid key for the same user.
🤖
There was a problem hiding this comment.
Verified fixed in 3cbebe3321.
🤖
| } | ||
| // A preview runs agent-written code as whoever opens it, so only the | ||
| // workspace owner may, even when the workspace is shared. | ||
| if workspace.OwnerID != apiKey.UserID { |
There was a problem hiding this comment.
P3 [CRF-11] The owner-only and port forwarding checks here copy the rules Issue enforces at coderd/workspaceapps/db.go:189-195, using a different agent lookup. (Ryosuke, Meruem, Pariston)
This handler matches req.AgentName exactly against GetWorkspaceAgentsInLatestBuildByWorkspaceID and only for port slugs, while Issue resolves the agent through Request.getDatabase; the two already disagree for an unknown agent on a file slug. When a rule changes in one copy, the endpoint mints keys for previews that Issue refuses, or refuses previews Issue would serve, and no test compares them. Move the rules into one workspaceapps function and call it from both places.
🤖
There was a problem hiding this comment.
Verified fixed in 3cbebe3321.
🤖
|
|
||
| http.SetCookie(rw, s.Previews.SessionCookie(payload.APIKey, s.CookiesConfig)) | ||
|
|
||
| redirectURL := originLocalURL(r.URL.Path) |
There was a problem hiding this comment.
P3 [CRF-12] The post-sign-in redirect is built from the decoded r.URL.Path, so /files/a%2Fb.html reloads as /files/a/b.html. (Mafuuu, Hisoka, Razor)
Hosting.URL keeps RawPath in the URL it signs, but originLocalURL(r.URL.Path) drops it; verified that originLocalURL on /files/a%2Fb.html returns /files/a/b.html. A preview server that routes on escaped segments serves a different resource than the one requested. Build the redirect from r.URL.EscapedPath() with the same leading-slash trimming.
🤖
There was a problem hiding this comment.
Verified fixed in 3cbebe3321.
🤖
| hosting, err := api.previewHostingFor(ctx, req.RegionID) | ||
| if err != nil { | ||
| httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ | ||
| Message: "This region does not serve previews.", |
There was a problem hiding this comment.
P3 [CRF-1] Every previewHostingFor error becomes 400 "This region does not serve previews.", including database failures. (Netero)
A lost connection or canceled context from GetWorkspaceProxyByID answers 400 with the raw database error in Detail, while the rest of this handler answers such errors with httpapi.InternalServerError. Return 400 for sql.ErrNoRows, a deleted proxy, and a missing wildcard hostname, and 500 for every other error.
🤖
There was a problem hiding this comment.
Verified fixed in 3cbebe3321.
🤖
| return | ||
| } | ||
|
|
||
| // The direct-open redirect above already answered page loads, so a |
There was a problem hiding this comment.
P3 [CRF-2] The comment refers to "the direct-open redirect above", but the code above refuses page loads with a 403 error page. (Netero)
Say "The page-load refusal above".
🤖
There was a problem hiding this comment.
Verified fixed in 3cbebe3321.
🤖
| // Workspace proxies always host previews in strict mode. | ||
| func (api *API) previewHostingFor(ctx context.Context, regionID uuid.UUID) (*previewhost.Hosting, error) { | ||
| if regionID == uuid.Nil || regionID.String() == api.DeploymentID { | ||
| if api.previewHosting == nil { |
There was a problem hiding this comment.
P4 [CRF-4] The primary-without-wildcard branch and the deleted or no-wildcard proxy branch of previewHostingFor have no test. (Netero)
Verified with -coverprofile: blocks at previews.go:153 and :164 have count 0. If the proxy.Deleted check is removed, a deleted proxy's hostname gets a sign-in token and no test fails.
🤖
There was a problem hiding this comment.
Verified fixed in 3cbebe3321.
🤖
| URLPath string `json:"url_path,omitempty"` | ||
| // RegionID picks the primary or a workspace proxy. Empty picks the | ||
| // primary. | ||
| RegionID uuid.UUID `json:"region_id,omitempty" format:"uuid"` |
There was a problem hiding this comment.
Nit [CRF-5] omitempty on RegionID uuid.UUID has no effect: uuid.UUID is a [16]byte array, so it is always sent as the zero UUID. (Netero)
Drop omitempty, or use *uuid.UUID if the field should be omitted.
🤖
There was a problem hiding this comment.
Not a bug: the tag makes the generated TypeScript field optional (readonly region_id?: string), as it does for the other uuid.UUID fields with omitempty in codersdk.
There was a problem hiding this comment.
Defense accepted.
🤖
There was a problem hiding this comment.
New evidence against the round 3 defense: guts also marks omitzero fields optional (convert.go:816 in v1.7.0 checks omitempty || omitzero), and codersdk already uses uuid.UUID with omitzero (codersdk/agentsdk/agentsdk.go:896, codersdk/chats.go:735). json.Marshal(codersdk.PreviewSignInRequest{}) still produces "region_id":"00000000-0000-0000-0000-000000000000". Use json:"region_id,omitzero" (Go 1.24+), which keeps readonly region_id?: string and actually omits the field. (Ging-Go)
🤖
There was a problem hiding this comment.
Fixed in aa2ba14: thanks for the new evidence. region_id now uses omitzero, so a zero region is omitted; the generated TypeScript stays region_id?: string.
There was a problem hiding this comment.
Verified fixed in aa2ba145ea.
🤖
| // parent domain, such as by another preview. | ||
| func (h *Hosting) SessionCookieName() string { | ||
| if h.scheme == "https" { | ||
| return "__Host-" + codersdk.PreviewSessionTokenCookie |
There was a problem hiding this comment.
Nit [CRF-6] The literal "__Host-" duplicates codersdk.cookieHostPrefix, and coderd/httpapi/cookie.go:34 has a third copy. (Netero)
Export the codersdk constant and use it in both places.
🤖
There was a problem hiding this comment.
Declined: exporting codersdk.cookieHostPrefix widens the SDK API for one string literal; cheap to revisit.
There was a problem hiding this comment.
Defense accepted.
🤖
24b45ed to
c8d90ac
Compare
b5aeb4e to
8ef1834
Compare
8ef1834 to
d20b13b
Compare
d20b13b to
13255ec
Compare
7e0d8c7 to
c9d354e
Compare
c9d354e to
f7708c9
Compare
|
/coder-agents-review |
There was a problem hiding this comment.
This rebase changes only coderd/previews_test.go: refusal cases now call both endpoints, and three region tests are merged into TestPreviewRegions. Findings this round: 1 P4, 2 Nit, all in test comments and names.
The merged test keeps every case from the three tests it replaces, and the primary cross-site row is now cross-site by construction. No production code changed since round 7. CI for 9aae1d9d33 has no completed result: the failed jobs that were checked (changes, Flake Check, lint, fmt) are cancelled runs with no failed step.
🤖 This review was automatically generated with Coder Agents.
| if tc.client != nil { | ||
| c = tc.client | ||
| } | ||
| // The address endpoint refuses what sign-in refuses. |
There was a problem hiding this comment.
Nit [CRF-70] "The address endpoint refuses what sign-in refuses." now restates the loop below it. (Gon)
In the old TestPreviewAddress it explained a single PreviewAddress call; here both endpoints are called with the same req and checked against the same tc.wantStatus, so the code says it. Delete the comment.
🤖
There was a problem hiding this comment.
Declined: the loop calls both endpoints, but the comment states the rule the test exists for (the address endpoint refuses what sign-in refuses), which a reader would otherwise have to infer from the shared req.
There was a problem hiding this comment.
Defense accepted.
🤖
|
|
||
| const apps = "*.apps.test.coder.com" | ||
| const regionRefused = "This region does not serve previews." | ||
| const hostPrefixOff = "Previews require --host-prefix-cookie. An administrator can enable it." |
There was a problem hiding this comment.
P4 [CRF-72] The constant hostPrefixOff holds an error message, and the table field hostPrefixOff is a bool, so rows read hostPrefixOff: true, ..., wantMessage: hostPrefixOff. (Gon)
A reader has to work out that the key is the field and the value is the constant. Rename the constants to hostPrefixRequiredMessage and regionRefusedMessage.
🤖
There was a problem hiding this comment.
Declined: the table field and the constant share a name because each row that sets the flag also expects that message, and the constant is declared three lines above the table, so a reader finds which is which immediately.
There was a problem hiding this comment.
Defense accepted.
🤖
| dv := coderdtest.DeploymentValues(t) | ||
| dv.Experiments = []string{string(codersdk.ExperimentOpenPreview)} | ||
| dv.HTTPCookies.EnableHostPrefix = !tc.hostPrefixOff | ||
| // The port checks that same-site comparisons ignore it. |
There was a problem hiding this comment.
Nit [CRF-73] "The port checks that same-site comparisons ignore it." reads as the noun phrase "the port checks", and it omits that the Primary row's wantOrigin also relies on :8443. (Leorio, Gon)
Someone simplifying the setup could drop the port and break Primary without knowing why. Say what each row needs, for example: "The dashboard's :8443 port makes the Proxy row fail if the same-site check compares ports, and the Primary row expects the port in its origin."
🤖
There was a problem hiding this comment.
Fixed in 4f68cc0: the comment now says the :8443 port makes the Proxy row fail if the same-site check compares ports, and that the Primary row expects the port in its origin.
There was a problem hiding this comment.
The Primary row also depends on the port being ignored: previewHostingFor compares registrableDomain of *.apps.test.coder.com with the :8443 access URL, so a port-comparing check fails both successful rows, not only Proxy. Say "makes the Primary and Proxy rows fail if the same-site check compares ports, and the Primary row expects the port in its origin." (Gon)
🤖
There was a problem hiding this comment.
Fixed in aa2ba14: the comment now says the :8443 port makes the Primary and Proxy rows fail if the same-site check compares ports.
There was a problem hiding this comment.
Verified fixed in aa2ba145ea.
🤖
9aae1d9 to
4f68cc0
Compare
|
/coder-agents-review |
There was a problem hiding this comment.
This rebase changes previewHostingFor to read the workspace proxy with the caller's context instead of AsSystemRestricted, runs the region tests as a member, and adds a scoped-token proxy case. Findings this round: 1 P3, 1 Nit new; 1 P4 and 1 Nit re-raised.
The caller-context read blocks every scoped token from every proxy region with a message that says the proxy is missing, while the regions endpoint and app sign-in read proxies as the system. The omitempty on RegionID is re-raised because omitzero keeps the TypeScript field optional and also omits it. Two contested findings are closed.
Out of scope (needs a ticket or explicit acceptance by a human):
enterprise/coderd/workspaceproxy.go:64: thefetchRegionscomment says users cannot usually access workspace proxies, butmemberRolegrants every member read on them, so a reader would wrongly expect the new caller-context read to refuse members.
CI: the failed jobs that were checked (changes, fmt, test-go-pg) are cancelled runs, so 4f68cc01bd has no completed CI result yet.
🤖 This review was automatically generated with Coder Agents.
| // such as through a token scope without workspace_proxy:read, counts as | ||
| // unknown. | ||
| proxy, err := api.Database.GetWorkspaceProxyByID(ctx, regionID) | ||
| if httpapi.Is404Error(err) { |
There was a problem hiding this comment.
P3 [CRF-74] Reading the proxy with the caller's context refuses every scoped token for every proxy region, and the response says the proxy does not exist. (Razor, Gon, Leorio, Ryosuke, Bisky, Chopper)
httpapi.Is404Error matches dbauthz denials, so a token without workspace_proxy:read gets 400 "This region does not serve previews." with Detail "no workspace proxy has ID ...: choose another region" (reproduced in the new TestPreviewSignInScopedToken case), and CreateToken rejects workspace_proxy:read as internal, so no narrower-than-all token can ever pass. The read protects no data: fetchRegions (enterprise/coderd/workspaceproxy.go:67) lists every proxy's URL and wildcard under AsSystemRestricted, and workspaceApplicationAuth looks proxies up the same way, so the same token can open ordinary apps on that proxy but not previews. Either read the proxy as fetchRegions does and expect success in the scoped case, or keep the caller read and return a distinct refusal that does not claim the proxy is missing, and assert its exact message at previews_test.go:433.
🤖
There was a problem hiding this comment.
Fixed in aa2ba14: you are right that no public scope can carry workspace_proxy:read and that the read protects no data. The proxy lookup reads as the system again, like the regions endpoint and app sign-in, and TestPreviewSignInScopedToken now expects a coder:workspaces.access token to sign in to a proxy region (it fails if the lookup uses the caller context).
There was a problem hiding this comment.
Verified fixed in aa2ba145ea.
🤖
| require.NoError(t, signIn(uuid.Nil, codersdk.APIKeyScopeCoderWorkspacesAccess, codersdk.APIKeyScopeApiKeyCreate)) | ||
| require.Equal(t, 1, appConnectKeys(ctx, t, api.Database, first.UserID)) | ||
|
|
||
| // The scope cannot read workspace proxies, so a proxy region is refused. |
There was a problem hiding this comment.
Nit [CRF-75] "The scope cannot read workspace proxies" credits the scope alone, but the token's allow list also blocks the read, and either one produces the 400. (Bisky)
Verified by temporary edits: APIKeyScopeAll with this allow still gets 400, and so does the workspaces-access scope with a proxy allow target; only both together get 200. Say "Neither the scope nor the allow list grants workspace_proxy:read".
🤖
There was a problem hiding this comment.
Fixed in aa2ba14: that refusal is gone, and the comment above the new proxy-region success now says no public scope grants workspace_proxy:read.
There was a problem hiding this comment.
The new comment says "No public scope grants workspace_proxy:read", which is false for coder:all (see CRF-77), and it still leaves out the allow list: in round 9, APIKeyScopeAll with this token's allow also got 400. Say "No public low-level scope grants workspace_proxy:read, and the allow list has no proxy entry, so the token signs in to a proxy region only because the lookup needs neither." (Gon)
🤖
There was a problem hiding this comment.
Fixed in cb551b7: the test comment now says no public low-level scope grants workspace_proxy:read and the allow list has no proxy entry, so the token signs in to a proxy region only because the lookup needs neither.
4f68cc0 to
aa2ba14
Compare
|
/coder-agents-review |
There was a problem hiding this comment.
The proxy lookup reads as the system again, and the CRF-74, CRF-73 and CRF-5 fixes are verified: go test ./coderd -run TestPreview passes, the scoped-token proxy case fails if the caller-context read returns (it got 400 in round 9), and regenerating the TypeScript types keeps region_id?: string. Findings this round: 1 Nit new, 1 Nit re-raised. Both are comments that say no public scope grants workspace_proxy:read, which is false for coder:all.
CI at aa2ba145ea: 15 passed, 12 skipped, 5 still running, none failed.
🤖 This review was automatically generated with Coder Agents.
| return api.previewHosting, nil | ||
| } | ||
|
|
||
| // The regions endpoint and app sign-in read proxies the same way, so a |
There was a problem hiding this comment.
Nit [CRF-77] "a scoped token, which can never hold workspace_proxy:read" is false: the public coder:all scope grants it. (Gon)
IsExternalScope accepts ScopeAll (coderd/rbac/scopes_catalog.go), and its role grants ResourceWildcard.Type: {policy.WildcardSymbol} (coderd/rbac/scopes.go:81-82). The claim the code relies on is narrower: no public low-level scope grants workspace_proxy:read. Say "No public low-level scope grants workspace_proxy:read, so reading with the caller's context would refuse every proxy region to a token limited to those scopes."
🤖
There was a problem hiding this comment.
Fixed in cb551b7: the comment now says no public low-level scope grants workspace_proxy:read (the all scope does), so reading as the caller would refuse scoped tokens that ordinary apps accept.
aa2ba14 to
cb551b7
Compare
|
/coder-agents-review |
|
@DanielleMaywood ⛔ This review has reached its per-chat spend limit ($107.08 / $100.00). Further review rounds are paused. To raise the limit and continue, comment: This is a per-chat budget, separate from any account-level usage limit.
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cb551b7f0c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| Path: "/" + strings.TrimLeft(r.URL.Path, `/\`), | ||
| RawPath: "/" + strings.TrimLeft(r.URL.EscapedPath(), `/\`), |
There was a problem hiding this comment.
Preserve an encoded leading slash during sign-in
When url_path begins with an encoded slash, such as /%2Fadmin, net/http exposes r.URL.Path as //admin while EscapedPath() remains /%2Fadmin. Trimming the decoded path changes it to /admin, so the supplied RawPath no longer encodes Path; url.URL.String() consequently discards RawPath and redirects to /admin. Since CheckURLPath accepts this input, sign-in silently opens a different application route. Preserve matching decoded and escaped paths, or reject an encoded leading slash.
Useful? React with 👍 / 👎.
| if registrableDomain(strings.Replace(proxy.WildcardHostname, "*", "preview", 1)) != registrableDomain(api.AccessURL.Host) { | ||
| return nil, crossSiteError("Previews need a workspace proxy on the same site as the dashboard.") |
There was a problem hiding this comment.
Include the scheme when validating a proxy's site
When the dashboard and workspace proxy share a registrable domain but use different schemes, this check accepts the region even though browsers treat them as different schemeful sites. An HTTPS dashboard cannot frame an HTTP proxy because the iframe is active mixed content; in the inverse configuration, the default SameSite=Lax preview cookie is not sent in the cross-site iframe. The endpoint therefore returns a successful but unusable preview URL, so the proxy scheme should also match the dashboard scheme.
Useful? React with 👍 / 👎.
cb551b7 to
ca2cc97
Compare
ca2cc97 to
659491c
Compare
db90c9e to
162a9ad
Compare
Adds POST /api/experimental/previews/sign-in, which returns the preview URL with a one-minute token bound to the exact preview host. The preview host exchanges it for a host-only session cookie and never accepts the wildcard app cookie, so a preview cannot replace the user's app sign-in. POST /api/experimental/previews/address returns the same preview address without minting a token, so the dashboard can load the preview with an existing preview session first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
162a9ad to
2a170aa
Compare
Main's app sign-in (
/api/v2/applications/auth-redirect) sets one cookie on the whole wildcard domain, which every subdomain app receives. A preview page must not share that cookie, so each preview gets a host-only cookie and a sign-in token bound to its exact host.Sign-in reuses main's minting, scopes and app encryption key, so workspace proxies need no new keys or RPCs. The dashboard calls it from the chat only when the preview host reports no session, and the separate address endpoint mints nothing, so reopening a signed-in preview creates no API key.
Implementation details
Adds two endpoints.
POST /api/experimental/previews/addressreturns a preview's URL, origin and sandbox without minting anything, so the dashboard can load a preview with an existing session.POST /api/experimental/previews/sign-insigns the workspace owner in to one preview host, and the dashboard calls it only when the preview host reports that it has no session. Coderd checks the experiment and that the caller owns the workspace, mints anapplication_connectkey, and returns the preview URL with a sign-in token encrypted under the existing workspace apps key. The token's audience iscoder_previewand it names the exact preview host. It is valid for one minute, plus up to one minute of clock leeway between coderd and the server that checks it.The preview host checks the token's host, sets a host-only session cookie (
__Host-coder_preview_session_tokenwithSecureon HTTPS, whatever--secure-auth-cookiesays, andcoder_preview_session_tokenon plain HTTP), and redirects to its own origin withReferrer-Policy: no-referrer, keeping the path's escaping, such as%2F. Workspace proxies decrypt the token with the key they already fetch, so they need no new keys or RPCs. This relies on #32439, where preview hosts refuse the app sign-in parameter, so a preview cannot replace the user's app sign-in for their other apps, and answer a preview without a session with a 401 page.Sign-in refuses a region whose preview hosts are not on the dashboard's site, the primary's wildcard access URL or a workspace proxy's, because browsers would not send the preview's
SameSite=Laxsession cookie from the dashboard's frame. A region that cannot serve previews gets a 400, and a failed region lookup a 500.url_pathmust passpreviewhost.CheckURLPath, which the tool shares, so its path cannot carry bad percent-encoding, and it cannot carry a query parameter the preview host reads itself. Both endpoints run the same checks. With the experiment off they return 404, and without--host-prefix-cookiethey return 400 "Previews require --host-prefix-cookie. An administrator can enable it." and mint nothing.Stack (review bottom-up). Replaces the closed #31282 stack. Security review: coder/security-assessments#437.
🤖 Generated with Claude Code