Skip to content

feat: sign previews in from the dashboard with a host-bound token - #32522

Draft
DanielleMaywood wants to merge 1 commit into
open-preview/routingfrom
open-preview/sign-in
Draft

DanielleMaywood wants to merge 1 commit into
open-preview/routingfrom
open-preview/sign-in

Conversation

@DanielleMaywood

@DanielleMaywood DanielleMaywood commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Adds two endpoints. POST /api/experimental/previews/address returns 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-in signs 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 an application_connect key, and returns the preview URL with a sign-in token encrypted under the existing workspace apps key. The token's audience is coder_preview and 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_token with Secure on HTTPS, whatever --secure-auth-cookie says, and coder_preview_session_token on plain HTTP), and redirects to its own origin with Referrer-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=Lax session cookie from the dashboard's frame. A region that cannot serve previews gets a 400, and a failed region lookup a 500. url_path must pass previewhost.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-cookie they 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.

  1. feat: serve published HTML previews from the workspace agent #32438 Agent file previews
  2. feat: serve agent previews on strict preview hosts #32439 Strict preview hosting and experiment
  3. feat: sign previews in from the dashboard with a host-bound token #32522 Preview sign-in, this PR
  4. feat(coderd): add the open_preview chat tool #32440 open_preview chat tool
  5. feat(site/src): open open_preview results in the right panel #32441 Agents UI
  6. docs: document open_preview previews #32442 Docs

🤖 Generated with Claude Code

@DanielleMaywood

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review

coder-agents-review Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Chat: Review posted | View chat
Requested: 2026-11-26 13:57 UTC by @DanielleMaywood
Spend: $98.37 / $100.00

Review history
  • R1 (2026-11-25): 13 reviewers, 5 Nit, 2 P2, 14 P3, 12 P4, COMMENT. Review
  • R2 (2026-11-25), 5 Nit, 2 P2, 14 P3, 12 P4, COMMENT. Review
  • R3 (2026-11-25): 15 reviewers, 7 Nit, 2 P2, 16 P3, 20 P4, COMMENT. Review
  • R4 (2026-11-26): 11 reviewers, 9 Nit, 2 P2, 18 P3, 25 P4, COMMENT. Review
  • R5 (2026-11-26): 9 reviewers, 10 Nit, 2 P2, 18 P3, 27 P4, COMMENT. Review
  • R6 (2026-11-26): 6 reviewers, 11 Nit, 2 P2, 18 P3, 27 P4, COMMENT. Review
  • R7 (2026-11-26): 6 reviewers, 11 Nit, 2 P2, 18 P3, 27 P4, APPROVE. Review
  • R8 (2026-11-26): 6 reviewers, 13 Nit, 2 P2, 18 P3, 28 P4, COMMENT. Review
  • R9 (2026-11-26): 8 reviewers, 13 Nit, 2 P2, 19 P3, 29 P4, COMMENT. Review

deep-review v0.13.1 | Round 9 | 327e5ed..4f68cc0

Last posted: Round 9, 63 findings (2 P2, 19 P3, 29 P4, 13 Nit), COMMENT. Review

Finding inventory

Finding inventory: PR #32522

Findings

# Sev Status Location Summary Round Reviewer Posted
CRF-1 P3 Author fixed (3cbebe3) coderd/previews.go:94 previewHostingFor database errors answered as 400 with raw error in Detail R1 Netero Yes
CRF-2 P3 Author fixed (3cbebe3) coderd/workspaceapps/preview.go:61 Comment refers to a direct-open redirect that does not exist R1 Netero Yes
CRF-3 P3 Author fixed (69ee6a9, in #32439) coderd/httpapi/cookie.go:32 Comment reason made false: preview cookie prefix now follows scheme, not deployment setting R1 Netero Yes
CRF-4 P4 Author fixed (3cbebe3) coderd/previews.go:153 previewHostingFor refusal branches (no wildcard, deleted proxy) untested R1 Netero Yes
CRF-5 P4 Author contested; panel closed R3 (1/1 accept); re-raised R9 by Ging-Go with new evidence (omitzero also makes the TS field optional) codersdk/previews.go:23 omitempty on uuid.UUID RegionID has no effect R1 Netero Yes
CRF-6 Nit Author contested; panel closed R3 (1/1 accept) coderd/workspaceapps/previewhost/previewhost.go:78 "__Host-" literal duplicates codersdk cookieHostPrefix R1 Netero Yes
CRF-7 Note Note (body) coderd/previews.go:126 payload.Subject is set but never read R1 Netero No
CRF-8 P2 Author fixed (3cbebe3) coderd/previews.go:101 Unvalidated AgentName plus HostnamesMatch port stripping lets a token minted by one user sign in another user's preview host R1 Kurapika P2, Netero Note Yes
CRF-9 P2 Author fixed (5421940), verified R4 coderd/workspaceapps/previewhost/previewhost.go:87 Preview session cookie uses deployment SameSite (Lax), dropped in cross-site dashboard iframe R1 Razor, Ryosuke, Melody, Pariston, Mafuuu, Bisky, Meruem P2; Hisoka P3 Yes
CRF-10 P3 Author fixed (3cbebe3) coderd/previews.go:113 Each preview open mints a session-length whole-user application_connect key; replaced keys stay valid R1 Pariston P3, Kurapika P4, Ryosuke Note, Mafuuu Note Yes
CRF-11 P3 Author fixed (3cbebe3) coderd/previews.go:64 Preview access rules duplicated from Issue with a different agent lookup R1 Ryosuke P3, Meruem P3, Pariston Note Yes
CRF-12 P3 Author fixed (3cbebe3) coderd/workspaceapps/preview.go:116 Post-sign-in redirect decodes escaped path segments R1 Mafuuu P3, Hisoka P4, Razor P4 Yes
CRF-13 P3 Author contested; panel closed R3 (1/1 accept) coderd/workspaceapps/preview.go:63 Expired sign-in param shows error even when host already has a valid session cookie R1 Mafuuu Yes
CRF-14 P4 Author fixed (3cbebe3) coderd/previews.go:140 URLPath containing reserved query params yields a URL that never opens R1 Meruem, Mafuuu, Melody Yes
CRF-15 P3 Author fixed (3cbebe3) coderd/previews.go:85 Unknown agent reported as "does not allow port forwarding" R1 Leorio Yes
CRF-16 P3 Author fixed (3cbebe3) codersdk/previews.go:28 "one-minute" token is accepted up to two minutes after minting R1 Gon P3 (+P2 at token.go:90), Leorio P4 Yes
CRF-17 Nit Author contested; panel closed R3 (1/1 accept) coderd/workspaceapps/token.go:98 Validate doc comment restates the body R1 Gon P2 Yes
CRF-18 P3 Author contested; panel closed R3 (1/1 accept) coderd/workspaceapps/previewhost/previewhost.go:74 SessionCookieName comment says __Host- makes the cookie Secure and host-only R1 Gon P2 Yes
CRF-19 P4 Author fixed (5421940), verified R4 coderd/workspaceapps.go:138 createAppConnectKey comment omits the DefaultDuration cap and the return value R1 Gon P3 Yes
CRF-20 P4 Author fixed (3cbebe3) codersdk/previews.go:30 Origin doc uses undefined "wrapper" and does not say which check uses it R1 Gon P3 Yes
CRF-21 P4 Author contested; panel closed R3 (1/1 accept) coderd/workspaceapps/token.go:94 Sign-in lifetime is an inline time.Minute repeated in comments R1 Gon Yes
CRF-22 P4 Author contested; panel closed R3 (1/1 accept) coderd/workspaceapps/token.go:100 Expiry nil check duplicates RegisteredClaims.Validate R1 Gon Yes
CRF-23 Nit Author contested; panel closed R3 (1/1 accept) coderd/workspaceapps/provider.go:42 PreviewSessionCookie field holds a name; call it PreviewSessionCookieName R1 Gon Yes
CRF-24 Nit Author fixed (3cbebe3) coderd/workspaceapps/token.go:77 "dashboard mints" names the frontend; coderd mints the payload R1 Gon Yes
CRF-25 P4 Author contested; panel closed R3 (1/1 accept) coderd/workspaceapps/provider.go:42 Other ResolveRequest callers rely on r.Cookie("") failing; cookie name threads through generic options R1 Meruem Yes
CRF-26 P3 Author fixed (3cbebe3) coderd/workspaceapps/preview_test.go:79 Tests use a zero cookie config, so Secure-follows-config and cookiesToPrefix removal are untested R1 Bisky Yes
CRF-27 P3 Author fixed (3cbebe3) coderd/previews.go:152 RegionID equal to DeploymentID branch untested R1 Bisky Yes
CRF-28 P3 Author fixed (3cbebe3) coderd/previews.go:114 No scoped-token test for the new key-minting endpoint R1 Bisky Yes
CRF-29 P4 Author fixed (3cbebe3) coderd/workspaceapps/preview_test.go:174 No test sends a sign-in token on a top-level page load R1 Bisky Yes
CRF-30 P4 Author contested; panel closed R3 (1/1 accept) coderd/workspaceapps/preview_test.go:340 Fake http.Response to parse Set-Cookie; use http.ParseSetCookie R1 Ging-Go Yes
CRF-31 P4 Author contested; panel closed R3 (1/1 accept) coderd/previews_test.go:103 Fake http.Response to parse Set-Cookie; use http.ParseSetCookie R1 Ging-Go Yes
CRF-32 P3 Author fixed (3cbebe3) coderd/workspaceapps/provider.go:64 PR description and commit message credit #32439 protections to this PR and cite unresolvable references R1 Mafu-san P3, Leorio P3/P4 Yes
CRF-33 P4 Author contested; panel closed R3 (1/1 accept) coderd/previews.go:72 Invalid slug message does not state the valid format R1 Leorio Yes
CRF-34 P4 Author contested; panel closed R3 (1/1 accept) coderd/previews.go:107 "Invalid preview address." blames the request when the hostname label is too long R1 Leorio Yes
CRF-35 OOS Out of scope (body) coderd/workspaceapps/provider.go:95 Signed app token cookie also uses deployment SameSite on preview hosts R1 Mafuuu No
CRF-36 OOS Out of scope (body) coderd/workspaceapps/proxy.go:326 handleAPIKeySmuggling redirect also decodes escaped paths R1 Mafuuu, Hisoka No
CRF-37 OOS Out of scope (body) coderd/workspaceapps/token.go:58 EncryptedAPIKeyPayload also accepted for two minutes, undocumented R1 Gon No
CRF-38 OOS Out of scope (body) coderd/workspaceapps/previewhost/previewhost.go:191 Preview scripts can set Domain cookies on the app wildcard via document.cookie R1 Razor No
CRF-39 OOS Out of scope (body) coderd/workspaceapps.go:140 createAppConnectKey uses time.Until and dbtime.Now instead of api.Clock R1 Meruem No
CRF-40 P3 Author contested; panel closed R4 (1/1 accept) codersdk/previews.go:12 Sign-in request/response types reused by the address endpoint, which does not sign in R3 Netero Yes
CRF-41 P4 Author contested; panel closed R4 (1/1 accept) coderd/workspaceapps/previewhost/previewhost.go:192 Unreachable url.Parse error branch in Hosting.URL R3 Netero Yes
CRF-42 P4 Author contested; panel closed R4 (1/1 accept) coderd/workspaceapps/preview.go:139 signInPreview copies originLocalURL trimming instead of fixing originLocalURL R3 Netero Yes
CRF-43 P4 Author contested; panel closed R4 (1/1 accept) coderd/previews_test.go:305 Inline application_connect key counts instead of appConnectKeys helper R3 Netero Yes
CRF-44 Nit Author fixed (5421940), verified R4 coderd/workspaceapps/token.go:76 "The coderd mints it" extra article R3 Netero Yes
CRF-45 P3 Author accepted R5 (operator decision for the experimental release, no issue) coderd/previews.go:74 Preview sign-in key has the whole-user allow list; restrict it to the preview's workspace R3 Knov P3, Kurapika P3 Yes
CRF-46 P4 Author accepted R5 (operator decision for the experimental release, no issue) coderd/workspaceapps/preview.go:126 Exact host compare includes the port, so a reverse proxy that drops a non-default port fails every sign-in R3 Hisoka Yes
CRF-47 P4 Author fixed (5421940), verified R4 coderd/previews_test.go:303 NotContains "connection reset" on Message cannot fail; the error is in Detail R3 Bisky Yes
CRF-48 P4 Dropped by orchestrator (row guards the CRF-8 regression of a port-only agent check) coderd/previews_test.go:165 UnknownAgentForFile row runs the same path as UnknownAgent R3 Bisky No
CRF-49 P4 Author fixed (5421940), verified R4 coderd/previews.go:244 registrableDomain SplitHostPort branch untested R3 Bisky Yes
CRF-50 P4 Author contested; panel closed R4 (1/1 accept) coderd/previews.go:109 Address endpoint requires api_key:create; neither endpoint checks application_connect on the workspace R3 Kite Yes
CRF-51 P4 Author fixed (5421940), verified R4 coderd/previews_test.go:294 Region refusal test asserts only 400, not the refusal reason R3 Kite Yes
CRF-52 P2 Dropped by orchestrator (moved, accurate comment; verbosity only) coderd/workspaceapps/appurl/appurl.go:15 Moved SubdomainProxyAPIKeyParam comment is wordy R3 Gon No
CRF-53 Nit Author contested; panel closed R4 (1/1 accept) codersdk/previews.go:49 previewFrame names both the SDK request helper and the coderd response builder R3 Gon Yes
CRF-54 Note Note (body) coderd/previews.go:241 Same-site check ignores scheme (schemeful same-site); unverified in a browser R3 Gon No
CRF-55 P4 Dropped by orchestrator (squash commits use the PR body, verified by Mafu-san) commit 3cbebe3 Commit body still says one-minute token and credits #32439 refusals R3 Leorio No
CRF-56 P3 Author contested; panel closed R5 (3/3 accept) coderd/previews.go:224 Same-site rule lives in the handler: two copies, a second refusal error type, sentinel doc now wrong, no startup diagnostic R4 Netero P4, Ryosuke P4, Gon P4 Yes
CRF-57 Nit Author contested; panel closed R5 (1/1 accept) coderd/previews.go:209 crossSiteError doc calls the Message field "response title" R4 Gon Yes
CRF-58 P4 Author fixed (99d01d9, doc only), verified R5 coderd/workspaceapps/previewhost/previewhost.go:54 CheckURLPath accepts bad query escapes and ";" pairs that hide reserved keys R4 Ging-Go Yes
CRF-59 Nit Author fixed (99d01d9), verified R5 coderd/previews.go:162 errors.As with a var; GO.md prefers errors.AsType R4 Ging-Go Yes
CRF-60 P4 Author fixed (7cf249d), verified R7 coderd/previews.go:224 Same-site refusal ignores --samesite-auth-cookie=none, and its comment cites only the default Lax R4 Melody P4, Leorio P4 Yes
CRF-61 P4 Author contested; panel closed R5 (1/1 accept) coderd/previews_test.go:441 Primary CrossSite row passes with a same-site app hostname because the dashboard is 127.0.0.1 R4 Bisky Yes
CRF-62 P4 Author contested; panel closed R5 (1/1 accept) enterprise/wsproxy/preview_test.go:78 Proxy-region refusal asserts only status 400 R4 Bisky Yes
CRF-63 P3 Author fixed (PR description), verified R5 coderd/previews.go:224 PR description says only proxies are refused for being cross-site; the primary is now refused too R4 Leorio P3, Razor P4 Yes
CRF-64 P4 Author contested; panel closed R5 (1/1 accept) coderd/previews.go:163 Cross-site refusal has no Detail naming the compared domains, and the proxy case dropped "choose another region" R4 Leorio Yes
CRF-65 Nit Author fixed (588ce57), verified R6 coderd/previews.go:205 "Its text" now reads as crossSiteError's text after the new sentence R5 Gon Yes
CRF-66 P4 Author contested; panel closed R6 (1/1 accept) coderd/workspaceapps/proxy.go:43 SubdomainProxyAPIKeyParam has two names (appurl constant and workspaceapps alias), both used in this PR's tests R5 Zoro Yes
CRF-67 P4 Author contested; panel closed R6 (1/1 accept) coderd/previews.go:221 "no wildcard app hostname" text duplicated instead of wrapping api.previewsUnavailable R5 Zoro Yes
CRF-68 OOS Out of scope (body) coderd/x/chatd/chattool/openpreview.go:150 #32440 OpenPreview treats any previewsUnavailable as unavailable in every region, blocking same-site proxies R5 Ryosuke No
CRF-69 Nit Author fixed (7cf249d), verified R7 coderd/workspaceapps/previewhost/previewhost.go:84 Hosting.host doc says "with the serving port" but Strict drops the default port R6 Meruem Yes
CRF-70 Nit Author contested; panel closed R9 (1/1 accept) coderd/previews_test.go:196 Moved comment "The address endpoint refuses what sign-in refuses." now restates the loop below it R8 Gon P2 Yes
CRF-71 P2 Dropped by orchestrator (Leorio showed each clause names a table row to update; accurate test doc) coderd/previews_test.go:252 TestPreviewRegions doc restates the table's assertions R8 Gon No
CRF-72 P4 Author contested; panel closed R9 (1/1 accept) coderd/previews_test.go:262 Constant hostPrefixOff (message) shares its name with the bool field hostPrefixOff in the same rows R8 Gon Yes
CRF-73 Nit Author fixed (4f68cc0); re-raised R9 by Gon (Primary row also depends on the port) coderd/previews_test.go:312 "The port checks that same-site comparisons ignore it." is ambiguous and omits that Primary also relies on the port R8 Leorio Nit, Gon Note Yes
CRF-74 P3 Open coderd/previews.go:233 Caller-context proxy read refuses every scoped token for every proxy region with a false "no workspace proxy has ID" Detail; the scope is internal and cannot be requested R9 Razor P3, Gon P4, Leorio P4, Ryosuke P4, Bisky P4, Chopper P4 Yes
CRF-75 Nit Open coderd/previews_test.go:429 Scoped-token proxy case comment credits the scope alone; the allow list also blocks the read R9 Bisky Yes
CRF-76 OOS Out of scope (body) enterprise/coderd/workspaceproxy.go:64 fetchRegions comment says users cannot usually access proxies, but memberRole grants read R9 Ryosuke No

Contested and acknowledged

CRF-70 (Nit, previews_test.go:196) and CRF-72 (P4, previews_test.go:262)

  • Finding: Restating comment; constant and bool field share the name hostPrefixOff.
  • Author defense: The comment states the rule the test exists for; each row that sets the flag expects that message and the constant is three lines above.
  • Panel closure (R9, 1/1 each): Gon, the agent that raised them: accurate comment with no behavior effect; a wrong pairing fails the test.

CRF-66 (P4, proxy.go:43) and CRF-67 (P4, previews.go:221)

  • Finding: Two names for SubdomainProxyAPIKeyParam; duplicated "no wildcard app hostname" text.
  • Author defense: The alias keeps main's references untouched and names where the constant lives; the duplicated text is only Detail under "choose another region".
  • Panel closure (R6, 1/1 each): Zoro, the agent that raised them: git blame shows the workspaceapps-name test use comes from base 6747c02, only the appurl use is new; a drifted Detail breaks nothing.

CRF-45 (P3, previews.go:74) - whole-user key scope

  • Author accepted (R5): "Accepted for the experimental release (operator decision, no issue filed)": the key matches main's subdomain sign-in key, sign-in runs only when a preview host has no session, and the sign-in URL is host-bound and short-lived. Recorded as a human decision by the PR author's account.

CRF-46 (P4, preview.go:126) - port in exact host compare

  • Author accepted (R5): "Accepted for the experimental release (operator decision, no issue filed)": a reverse proxy on a non-default port must forward Host with its port.

CRF-56 (P3, previews.go:224) - same-site rule in handler

  • Finding: Two copies, second refusal type, false sentinel doc, no startup warning; move into previewhost.Strict.
  • Author defense: Sentinel doc fixed; rule kept in previewHostingFor so the chat tool still offers previews and the tab shows the reason.
  • Panel closure (R5, 3/3): Netero, Ryosuke and Gon, the agents that raised the parts. Ryosuke found that feat(coderd): add the open_preview chat tool #32440's OpenPreview refuses every region when previewsUnavailable is set, so the proposed startup recording would block same-site proxies; the user-facing message names the cause.

CRF-57 (Nit, previews.go:209) - "response title"

  • Author defense: The message is the alert title the preview tab shows.
  • Panel closure (R5, 1/1): Gon: the word describes what the user reads and cannot lead a caller to the wrong field.

CRF-60 (P4, previews.go:224) - refusal under SameSite=None

  • Finding: The refusal ignores --samesite-auth-cookie=none and the comment cites only default Lax.
  • Author defense: Refusing under none is intended because Safari and Firefox block or partition third-party cookies.
  • Panel re-raise (R5, comment only): Melody accepted the behavior; Leorio accepted the behavior but re-raised the comment, which still gives only the default Lax reason, so a maintainer could add a none exemption and bring back the Safari sign-in loop. Melody noted the same comment gap.

CRF-61, CRF-62 (P4, tests) - CrossSite row and proxy refusal assertion

  • Panel closure (R5, 1/1 each): Bisky withdrew both: the two tests together cover both outcomes of the comparison, and the proxy message is asserted exactly in TestPreviewSignInRegions.

CRF-64 (P4, previews.go:163) - cross-site refusal Detail

CRF-40 (P3, codersdk/previews.go:12) - sign-in types reused by address endpoint

  • Finding: Rename PreviewSignInRequest/PreviewSignInResponse since the address endpoint does not sign in.
  • Author defense: Same request and frame for both; the type comment says so; renaming across stacked PRs is churn.
  • Panel closure (R4, 1/1): Netero, the agent that raised it: the type comments state both uses and the API is experimental with one in-stack consumer, so a later rename has no compatibility cost.

CRF-41 (P4, previewhost.go:192) - unreachable url.Parse branch

  • Finding: Share one parse or drop the branch.
  • Author defense: The error must still be handled; a helper would add code to remove three lines.
  • Panel closure (R4, 1/1): Netero, the agent that raised it: no runtime effect.

CRF-42 (P4, preview.go:139) - originLocalURL copy

  • Finding: Fix originLocalURL to keep RawPath instead of copying its trimming.
  • Author defense: Changing it alters main's app redirects, out of scope for the stack.
  • Panel closure (R4, 1/1): Netero, the agent that raised it: the comment names originLocalURL, so the copies point at each other.

CRF-43 (P4, previews_test.go:305) - inline key counts

  • Finding: Use appConnectKeys.
  • Author defense: Both tests use password sessions, so the inline count sees every key.
  • Panel closure (R4, 1/1): Netero, the agent that raised it, verified both tests sign in with password sessions.

CRF-45 (P3, previews.go:74) - whole-user key scope

  • Finding: Each preview sign-in key has the *:* allow list; restrict it to the preview's workspace.
  • Author defense: Same key as main's subdomain sign-in; minting frequency was reduced; the allow list was left out of this release. No ticket.
  • Panel re-raise (R4): Knov and Kurapika, the agents that raised it: main's key serves every app via the wildcard cookie, while this key sits in a host-only cookie for one workspace; minting less often does not narrow what one key reaches. Fix verified in R3. No ticket, so this needs a fix or a human decision.

CRF-46 (P4, preview.go:126) - port in exact host compare

  • Finding: A reverse proxy that drops a non-default port from Host fails every sign-in.
  • Author accepted: Keeps the exact compare to protect the SignInForHostEndingInOtherHost case; documented reverse proxy setup listens on 443. No ticket; a human must accept or file it.

CRF-50 (P4, previews.go:109) - ActionCreate on address endpoint

  • Finding: Address endpoint requires api_key:create; neither checks ActionApplicationConnect.
  • Author defense: Shared checks keep the address endpoint from returning addresses sign-in would refuse; no reachable case where an owner passes and Issue refuses.
  • Panel closure (R4, 1/1): Kite, the agent that raised it: owners hold application_connect; scoped tokens hit ErrExceedsCaller; a dormant workspace has no agent and is refused before minting (inferred).

CRF-53 (Nit, codersdk/previews.go:49) - previewFrame name collision

  • Finding: Rename the SDK request helper.
  • Author defense: Unexported in different packages; both return the frame.
  • Panel closure (R4, 1/1): Gon, the agent that raised it: each returns a PreviewSignInResponse.

CRF-5 (Nit, codersdk/previews.go:23) - omitempty on uuid.UUID RegionID

  • Finding: omitempty on a uuid.UUID has no effect in encoding/json; drop it or use *uuid.UUID.
  • Author defense: The tag makes the generated TypeScript field optional, as for other codersdk uuid.UUID fields.
  • Panel closure (R3, 1/1): Netero, the agent that raised it, confirmed readonly region_id?: string in typesGenerated.ts and 63 other uuid.UUID fields with omitempty in codersdk; the server treats the nil UUID as the primary.

CRF-6 (Nit, previewhost.go:136) - "__Host-" literal duplication

  • Finding: Export codersdk.cookieHostPrefix and reuse it instead of the literal.
  • Author defense: Exporting widens the SDK API for one literal.
  • Panel closure (R3, 1/1): Netero, the agent that raised it, verified a typo in the previewhost copy fails TestServePreviewPolicy, which asserts the full cookie name.

CRF-13 (P3, preview.go:71) - expired sign-in param ignores valid cookie

  • Finding: A request with an expired coder_preview_sign_in shows the error page even when the host has a valid session cookie.
  • Author defense: PreviewFrame loads the untokenized address on every mount and reload and uses a minted URL only right after a fresh sign-in, whose 303 drops the token.
  • Panel closure (R3, 1/1): Mafuuu, the agent that raised it, verified postPreviewAddress returns an untokenized URL for every load, removing the cached-response trigger.

CRF-17 (Nit, token.go:100) - Validate doc restates body

  • Finding: Delete the restating doc comment.
  • Author defense: Exported symbols need doc comments.
  • Panel closure (R3, 1/1): Gon, the agent that raised it, confirmed .golangci.yaml:135 enables revive's exported rule.

CRF-18 (P3, previewhost.go:132) - __Host- comment mechanism

  • Finding: The comment says the prefix makes browsers keep the cookie Secure and host-only.
  • Author defense: Wording nit; SessionCookie sets Secure itself.
  • Panel closure (R3, 1/1): Gon, the agent that raised it, verified removing the Secure assignment fails the https row of TestServePreviewSessionCookie, so the misleading text cannot cause a silent break.

CRF-19 (P4, workspaceapps.go:138) - createAppConnectKey doc lifetime

  • Finding: The doc says "same lifetime as the current session" but the key is capped at Sessions.DefaultDuration, and it does not say it returns the secret.
  • Author defense: Out of scope; the text and cap come from main and were only moved.
  • Panel re-raise (R3): Gon, the agent that raised it, showed main had an inline remark inside workspaceApplicationAuth; this PR turns it into the doc comment of a new function that the new sign-in endpoint calls, so it is added text in scope.

CRF-21 (P4, token.go:96) - inline time.Minute

  • Finding: Name the sign-in lifetime constant.
  • Author defense: One use; the Fill doc states it.
  • Panel closure (R3, 1/1): Gon, the agent that raised it: the codersdk doc cannot reference a workspaceapps constant, so a constant would not remove the second copy.

CRF-22 (P4, token.go:102) - redundant Expiry nil check

  • Finding: Keep only NotBefore == nil.
  • Author defense: Harmless and keeps the rule visible.
  • Panel closure (R3, 1/1): Gon, the agent that raised it: the clause changes no result.

CRF-23 (Nit, provider.go:42) - PreviewSessionCookie field name

  • Finding: Rename to PreviewSessionCookieName.
  • Author defense: Naming preference; the field doc says it is a name.
  • Panel closure (R3, 1/1): Gon, the agent that raised it: the field is passed to r.Cookie, which takes a name, so a caller cannot misuse it.

CRF-25 (P4, provider.go:42) - empty cookie name in other callers

  • Finding: Other ResolveRequest callers fail closed only because r.Cookie("") errors.
  • Author defense: The empty lookup yields no session and Issue refuses; no access is gained.
  • Panel closure (R3, 1/1): Meruem, the agent that raised it, agreed no caller gains access.

CRF-30 (P4, preview_test.go:473) and CRF-31 (P4, previews_test.go:108) - fake http.Response

  • Finding: Use http.ParseSetCookie.
  • Author defense: Established idiom; malformed cookies still fail the test.
  • Panel closure (R3, 1/1 each): Ging-Go, the agent that raised them, found the "established idiom" claim false (only these two uses in the repo) but verified the preceding assertions fail on a missing or malformed cookie.

CRF-33 (P4, previews.go:143) and CRF-34 (P4, previews.go:180) - error message wording

  • Finding: State the slug format; do not blame the request for a too-long label.
  • Author defense: Slugs come from the tool; the tool refuses long labels and Detail names the cause.
  • Panel closure (R3, 1/1 each): Leorio, the agent that raised them: the field doc gives the format, only code-built requests reach these branches, and Detail names the cause.

Law analysis

R1: not run. Effective additions 805, below the 1000 threshold.
R3: effective additions 1560 at head 3cbebe3. Verdict: Don't split. Enforcement: Advisory. One dependency chain (refactors, URL validation, host sign-in, endpoints, proxy regions); the only vertical cut (proxy regions, about 45 production LOC) was judged not worth taking.

Round log

Round 1

Netero 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.
Specialists: ging-go (.go files), Kurapika (tokens, cookies, host matching), Ryosuke (Go API and package boundaries), Melody (token crosses coderd to preview host and wsproxy). ging-ts and ging-react not spawned: the only .ts change is generated site/src/api/typesGenerated.ts.
Core: Pariston, Mafuuu. Pool: Bisky, Hisoka, Gon, Leorio, Razor, Mafu-san. Wildcard (random from distilled set): Meruem.

Cross-check:

  • CRF-8 upgraded from Netero Note to P2: Kurapika reproduced a token for one user's preview host passing the host check on another user's preview host (AgentName with a colon, HostnamesMatch strips the port). Orchestrator confirmed HostnamesMatch uses net.SplitHostPort on both sides (appurl.go:228) and hosting.URL does not validate AgentName.
  • CRF-9 convergent across 8 reviewers; Razor reproduced with Playwright Chromium (cookie sent for same-site frame, not for cross-site frame).
  • CRF-10 merges Pariston P3, Kurapika P4, Ryosuke Note, Mafuuu Note; higher severity P3.
  • CRF-12 merges Mafuuu P3, Hisoka P4, Razor P4; higher severity P3.
  • CRF-16 merges Gon P3 (codersdk/previews.go:28), Gon P2 (token.go:90, restatement plus wrong lifetime), Leorio P4.
  • CRF-17 downgraded Gon P2 to Nit. Keep argument: comments that restate code break the repository comment rule. Downgrade reason: the comment is accurate, so the consequence is a convention violation only.
  • CRF-18 downgraded Gon P2 to P3. Keep argument: a maintainer could drop the Secure line believing the prefix supplies it. Downgrade reason: the https row of TestServePreviewSessionCookie asserts the cookie string, so that removal fails a test.
  • CRF-19 downgraded Gon P3 to P4. Keep argument: the doc misstates the key lifetime. Downgrade reason: the real lifetime is shorter than documented, so a caller relying on the doc is not given a longer-lived key than expected; the text moved unchanged from workspaceApplicationAuth.
  • CRF-20 downgraded Gon P3 to P4. Keep argument: an exported field with an unclear contract can be checked wrongly by the client. Downgrade reason: experimental API whose only consumer is feat(site/src): open open_preview results in the right panel #32441 in the same stack; no wrong behavior in this PR.
  • CRF-32 merges Mafu-san P3 and Leorio P3 plus Leorio P4 (unresolvable references), all about PR text accuracy.
  • Positive confirmation notes (Melody, Razor, Bisky, Leorio, Mafu-san) record cleared concerns and are not inventoried.
    Totals posted: 2 P2, 14 P3, 12 P4, 5 Nit. 1 Note (body). 5 out of scope. Reviewed against f0bc2f2..24b45ed.

Round 2 update

BLOCKED. 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 3

Panel (restructure: new address endpoint, effective additions 805 to 1560). Churn guard PROCEED: 14 findings contested by author replies.
Netero (reused R1 agent) and Law ran; Law: Don't split, advisory.
Panel: ging-go, mafuuu, gon, leorio, meruem (reused R1 agents for dispute check-in; not counted toward size), kurapika, ryosuke, melody, pariston, bisky, hisoka, razor, mafu-san, knov (pool), kite (wildcard, random from chopper/kite/zoro).
Dispute check-in: 13 closed (CRF-5, 6, 13, 17, 18, 21, 22, 23, 25, 30, 31, 33, 34), 1 re-raised (CRF-19, Gon, new evidence that the text is a new doc comment).
Fix verification: CRF-9 re-raised at P2 by 10 reviewers (Hisoka P3): same-site check covers proxies only; Melody, Pariston, Bisky, Kite reproduced a 200 sign-in for a cross-site primary wildcard. CRF-10 per-open minting verified fixed (Pariston, Ryosuke); Kurapika's scope part split into CRF-45 with Knov's verified allow-list fix. Other fixes verified by Netero, Kurapika, Mafuuu, Gon, Meruem, Bisky, Razor, Leorio.
Drops: CRF-48 keep argument: duplicate rows cost maintenance; drop reason: the row is the only guard against re-adding a port-only agent check (the CRF-8 bug). CRF-52 keep argument: comment is on a new declaration; drop reason: moved unchanged, accurate, verbosity has no consequence, P2 not supported. CRF-55 keep argument: git log on the branch shows stale text; drop reason: Mafu-san verified squash commits use the PR body (f2b6084 from #31600), and the PR body is correct.
CI: Flake Check was cancelled for a newer run (Mafu-san), not a test failure.
Totals: 1 P2 re-raise, 1 P4 re-raise, new 2 P3, 8 P4, 2 Nit; 1 Note (body); 3 dropped. Reviewed against 69ee6a9..3cbebe3.

Round 4

Fix round (no added files or new goal; effective additions 1560 to 1581). Churn guard PROCEED: 6 addressed, 1 acknowledged (CRF-46), 7 contested.
Netero (reused) closed CRF-40 to CRF-43 (1/1 each) and raised CRF-56.
Panel: kurapika, knov, kite, gon, hisoka (reused agents), ging-go, ryosuke, melody, bisky, leorio (new agents; specialists for changed .go files, raisers of touched findings, Gon/Leorio for doc comment changes), razor (wildcard, random from mafuuu/meruem/chopper/zoro/razor).
Dispute check-in: CRF-50 and CRF-53 closed; CRF-45 re-raised by both raisers. CRF-46 acknowledged without ticket: needs human decision.
Fix verification: CRF-9 primary check verified (Kurapika, Knov, Kite, Ryosuke, Melody, Razor, Netero; Ryosuke and Melody ran Playwright probes of registrableDomain against Chromium/Firefox). CRF-19, 44, 47, 49, 51 verified.
Cross-check: CRF-56 raised to P3 as the convergence of Netero (duplicate check, two error types), Gon (sentinel doc now false), and Ryosuke (no startup diagnostic); one fix (same-site rule in previewhost.Strict wrapping the sentinel, primary recorded in previewsUnavailable at startup) resolves all three. CRF-60 merges Melody (refusal ignores SameSite=None, reproduced) and Leorio (comment cites only default Lax). CRF-63 merges Leorio P3 and Razor P4.
Totals: 1 P3 re-raise; new 2 P3, 5 P4, 2 Nit. Reviewed against e919721..5421940.

Round 5

Fix 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.
Netero (reused): no findings; closed its CRF-56 part. Panel (reused agents): gon, ryosuke, melody, leorio, bisky, ging-go, razor, kurapika; zoro (wildcard, random from mafuuu/meruem/chopper/kite/zoro/knov, new agent).
Dispute check-in: CRF-56 closed 3/3, CRF-57, CRF-61, CRF-62, CRF-64 closed; CRF-60 re-raised by Leorio for the comment only.
Verified: CRF-58 (doc; Ging-Go and Kurapika showed the ";" pair is harmless because every reader uses the same query parsing), CRF-59, CRF-63.
New: 2 P4, 1 Nit; 1 out of scope (#32440). Reviewed against 6747c02..99d01d9.

Round 6

Fix round (comment-only commit 588ce57). Churn guard PROCEED: 2 addressed, 2 contested.
Netero (reused): no findings. Panel: zoro, gon, leorio, melody, ging-go (reused agents), meruem (wildcard, random from mafuuu/meruem/chopper/kite/knov/razor, new agent).
Dispute check-in: CRF-66 and CRF-67 closed by Zoro.
Fix verification: CRF-65 verified. CRF-60 re-raised by Melody and Leorio (its raisers), with Gon converging: the new comment says browsers block or partition the cookie even with SameSite=None, but the R4 Playwright probe showed Chromium and Firefox send it, and Firefox partitioning keeps it in the reading frame; only blocking (Safari default, Chrome with third-party cookies off) breaks the flow. Meruem read the comment as correct; the raisers' empirical evidence outweighs it.
New: 1 Nit. Reviewed against 6747c02..588ce57.

Round 7

Fix round (comment-only commit 7cf249d). Churn guard PROCEED: 2 addressed, nothing contested.
Netero (reused): no findings. Panel: melody, leorio, gon, meruem, ging-go (reused agents; raisers of CRF-60 and CRF-69, Gon/Leorio for touched comments, Go specialist), kite (wildcard, random from mafuuu/chopper/kite/zoro/knov/razor, new agent).
Verified: CRF-60 and CRF-69. No new findings. No open findings remain; CRF-45 and CRF-46 stand as the author's operator decisions for the experimental release. Reviewed against 6747c02..7cf249d.

Round 8

Fix 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.
Netero (reused): no findings; verified every removed case survives and cancelled CI. Panel (new agents): bisky, ging-go, komugi (test changes), gon, leorio (comments changed), mafuuu (wildcard, random from mafuuu/meruem/chopper/kite/zoro/knov/razor).
Cross-check: CRF-70 downgraded Gon P2 to Nit. Keep argument: the moved comment now restates the code, against the repository comment rule. Downgrade reason: accurate test comment, no behavior consequence, consistent with CRF-17. CRF-71 dropped. Keep argument: four clauses restate the table. Drop reason: Leorio showed each clause maps to a row or assertion a maintainer must update when changing a refusal, so the doc carries navigation the table alone does not. CRF-73 merges Leorio's Nit and Gon's Note on the same comment.
Bisky, Mafuuu: tests genuine; only registrableDomain fallback (line 264) lost coverage and does not need a test. Komugi: map iteration order cannot change results; -race -count=5 passed.
New: 1 P4, 2 Nit. Reviewed against 4cae110..9aae1d9.

Round 9

Fix 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.
Netero (reused): no findings; mutation-verified the scoped proxy case fails if AsSystemRestricted returns. Panel: gon, leorio (reused), kurapika, razor, ryosuke, ging-go, bisky (new; authz and test specialists for the changed code), chopper (wildcard, random from mafuuu/meruem/chopper/kite/zoro/knov).
Dispute check-in: CRF-70, CRF-72 closed by Gon.
Cross-check: CRF-74 convergent across six reviewers; severity P3 from Razor, supported by Bisky's verification that workspace_proxy:read is internal and cannot be requested by a token, so every scoped token is refused for every proxy region and the only remedy a message could name is not available. Razor and Ryosuke: fetchRegions and workspaceApplicationAuth read proxies under AsSystemRestricted, so the caller-context read protects no data. Kurapika rated the caller-context read correct (Note); the higher severity with stronger evidence wins. Leorio's proposed message (add workspace_proxy:read) is contradicted by Bisky's evidence and is not used.
CRF-73: Leorio verified, Gon re-raised (Primary row also compares the ported access URL); Gon's evidence is specific, re-raised as Nit.
CRF-5: re-raised by Ging-Go (new persona) with new evidence defeating the R3 defense: guts treats omitzero as optional too, and codersdk already uses uuid.UUID with omitzero.
New: 1 P3, 1 Nit; 2 re-raises (P4, Nit); 1 out of scope. Reviewed against 327e5ed..4f68cc0.

About deep-review

CRF = Coder Review Finding (P0-P4, Nit, Note)

Reviewer Focus
Bisky tests
Chopper ops/errors
Churn-guard change verification
Ging language modernization
Gon naming
Hisoka edge cases
Killua perf
Kite change integrity
Knov contracts
Knuckle SQL
Komugi flake/determinism
Kurapika security
Law decomposition
Leorio docs
Luffy product
Mafu-san process
Mafuuu contracts
Melody dispatch/pairing
Meruem structural
Nami frontend
Netero mechanical checks
Pariston premise testing
Pen-botter product gaps
Razor verification
Robin duplication
Ryosuke Go arch
Takumi concurrency
Zoro shape

🤖 Managed by Coder Agents.

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: handleAPIKeySmuggling also redirects through originLocalURL(r.URL.Path), so subdomain apps opened at a path with %2F load a different path after app sign-in.
  • coderd/workspaceapps/token.go:58: EncryptedAPIKeyPayload is accepted for up to two minutes after minting (one-minute expiry plus jwt.DefaultLeeway), and nothing documents that window.
  • coderd/workspaceapps/previewhost/previewhost.go:191: applyPolicy drops Set-Cookie headers with a Domain, but preview scripts run with allow-same-origin and can set document.cookie with domain= the app wildcard parent, including a coder_subdomain_app_session_token_* cookie on the user's other apps.
  • coderd/workspaceapps.go:140: createAppConnectKey computes expiry with time.Until and dbtime.Now, not api.Clock, so mock-clock tests cannot control the key lifetime.

Notes:

  • coderd/previews.go:126: payload.Subject is set, but signInPreview and PreviewSignInPayload.Validate never read it, while the APIKey field 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.

Comment thread coderd/previews.go
}
previewURL, err := hosting.URL(appurl.ApplicationURL{
AppSlugOrPort: req.PreviewSlug,
AgentName: req.AgentName,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

🤖

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

🤖

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified fixed in 5421940ac8.

🤖

Comment thread coderd/previews.go Outdated
return
}

key, err := api.createAppConnectKey(ctx, apiKey)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

🤖

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified fixed in 3cbebe3321.

🤖

Comment thread coderd/previews.go
}
// 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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

🤖

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified fixed in 3cbebe3321.

🤖

Comment thread coderd/workspaceapps/preview.go Outdated

http.SetCookie(rw, s.Previews.SessionCookie(payload.APIKey, s.CookiesConfig))

redirectURL := originLocalURL(r.URL.Path)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

🤖

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified fixed in 3cbebe3321.

🤖

Comment thread coderd/previews.go
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.",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

🤖

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified fixed in 3cbebe3321.

🤖

Comment thread coderd/workspaceapps/preview.go Outdated
return
}

// The direct-open redirect above already answered page loads, so a

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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".

🤖

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified fixed in 3cbebe3321.

🤖

Comment thread coderd/previews.go
// 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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

🤖

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified fixed in 3cbebe3321.

🤖

Comment thread codersdk/previews.go
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"`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defense accepted.

🤖

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

🤖

// parent domain, such as by another preview.
func (h *Hosting) SessionCookieName() string {
if h.scheme == "https" {
return "__Host-" + codersdk.PreviewSessionTokenCookie

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declined: exporting codersdk.cookieHostPrefix widens the SDK API for one string literal; cheap to revisit.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defense accepted.

🤖

@DanielleMaywood
DanielleMaywood force-pushed the open-preview/sign-in branch 2 times, most recently from b5aeb4e to 8ef1834 Compare November 25, 2026 16:09
@DanielleMaywood
DanielleMaywood force-pushed the open-preview/sign-in branch 2 times, most recently from 7e0d8c7 to c9d354e Compare November 25, 2026 22:02
@DanielleMaywood

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new commit addresses 19 of the 33 round 1 findings, including both P2 findings (host binding and cross-site SameSite). The panel will check those fixes in the next round. 14 findings have no fix and no reply, so further review is blocked until each one is fixed or answered on its thread (fix, a linked issue, or the reason it should not change):

  • P3 coderd/workspaceapps/preview.go:71: an expired sign-in token shows "invalid or expired" even when the host already has a valid session cookie.
  • P3 coderd/workspaceapps/previewhost/previewhost.go:132: the SessionCookieName comment says __Host- makes the cookie Secure and host-only.
  • P4 coderd/workspaceapps.go:138: the createAppConnectKey comment omits the DefaultDuration cap and the return value.
  • P4 coderd/workspaceapps/token.go:96: the sign-in lifetime is an inline time.Minute.
  • P4 coderd/workspaceapps/token.go:102: the Expiry == nil check repeats RegisteredClaims.Validate.
  • P4 coderd/workspaceapps/provider.go:42: the other ResolveRequest callers rely on r.Cookie("") failing.
  • P4 coderd/workspaceapps/preview_test.go:473 and coderd/previews_test.go:108: a fake http.Response is built to parse Set-Cookie.
  • P4 coderd/previews.go:143: "Invalid preview slug" does not state the valid format.
  • P4 coderd/previews.go:180: "Invalid preview address." blames the request when the hostname label is too long.
  • Nit codersdk/previews.go:23: omitempty on uuid.UUID has no effect.
  • Nit coderd/workspaceapps/previewhost/previewhost.go:136: the "__Host-" literal duplicates codersdk.cookieHostPrefix.
  • Nit coderd/workspaceapps/token.go:100: the Validate doc comment restates the body.
  • Nit coderd/workspaceapps/provider.go:42: PreviewSessionCookie holds a name; call it PreviewSessionCookieName.

🤖 This review was automatically generated with Coder Agents.

@DanielleMaywood

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new commit adds a no-mint address endpoint, binds the sign-in token to the exact host, refuses cross-site proxies, and adds tests for most round 1 gaps. Findings this round: 1 P2 and 1 P4 re-raised, 2 P3, 8 P4, 2 Nit new.

Verified fixed: 17 findings, including the host binding bypass. 13 of the 14 contested findings are closed; the createAppConnectKey doc comment is re-raised because main had an inline remark, not this doc comment on a new function. The cross-site SameSite fix is incomplete: the primary region has no same-site check, so a --wildcard-access-url on another site still mints a key for a preview that never loads.

Notes:

  • coderd/previews.go:241: the same-site check compares registrable domains but not schemes. Under schemeful same-site, an http dashboard and an https proxy on one domain are cross-site; this is unverified in a browser.

🤖 This review was automatically generated with Coder Agents.

Comment thread coderd/previews.go
return
}

key, err := api.createAppConnectKey(ctx, httpmw.APIKey(r))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 [CRF-45] The key each sign-in mints opens every workspace app its owner can reach, while the preview cookie only needs one workspace. (Knov, Kurapika)

Each new preview ID or port is a new host with no cookie, so each one mints another application_connect key with the *:* allow list and up to Sessions.DefaultDuration lifetime, and any client that loads a sign-in URL within its window with Sec-Fetch-Dest: iframe gets the raw key in Set-Cookie. apikey.CreateParams.AllowList accepts {Type: "workspace", ID: <workspace ID>}, and InheritWithinCaller accepts it as a subset of the dashboard session; verified that with this allow list TestPreviewSignIn/SignsInOnlyThePreviewHost still loads the preview with 200. Pass the workspace ID from resolvePreview to createAppConnectKey for preview sign-in only.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declined: we kept the same application_connect key that main's subdomain app sign-in mints and cut how often it is minted instead, since the dashboard now signs in only when the preview host has no cookie, so a workspace allow list was left out of this release.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The defense does not change what one key reaches. Main's subdomain key lives in the wildcard app cookie that every app of the user reads, so whole-user scope matches its use; this key lives in a host-only cookie on one preview host of one workspace, and that host runs agent-written code. Each new preview ID or port is a new host with no cookie, so each still mints a 24h *:* key, and anyone who reads a sign-in URL within its window can obtain it with Sec-Fetch-Dest: iframe. Passing AllowList: {workspace: <ID>} for preview sign-in was verified in round 3 to still serve the preview. With no linked issue, this needs either the allow list in this PR or a human decision to accept the gap. (Knov, Kurapika)

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted for the experimental release (operator decision, no issue filed): the key matches what main's subdomain app sign-in mints, the dashboard signs in only when a preview host has no session, and the sign-in URL is host-bound and short-lived, so we are not narrowing the key's allow list in this PR.

err := jwtutils.Decrypt(ctx, s.APIKeyEncryptionKeycache, r.URL.Query().Get(previewhost.SignInParam), &payload)
// The whole host is compared: a host:port split would read text after a
// ":" in the payload's host as a port.
if err == nil && !strings.EqualFold(payload.Host, host) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P4 [CRF-46] The exact host comparison includes a non-default port, while preview routing ignores the port, so a reverse proxy that forwards Host without the port fails every sign-in. (Hisoka)

With access URL https://coder.example.com:8443 behind nginx with proxy_set_header Host $host; (docs/admin/networking/reverse-proxy-nginx.md:127), the request host has no port and the payload has :8443, so the user gets "invalid or expired" each time; inferred from the code, not run. Now that Hosting.URL refuses names that do not parse back, comparing hostnames without ports keeps the host binding. Compare without ports and update SignInForOtherPort.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declined: you are right that a reverse proxy on a non-default port that drops the port from Host fails every sign-in, but comparing hostnames without ports would reopen the case the SignInForHostEndingInOtherHost row guards, and the documented reverse proxy setup listens on 443, so we keep the exact host comparison for this experiment.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The consequence and reasoning are stated, but no issue is linked, so this needs a human decision: file an issue for deployments on a non-default port behind a proxy that drops it, or accept the limitation explicitly.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted for the experimental release (operator decision, no issue filed): sign-in compares the whole host the browser sends, so a reverse proxy on a non-default port must forward Host with its port, as the documented setup on 443 already does.

Comment thread coderd/previews_test.go Outdated
var sdkErr *codersdk.Error
require.ErrorAs(t, err, &sdkErr)
require.Equal(t, http.StatusInternalServerError, sdkErr.StatusCode())
require.NotContains(t, sdkErr.Message, "connection reset")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P4 [CRF-47] require.NotContains(t, sdkErr.Message, "connection reset") cannot fail. (Bisky)

httpapi.InternalServerError always sets Message to "An internal server error occurred." and puts the error text in Detail, so the assertion reads as proof the raw error is hidden when it is not. Delete the line; the status assertion above it tests the fix.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 5421940: the misleading Message assertion is deleted.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified fixed in 5421940ac8.

🤖

Comment thread coderd/previews.go
// itself when it has none, such as an IP address or localhost. Browsers treat
// two hosts as the same site when these are equal.
func registrableDomain(host string) string {
if hostname, _, err := net.SplitHostPort(host); err == nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P4 [CRF-49] No test calls registrableDomain with an access URL that has a port, so its net.SplitHostPort branch has count 0. (Bisky)

If that branch broke, coder.example.com:8443 would compare as example.com:8443 and every same-site proxy on such a deployment would get "This region does not serve previews.". Use https://dashboard.test.coder.com:8443 as the access URL in TestPreviewSignInRegions.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 5421940: TestPreviewSignInRegions now uses an access URL with a port and fails when the SplitHostPort block is removed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified fixed in 5421940ac8.

🤖

Comment thread coderd/previews.go
func (api *API) resolvePreview(rw http.ResponseWriter, r *http.Request) (*url.URL, *previewhost.Hosting, bool) {
ctx := r.Context()
apiKey := httpmw.APIKey(r)
if !api.Experiments.Enabled(codersdk.ExperimentOpenPreview) || !api.Authorize(r, policy.ActionCreate, apiKey) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P4 [CRF-50] Both endpoints authorize policy.ActionCreate on the caller's API key, but the address endpoint creates nothing, and neither checks ActionApplicationConnect on the workspace. (Kite)

A token without api_key:create gets a 404 from the address endpoint that looks like "workspace not found", and sign-in mints a key that only Issue later refuses. Check ActionApplicationConnect on the workspace in resolvePreview, and the ActionCreate key check only in postPreviewSignIn.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declined: the address endpoint shares sign-in's checks on purpose so it never hands out an address the caller could not sign in to, and the owner check plus the key scope check leave no case where an owner passes and Issue then refuses, so a separate workspace check would add nothing reachable.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defense accepted.

🤖

Comment thread codersdk/previews.go

// PreviewSignInRequest names one preview of a workspace the caller owns, for
// the preview address and sign-in endpoints.
type PreviewSignInRequest struct {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 [CRF-40] PreviewSignInRequest and PreviewSignInResponse are now also the address endpoint's request and response, and that endpoint does not sign in. (Netero)

The generated TypeScript exports these names to #32441, so renaming later touches both PRs. Rename them now, for example PreviewRequest and PreviewFrame, and update the swagger annotations.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declined: both endpoints take the same request and return the same frame, and the type comment says so, so renaming an experimental API's types across two stacked PRs for no behavior change is not worth the churn here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defense accepted.

🤖

return nil, err
}
ref, err := url.Parse(urlPath)
if err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P4 [CRF-41] The url.Parse error branch in Hosting.URL cannot run, because CheckURLPath already rejects paths that fail to parse. (Netero)

Verified with -coverprofile: the block has count 0. Share one parse between CheckURLPath and URL, or drop the branch.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declined: you are right that CheckURLPath parses the same string first so the branch never fires today, but the error still has to be handled, and sharing one parse would add a helper only to remove three lines with no behavior change.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defense accepted.

🤖


// Like originLocalURL, but RawPath keeps the request's escaping, such as
// a %2F inside a name, so the preview reloads at exactly its path.
redirectURL := &url.URL{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P4 [CRF-42] signInPreview copies the slash trimming of originLocalURL instead of making originLocalURL keep RawPath. (Netero)

The two copies must now stay in step, and originLocalURL still decodes %2F for its three other callers in proxy.go. Giving originLocalURL the escaped path removes the copy.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declined: originLocalURL's other callers are main's app redirects, whose %2F decoding is pre-existing and out of scope for this stack, so the preview redirect keeps its own escaping instead of changing their behavior.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defense accepted.

🤖

Comment thread coderd/previews_test.go Outdated
require.Equal(t, http.StatusInternalServerError, sdkErr.StatusCode())
require.NotContains(t, sdkErr.Message, "connection reset")

keys, err := db.GetAPIKeysByUserID(ctx, database.GetAPIKeysByUserIDParams{LoginType: database.LoginTypePassword, UserID: owner.ID})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P4 [CRF-43] Two tests count application_connect keys inline for LoginTypePassword only, instead of using the appConnectKeys helper in the same file. (Netero)

The helper also counts LoginTypeToken keys. If either test's caller becomes a token client, the inline count is zero and the test still passes. Use the helper.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declined: both tests sign in with password sessions, so every key they could mint has the password login type and the inline count already sees it; the helper's token branch only matters for the scoped-token test that uses it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defense accepted.

🤖

Comment thread coderd/workspaceapps/token.go Outdated
return e.RegisteredClaims.Validate(ex)
}

// PreviewSignInPayload signs a browser in to one preview host. The

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit [CRF-44] "The coderd mints it" has an extra article. (Netero)

Say "coderd mints it".

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 5421940: the comment now says coderd mints it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified fixed in 5421940ac8.

🤖

@DanielleMaywood

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit adds the same-site check for the primary region and fixes five round 3 findings. Findings this round: 1 P3 re-raised; new 2 P3, 5 P4, 2 Nit.

Verified fixed: the primary same-site check (CRF-9) and five others. Accepted defenses: six contested findings are closed. Re-raised: the workspace allow list on the preview key, because the defense covers how often keys are minted, not what one key reaches; it has no linked issue.

The exact host comparison including a non-default port (coderd/workspaceapps/preview.go:126) was acknowledged without an issue. That needs a human decision: file an issue or accept the limitation explicitly.

CI: the failed jobs for this head that were checked (7 of 19, including lint, gen, and test-go-pg) show conclusion cancelled with no failed step, so 5421940ac8 has no completed CI result yet.

🤖 This review was automatically generated with Coder Agents.

Comment thread coderd/previews.go
if api.previewHosting == nil {
return nil, xerrors.Errorf("the deployment has no wildcard app hostname: %w", errRegionWithoutPreviews)
}
if registrableDomain(strings.Replace(api.AppHostname, "*", "preview", 1)) != registrableDomain(api.AccessURL.Host) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 [CRF-56] The same-site rule sits in the handler, which leaves two copies, a second refusal type, a doc that is now false, and no startup warning. (Netero, Ryosuke, Gon)

Lines 224 and 241 repeat registrableDomain(strings.Replace(<wildcard>, "*", "preview", 1)) != registrableDomain(api.AccessURL.Host), the refusal is a bare crossSiteError beside the errRegionWithoutPreviews sentinel, whose doc at line 204 still says it marks every region that cannot serve previews, and a cross-site primary starts without the workspace previews are unavailable warning that coderd.go:739-746 logs for the other primary-wide config problems. Have previewhost.Strict, which already receives dashboardURL from all three callers, return a same-site error that wraps the sentinel; store it in previewsUnavailable for the primary at startup, and map it the same way for proxies.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 99d01d9: the errRegionWithoutPreviews doc now covers only regions without preview hosts and points cross-site regions at crossSiteError; we kept the rule in previewHostingFor rather than Strict, so the chat tool still offers the preview and the tab shows the reason.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defense accepted.

🤖

Comment thread coderd/previews.go
// reason as the user's next step.
var errRegionWithoutPreviews = xerrors.New("choose another region")

// crossSiteError is the response title for a region whose preview hosts are on

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit [CRF-57] "crossSiteError is the response title" names a field that does not exist; the value fills codersdk.Response.Message. (Gon)

Write "is the response message".

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declined: the comment does not name a field; the message is the title of the error alert the preview tab shows, so "response title" says what the user reads, and the next line says what the type is for.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defense accepted.

🤖

strings.ContainsFunc(urlPath, unicode.IsControl) {
return xerrors.Errorf("url_path must start with a single /, contain only a path and query, have no backslashes, fragments or control characters, and be at most %d bytes", maxURLPathLength)
}
ref, err := url.Parse(urlPath)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P4 [CRF-58] CheckURLPath accepts a query with bad percent-encoding or a ; pair, though its doc and the PR description say url_path cannot carry bad percent-encoding. (Ging-Go)

url.Parse copies the query to RawQuery unchecked and ref.Query() drops the parse error. Reproduced: url.Parse("/?a=%zz") returns no error while url.ParseQuery on its query returns invalid URL escape "%zz", and /?a=1;coder_preview_sign_in=x passes because the ; pair is skipped. Call url.ParseQuery(ref.RawQuery) once, return its error, and check the reserved keys on its result.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 99d01d9: the CheckURLPath doc now limits the percent-encoding check to the path, and the PR description matches.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified fixed in 99d01d9a2e.

🤖

Comment thread coderd/previews.go Outdated

hosting, err := api.previewHostingFor(ctx, req.RegionID)
var crossSite crossSiteError
if errors.As(err, &crossSite) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit [CRF-59] var crossSite crossSiteError; errors.As(err, &crossSite) is the pattern .claude/docs/GO.md:106 says to replace with errors.AsType (Go 1.26, go.mod declares 1.26.11). (Ging-Go)

Write if crossSite, ok := errors.AsType[crossSiteError](err); ok {, or drop it if the same-site refusal becomes a wrapped sentinel.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 99d01d9: now uses errors.AsType[crossSiteError].

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified fixed in 99d01d9a2e.

🤖

Comment thread coderd/previews.go
if api.previewHosting == nil {
return nil, xerrors.Errorf("the deployment has no wildcard app hostname: %w", errRegionWithoutPreviews)
}
if registrableDomain(strings.Replace(api.AppHostname, "*", "preview", 1)) != registrableDomain(api.AccessURL.Host) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P4 [CRF-60] The same-site refusal ignores --samesite-auth-cookie, so a deployment set to none is refused previews its browsers would sign in to, and the crossSiteError comment justifies the check only by the default Lax. (Melody, Leorio)

Reproduced with Playwright in Chromium and Firefox: a SameSite=None; Secure cookie set by a framed 303 on preview.localhost was sent on the next framed request from dashboard.localhost; the Lax cookie was not. Either skip the check when HTTPSameSite() is SameSiteNoneMode, or keep it and say in the comment that it is intended under none because browsers that block third-party cookies drop that cookie.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declined: refusing cross-site regions under none is intended, because browsers that block or partition third-party cookies (Safari, Firefox) still drop or isolate that cookie in the dashboard's frame, so we keep one rule that behaves the same in every browser.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behavior is accepted: refusing under none is intended. The comment above crossSiteError still gives only the default SameSite=Lax cookie as the reason, and the Safari and Firefox reason is only in this thread. A maintainer who reads "default" can add a SameSiteNoneMode exemption, after which Safari users on a cross-site none deployment get the 401 page on every open and each retry mints another key. Put the reason in the comment, for example: "Browsers do not send the preview session cookie from the dashboard's frame across sites: they never send a SameSite=Lax cookie, and browsers that block or partition third-party cookies drop or isolate a SameSite=None one. The check therefore ignores --samesite-auth-cookie." (Leorio, Melody)

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 588ce57: the crossSiteError comment now also says browsers block or partition the preview cookie as a third-party cookie even with SameSite=None, which is why the rule applies under --samesite-auth-cookie=none too.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new clause says browsers "block or partition it as a third-party cookie even with SameSite=None", which reads as every browser. The round 4 Playwright probe showed Chromium and Firefox with default settings sending a framed SameSite=None; Secure cookie, and Firefox's partitioning stores it under the dashboard's site, where the same frame reads it, so only blocking breaks the flow (Safari by default, Chrome with third-party cookies off). A maintainer who tests in Chromium sees the cookie arrive and has no true reason left to keep the refusal under none. Suggested: "and Safari, or any browser set to block third-party cookies, drops it even with SameSite=None, so the check ignores --samesite-auth-cookie." (Melody, Leorio, Gon)

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 7cf249d: you are right that Chromium and Firefox send the framed SameSite=None cookie by default and Firefox's partition still serves the frame, so our earlier wording (and our reply naming Firefox) was wrong. The comment now says Safari, or any browser set to block third-party cookies, drops it even with SameSite=None; we keep the refusal under none so the rule does not depend on the browser.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified fixed in 7cf249d645.

🤖

Comment thread coderd/previews_test.go Outdated
wantMessage string
}{
{name: "NoWildcard", hostPrefix: true, wantMessage: "This region does not serve previews."},
{name: "CrossSite", appHostname: "*.apps.example.net", hostPrefix: true, wantMessage: "Previews need a wildcard access URL on the same site as the dashboard."},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P4 [CRF-61] The CrossSite row of TestPreviewSignInUnavailable also passes with a same-site app hostname, because the subtest's dashboard is coderdtest's 127.0.0.1. (Bisky)

Reproduced: with appHostname changed to *.apps.test.coder.com, the row still passes. Set AccessURL to https://dashboard.test.coder.com in the subtest, as TestPreviewAddress does, so example.net versus test.coder.com is the only reason for the 400.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declined: 127.0.0.1 and test.coder.com are also different sites, so the row passing with that hostname is the check working; removing the primary check fails this row, and TestPreviewSignIn already shows a same-site primary signing in.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defense accepted.

🤖

})
var sdkErr *codersdk.Error
require.ErrorAs(t, err, &sdkErr)
require.Equal(t, http.StatusBadRequest, sdkErr.StatusCode())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P4 [CRF-62] The proxy-region sign-in call asserts only status 400, so any refusal satisfies the step the comment at lines 67 to 69 describes. (Bisky)

An unknown agent, a bad slug, or a lookup refusal also returns 400. Assert sdkErr.Message equals "Previews need a workspace proxy on the same site as the dashboard.".

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declined: the exact message is asserted by the CrossSite row of TestPreviewSignInRegions, which fails if the proxy refusal changes reason; this step only shows why the test mints the proxy's token itself, and removing the check fails it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defense accepted.

🤖

Comment thread coderd/previews.go
if api.previewHosting == nil {
return nil, xerrors.Errorf("the deployment has no wildcard app hostname: %w", errRegionWithoutPreviews)
}
if registrableDomain(strings.Replace(api.AppHostname, "*", "preview", 1)) != registrableDomain(api.AccessURL.Host) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 [CRF-63] The PR description says only a workspace proxy is refused for being cross-site, but both endpoints now also refuse the primary when --wildcard-access-url is on another site than --access-url. (Leorio, Razor)

The squash commit uses the PR body, and #32442 (docs) is written from it, so main would not say that a deployment serving apps from a separate domain, such as *.coder-apps.com for coder.example.com, cannot use previews. Update the sentence to cover the primary wildcard and the proxy wildcard, and carry the requirement into #32442.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 99d01d9: the PR description now says a cross-site primary wildcard access URL is refused as well as a cross-site proxy.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified fixed in 99d01d9a2e.

🤖

Comment thread coderd/previews.go
hosting, err := api.previewHostingFor(ctx, req.RegionID)
var crossSite crossSiteError
if errors.As(err, &crossSite) {
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{Message: string(crossSite)})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P4 [CRF-64] A cross-site refusal returns only a Message, so it names neither of the domains that differ, and the proxy case no longer says that choosing another region works. (Leorio)

At 3cbebe3321 the cross-site proxy refusal went through errRegionWithoutPreviews and put the cause and "choose another region" in Detail. Add a Detail with both registrable domains, and wrap the sentinel for the proxy case as the other proxy refusals do.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declined: each cross-site case has its own message so the user reads the cause in the alert title, and the docs quote both messages and explain the site rule, which an admin needs more than the two domain names.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defense accepted.

🤖

@DanielleMaywood

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit switches to errors.AsType and corrects two doc comments. Findings this round: 1 P4 re-raised (comment only); new 2 P4, 1 Nit.

Verified fixed: three findings. Accepted defenses: five contested findings are closed. The workspace allow list on the preview key and the exact host comparison with a non-default port are recorded as operator decisions for the experimental release. Still open: the crossSiteError comment should state why the refusal also applies under --samesite-auth-cookie=none.

Out of scope (needs a ticket or explicit acceptance by a human):

  • coderd/x/chatd/chattool/openpreview.go:150 (#32440): OpenPreview treats any previewsUnavailable value, including a primary with no wildcard hostname, as unavailable in every region, so a same-site workspace proxy that could serve previews gets none from the tool.

CI: the failed jobs that were checked (changes, fmt, lint, test-go-pg) are cancelled runs with no failed step, so 99d01d9a2e has no completed CI result yet.

🤖 This review was automatically generated with Coder Agents.

Comment thread coderd/previews.go Outdated

// errRegionWithoutPreviews marks a region the user chose that has no preview
// hosts, as opposed to a failure looking it up. A region on another site gets
// crossSiteError instead. Its text follows each reason as the user's next step.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit [CRF-65] "Its text follows each reason as the user's next step" now follows a sentence about crossSiteError, so "Its" reads as crossSiteError's text, which has no "choose another region" suffix. (Gon)

Move the sentence before the crossSiteError sentence, or write "The sentinel's text follows each reason as the user's next step."

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 588ce57: the sentence about the sentinel's text now follows the first sentence, so "Its" refers to errRegionWithoutPreviews.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified fixed in 588ce5718b.

🤖

SubdomainProxyAPIKeyParam = "coder_application_connect_api_key_35e783"
// SubdomainProxyAPIKeyParam is defined in appurl, so previewhost can
// reserve it without importing this package.
SubdomainProxyAPIKeyParam = appurl.SubdomainProxyAPIKeyParam

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P4 [CRF-66] The app sign-in query parameter now has two names, appurl.SubdomainProxyAPIKeyParam and the alias workspaceapps.SubdomainProxyAPIKeyParam, and this PR's tests use both (previewhost_test.go:41, preview_test.go:246). (Zoro)

A reader has to check that the two are the same constant, and the alias exists only so nine existing references keep compiling. Delete the alias and change those references to appurl.SubdomainProxyAPIKeyParam.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declined: you are right that the PR's tests reach the same constant through two names. We kept the alias so the existing references on main stay untouched, and the comment on it says where the constant now lives, so a reader who checks finds one value.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defense accepted.

🤖

Comment thread coderd/previews.go
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 {
return nil, xerrors.Errorf("the deployment has no wildcard app hostname: %w", errRegionWithoutPreviews)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P4 [CRF-67] previewHostingFor writes "the deployment has no wildcard app hostname" again instead of using api.previewsUnavailable, which coderd.go:746 sets to that text for the same case. (Zoro)

resolvePreview has already returned for ErrHostPrefixCookieOff, so api.previewHosting == nil here means previewsUnavailable holds the no-wildcard error, and a change to the startup text makes the two disagree. Wrap the recorded reason: xerrors.Errorf("%w: %w", api.previewsUnavailable, errRegionWithoutPreviews).

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declined: you are right that the startup reason and this branch spell the same text twice and could drift if one changes. Both describe the same check today, and this one is only the detail under the "choose another region" response, so we are keeping the branch self-contained.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defense accepted.

🤖

@DanielleMaywood

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit rewrites two doc comments in coderd/previews.go. Findings this round: 1 P4 re-raised; 1 Nit new.

Verified fixed: the sentence order in the errRegionWithoutPreviews doc. Accepted defenses: the SubdomainProxyAPIKeyParam alias and the duplicated no-wildcard text are closed. Still open: the new crossSiteError clause says every browser blocks or partitions a SameSite=None cookie, which Chromium and Firefox defaults contradict; only blocking browsers such as Safari break the flow.

🤖 This review was automatically generated with Coder Agents.

return cookie
}

// Covers reports whether host is a preview host of h. That includes a

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit [CRF-69] The Hosting.host doc says it is "the wildcard host with the serving port", but Strict now drops the port when it is the scheme's default. (Meruem)

signInPreview compares the payload host, built from h.host, with the request host exactly, so a reader who trusts the doc expects *.apps.example.com:443, the value that would fail the compare. Say "the wildcard host as browsers send it: with the serving port unless it is the scheme's default, such as "*.apps.example.com:8443"".

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 7cf249d: the host doc now says it is the wildcard host as browsers send it, with the serving port unless it is the scheme's default.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified fixed in 7cf249d645.

🤖

@DanielleMaywood

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit corrects the crossSiteError and Hosting.host doc comments. Both open findings are verified fixed, and this round found nothing new.

No in-scope findings remain open. The whole-user allow list on the preview sign-in key and the exact host comparison with a non-default port stand as the author's recorded operator decisions for the experimental release. The out-of-scope items listed in earlier rounds still need a ticket or explicit acceptance by a human, including the #32440 OpenPreview handling of previewsUnavailable and script-set Domain cookies on preview hosts (#32439).

CI for 7cf249d645 was still pending at review time.

🤖 This review was automatically generated with Coder Agents.

@DanielleMaywood

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread coderd/previews_test.go
if tc.client != nil {
c = tc.client
}
// The address endpoint refuses what sign-in refuses.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defense accepted.

🤖

Comment thread coderd/previews_test.go

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."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defense accepted.

🤖

Comment thread coderd/previews_test.go Outdated
dv := coderdtest.DeploymentValues(t)
dv.Experiments = []string{string(codersdk.ExperimentOpenPreview)}
dv.HTTPCookies.EnableHostPrefix = !tc.hostPrefixOff
// The port checks that same-site comparisons ignore it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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."

🤖

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

🤖

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 <[email protected]>
@DanielleMaywood

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: the fetchRegions comment says users cannot usually access workspace proxies, but memberRole grants 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.

Comment thread coderd/previews.go
// such as through a token scope without workspace_proxy:read, counts as
// unknown.
proxy, err := api.Database.GetWorkspaceProxyByID(ctx, regionID)
if httpapi.Is404Error(err) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

🤖

Comment thread coderd/previews_test.go
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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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".

🤖

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

experimental Changes that might not necessarily be merged, until its approved to proceed with.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant