Skip to content

feat: serve agent previews on strict preview hosts - #32439

Draft
DanielleMaywood wants to merge 1 commit into
open-preview/agentfrom
open-preview/routing
Draft

DanielleMaywood wants to merge 1 commit into
open-preview/agentfrom
open-preview/routing

Conversation

@DanielleMaywood

@DanielleMaywood DanielleMaywood commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Adds the open-preview experiment, which is hidden from --experiments='*' and must be named explicitly, and serves agent previews on preview hosts under the existing wildcard app hostname in a strict mode. A security review (coder/security-assessments#437) showed that agent-written pages served like ordinary apps can reach the user's apps in every workspace, so preview hosts are locked down:

  • preview--<id>--<agent>--<workspace>--<owner> serves a file preview from the agent API (port 4), and preview--<port>--… serves a port. Both use the owner sharing level and ignore port shares. The port forwarding display app only hides the dashboard's ports UI, so it does not gate port previews, just as it does not gate port URLs. Connection logs record file previews as workspace_app and port previews as port_forwarding, under the preview-- slug.
  • coderd/workspaceapps/previewhost decides how previews are hosted. Coderd and workspace proxies build one Hosting at startup with previewhost.Strict, and every preview host request goes through servePreview. A later preview domain on another site would add a second constructor. Hosting.Sandbox, Hosting.URL and PreviewID.Slug are used by the sign-in (feat: sign previews in from the dashboard with a host-bound token #32522) and tool (feat(coderd): add the open_preview chat tool #32440) PRs. API.previewsUnavailable and previewhost.ErrHostPrefixCookieOff have no reader here beyond the startup log; the sign-in (feat: sign previews in from the dashboard with a host-bound token #32522) and tool (feat(coderd): add the open_preview chat tool #32440) PRs read them.
  • Hosting.ApplyPolicy adds the CSP (sandbox, default-src 'self', form-action 'self', frame-ancestors the dashboard) and drops Link headers, Clear-Site-Data and cookies with a Domain attribute. A response writer applies it to every response coderd writes on a preview host, including its own sign-in, error and 403 pages, at WriteHeader, because Go's ReverseProxy clears response headers after a 1xx. The writer drops 1xx responses other than 101. ReverseProxy writes a WebSocket 101 to the hijacked connection instead, so the proxy also applies the policy to every proxied response in ModifyResponse.
  • Requests whose Origin is another preview host of the same server get a 403, before CORS is applied.
  • DBTokenProvider.Issue refuses previews unless the experiment is on, --host-prefix-cookie is enabled, the request is a subdomain request, and the caller owns the workspace. The host-prefix requirement keeps a preview's script from replacing the user's Coder session cookie; without it, coderd still starts and logs a warning.
  • A preview without a session gets a 401 page that posts a coder-preview-sign-in-needed message to the dashboard, which then signs the user in once (see feat: sign previews in from the dashboard with a host-bound token #32522).
  • A top-level open of a preview host gets a 403 page that links to the dashboard, so a preview never loads outside the dashboard's wrapper. Browsers send no fetch metadata to a plain-HTTP host other than localhost, so there the page says previews need an HTTPS access URL. Service workers are refused.

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, this PR
  3. feat: sign previews in from the dashboard with a host-bound token #32522 Preview sign-in
  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 DanielleMaywood added the experimental Changes that might not necessarily be merged, until its approved to proceed with. label Nov 19, 2026
@DanielleMaywood DanielleMaywood changed the title feat: route file preview hostnames to the workspace agent feat: serve agent previews on strict preview hosts Nov 20, 2026
@DanielleMaywood
DanielleMaywood removed this pull request from stack #32443 November 20, 2026 11:36
@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: $92.60 / $100.00

Review history
  • R2 (2026-11-25), 11 Nit, 2 P1, 1 P2, 11 P3, 11 P4, COMMENT. Review
  • R3 (2026-11-25), 11 Nit, 2 P1, 1 P2, 11 P3, 11 P4, COMMENT. Review
  • R4 (2026-11-25): 14 reviewers, 13 Nit, 2 P1, 1 P2, 15 P3, 17 P4, COMMENT. Review
  • R5 (2026-11-26): 12 reviewers, 14 Nit, 2 P1, 1 P2, 15 P3, 17 P4, COMMENT. Review
  • R6 (2026-11-26): 4 reviewers, 14 Nit, 2 P1, 1 P2, 15 P3, 17 P4, APPROVE. Review
  • R7 (2026-11-26): 4 reviewers, 14 Nit, 2 P1, 1 P2, 15 P3, 17 P4, APPROVE. Review
  • R8 (2026-11-26): 4 reviewers, 14 Nit, 2 P1, 1 P2, 15 P3, 17 P4, APPROVE. Review
  • R9 (2026-11-26): 4 reviewers, 14 Nit, 2 P1, 1 P2, 15 P3, 17 P4, APPROVE. Review

deep-review v0.13.1 | Round 9 | 5e517bd..327e5ed

Last posted: Round 9, 49 findings (2 P1, 1 P2, 15 P3, 17 P4, 14 Nit), APPROVE. Review

Finding inventory

Finding inventory: PR #32439

Findings

# Sev Status Location Summary Round Reviewer Posted
CRF-1 P1 Author fixed (69ee6a9) previewhost.go:77 Covers claims existing apps with slug preview, which then get a 400 with the experiment off R1 Netero Yes
CRF-2 P3 Author fixed (69ee6a9) proxy.go:374 No test covers preview-origin refusal on path-based apps R1 Netero Yes
CRF-3 P3 Author fixed (69ee6a9) cookie.go:34 No test checks the preview session cookie is stripped before proxying R1 Netero Yes
CRF-4 P4 Author fixed (69ee6a9) previewhost.go:175 responseWriter.Flush and implicit-200 Write paths have no test R1 Netero, Bisky Yes
CRF-5 P4 Author fixed (69ee6a9) proxy.go:533 "does not serve previews" branch is unreachable in production R1 Netero Yes
CRF-6 P4 Author fixed (PR description edit) previewhost.go:63 Sandbox, URL, PreviewID.Slug have no production caller in this PR R1 Netero Yes
CRF-7 Nit Author contested; panel closed R4 (1/1 accept) cookie.go:34 "__Host-" literal duplicates codersdk.cookieHostPrefix R1 Netero Yes
CRF-8 P4 Author fixed (PR description edit) cors.go:109 PR description claims WorkspaceAppCors refuses preview origins; cors.go is unchanged R1 Netero Yes
CRF-9 P1 Author fixed (69ee6a9) previewhost.go:184 Proxied 101 response bypasses applyPolicy, so Domain cookies and Clear-Site-Data reach the browser R1 Melody, Pariston, Mafuuu, Ryosuke P1; Meruem, Hisoka, Kurapika P2 Yes
CRF-10 P2 Author fixed (69ee6a9) previewhost.go:21 allow-same-origin lets preview script set Domain cookies via document.cookie R1 Kurapika, Mafuuu Yes
CRF-11 P3 Author fixed (69ee6a9) preview.go:45 Plain-HTTP app hostname refuses every framed preview with a misleading message R1 Pariston, Kite, Luffy, Leorio Yes
CRF-12 P3 Author fixed (69ee6a9) preview.go:107 isFromOtherPreview lets Origin: null through; comment overclaims ping coverage R1 Hisoka P3, Melody Note Yes
CRF-13 P3 Author fixed (69ee6a9) provider.go:64 Without host prefix, any app host can toss coder_preview_session_token for the wildcard R1 Hisoka Yes
CRF-14 P3 Author fixed (69ee6a9) db.go:193 Port-forwarding display app gate restricts nothing the port subdomain app allows R1 Kite Yes
CRF-15 P3 Author fixed (69ee6a9) db.go:194 Owner refused by display-app gate sees generic "does not exist" page R1 Leorio Yes
CRF-16 P3 Author fixed (69ee6a9) request.go:313 File previews recorded as port_forwarding in connection log, untested R1 Ryosuke Yes
CRF-17 P3 Author contested; panel closed R4 (1/1 accept) proxy.go:805 Chat-header denylist is a hand copy of what agentchat trusts R1 Meruem Yes
CRF-18 P4 Author contested; panel closed R5 (1/1 accept) db_test.go:785 Public port share setup is not checked by any assertion R1 Bisky Yes
CRF-19 P3 Deferred (#32522, 3cbebe3) wsproxy.go:324 No test for previews served by a workspace proxy R1 Bisky Yes
CRF-20 P4 Author contested; panel closed R4 (1/1 accept) preview.go:92 "Back to site" link on in-frame error pages cannot navigate the tab R1 Kite Yes
CRF-21 P4 Author contested; panel closed R5 (1/1 accept) previewhost.go:41 Build Hosting inside NewServer instead of in each caller R1 Luffy Yes
CRF-22 P4 Author fixed (69ee6a9) appurl/preview.go:81 IsPreviewHostname matches app preview under suffix wildcards with numeric/hex agent names R1 Bisky Yes
CRF-23 P4 Author fixed (69ee6a9) preview_test.go:202 CORS strip assertion uses an empty CORSBehavior R1 Bisky Yes
CRF-24 P4 Author fixed (69ee6a9) appurl/preview.go:56 No test that AppSlugRegex rejects port preview slugs R1 Meruem Yes
CRF-25 P4 Author contested; panel closed R5 (1/1 accept) request.go:320 Agent route /api/v0/previews/ is a third string copy R1 Gon Yes
CRF-26 P4 Author fixed (69ee6a9) deployment.go:5564 Experiment comment names the open_preview tool, which this PR does not add R1 Gon P4, Leorio Nit Yes
CRF-27 Nit Author contested; panel closed R5 (1/1 accept) coderd.go:2267 previewHosting field comment restates the name and duplicates the nil rule R1 Gon Yes
CRF-28 Nit Author contested; panel closed R5 (2/2 accept) db.go:162 "wrapper" and "hop" undefined in comments (also preview.go:39) R1 Gon, Leorio Yes
CRF-29 Nit Author contested; panel closed R4 (1/1 accept) preview.go:15 servePreview doc opens by restating the name R1 Gon Yes
CRF-30 Nit Author contested; panel closed R4 (1/1 accept) previewhost.go:33 sandbox field comment duplicates the Sandbox() doc R1 Gon Yes
CRF-31 Nit Author contested; panel closed R4 (1/1 accept) previewhost.go:97 URL doc repeats the value of maxHostnameLabelLength R1 Gon Yes
CRF-32 Nit Author fixed (69ee6a9) appurl/preview.go:81 len(parts) < 5 is an unnamed segment count R1 Gon Yes
CRF-33 Nit Author contested; panel closed R4 (1/1 accept) proxy.go:805 removeCoderdAgentHeaders removes only chat headers R1 Gon Yes
CRF-34 Nit Author contested; panel closed R4 (1/1 accept) previewhost.go:132 responseWriter is called "preview policy writer" elsewhere R1 Gon Yes
CRF-35 Nit Author contested; panel closed R4 (1/1 accept) coderd.go:2269 One Hosting value has three names R1 Gon Yes
CRF-36 Nit Author contested; panel closed R4 (1/1 accept) db.go:478 Panic text no longer matches the Unwrap-chain condition R1 Leorio Yes
CRF-37 Note Dropped by orchestrator (comment states purpose, not only mechanism) appurl/preview.go:75 "Drop any prefix---" comment narrates code R1 Gon No
CRF-38 Note Dropped by orchestrator (clause gives the reason WriteHeader is the hook) previewhost.go:123 Wrap doc padded clause R1 Gon No
CRF-39 Note Note (body) previewhost.go:67 "preview host" has two definitions (Covers vs IsPreviewHostname) R1 Gon No
CRF-40 Note Note (body) f0bc2f2 Commit subject "strict" is opaque without reading previewhost.Strict R1 Leorio No
CRF-41 Note Note (body) db.go:166 Alone, this PR 401s every preview; sign-in arrives in #32522 R1 Leorio, Law No
CRF-42 Note Note (body) preview.go:105 Dashboard wrapper frame-src in #32441 is load-bearing for navigation containment R1 Pariston No
CRF-43 OOS Out of scope (body) cookie.go:23 StripCoderCookies misses __Host-coder_session_token after host prefix is turned off R1 Mafuuu No
CRF-44 OOS Out of scope (body) agent/api.go:20 Agent preview route sits behind chat middleware that trusts request headers R1 Meruem No
CRF-45 OOS Out of scope (body) request.go:312 Preview tokens carry the template CORSBehavior R1 Bisky No
CRF-46 OOS Out of scope (body) appurl.go:175 "---" prefix separator is an unnamed literal R1 Gon No
CRF-47 P3 Author fixed (e919721) proxy.go:116 ServerOptions.Previews doc says nil only without Hostname; coderd also leaves it nil without host prefix R4 Netero Yes
CRF-48 P4 Author fixed (PR description edit) coderd.go:746 API.previewsUnavailable and ErrHostPrefixCookieOff have no reader in this PR R4 Netero Yes
CRF-49 P3 Author contested; panel closed R5 (2/2 accept) wsproxy.go:324 Workspace proxy serves previews without checking its own --host-prefix-cookie R4 Kurapika, Hisoka Yes
CRF-50 P3 Author fixed (e919721) proxy_test.go:219 TestHandleSubdomainAppNamedPreview never reaches Covers, so it cannot catch a CRF-1 regression R4 Bisky Yes
CRF-51 P3 Author contested; panel closed R5 (1/1 accept) proxy.go:533 "This server does not serve previews." names no cause when --host-prefix-cookie is off R4 Leorio Yes
CRF-52 P3 Author contested; panel closed R5 (1/1 accept) db.go:165 Host-prefix refusal via a proxy renders the generic "does not exist" page R4 Leorio Yes
CRF-53 P4 Author contested; panel closed R6 (1/1 accept) previewhost.go:30 HTTPS message unreachable on plain HTTP; warning names a flag that breaks HTTP sign-in R4 Kite Yes
CRF-54 P4 Author contested; panel closed R5 (3/3 accept) cookie.go:32 Comment describes #32522's scheme-based cookie name, not this head R4 Gon P4, Mafuuu P4, Kite Nit Yes
CRF-55 P4 Author fixed (e919721) preview.go:144 isFromOtherPreview doc claims coverage where CSP is unenforced; Origin: null still passes R4 Melody Yes
CRF-56 P4 Author contested; panel closed R5 (1/1 accept) previewhost.go:193 Hijack doc "its writer" is ambiguous on where the 101 policy is applied R4 Gon Yes
CRF-57 Nit Author contested; panel closed R5 (1/1 accept) previewhost.go:136 ApplyPolicy Domain-cookie comment restates the loop R4 Gon Yes
CRF-58 Nit Author contested; panel closed R5 (1/1 accept) previewhost.go:34 CheckCookieConfig checks one field; name it for that field R4 Gon Yes
CRF-59 OOS Out of scope (body) proxy.go:541 WebSocket Origin checked only against preview hosts; same-site apps can open credentialed sockets R4 Kurapika No
CRF-60 Note Author accepted R7 (human operator decision for the experimental release; no ticket) previewhost.go:138 Page-script Domain cookies across the app wildcard accepted only in a code comment; needs a human decision R4 Kurapika No
CRF-61 Nit Author contested; panel closed R6 (1/1 accept) preview.go:143 Rewritten isFromOtherPreview doc repeats its first sentence and "it" has no clear referent R5 Gon Yes
CRF-62 Note Note (body) proxy.go:748 ApplyPolicy call would nil-deref if a preview token reached a server with nil Previews; invariant held only by agreeing checks in four files R5 Meruem No
CRF-63 OOS Out of scope (body) deployment.go:3701 --host-prefix-cookie description does not say it signs every user out over plain HTTP R6 Kite No

Contested and acknowledged

CRF-7 (Nit, cookie.go:34) - "__Host-" literal duplicates codersdk.cookieHostPrefix

  • Finding: The strip logic hard-codes "__Host-"; export codersdk.cookieHostPrefix and use it so the strip and the prefixing agree.
  • Author defense: Exporting the constant widens the SDK API for one string literal.
  • Panel closure: Pending. Netero raised it.

CRF-17 (P3, proxy.go:805) - Chat-header denylist is a hand copy of what agentchat trusts

  • Finding: removeCoderdAgentHeaders hard-codes the three headers agentchat.Middleware trusts; a fourth trusted header would reach the agent API from a preview page with no test failing. Share the list or forward an allowlist.
  • Author defense: Sharing the list is a cross-package refactor beyond this experiment; all three headers trusted today are stripped.
  • Panel closure: Pending. Meruem raised it.

CRF-18 (P3, db_test.go:785) - Public port share setup is not checked by any assertion

  • Finding: Changing the preview sharing level to public still passes the tests; add a plain-member case expecting 404, and credit the owner check in the comment.
  • Author defense: Issue refuses signed-out callers and non-owners before the sharing level matters, so the level has no observable effect to assert; the getDatabase comment now says port shares never apply to previews.
  • Panel closure: Pending. Bisky raised it.

CRF-19 (P3, wsproxy.go:324) - No test for previews served by a workspace proxy

CRF-20 (P4, preview.go:92) - "Back to site" link on in-frame error pages cannot navigate the tab

  • Finding: In-frame error pages offer a dashboard link that the sandbox keeps inside the frame; drop it from in-frame pages.
  • Author defense: The link only navigates the preview frame, which is harmless, and the page text says what to do.
  • Panel closure: Pending. Kite raised it.

CRF-21 (P4, previewhost.go:41) - Build Hosting inside NewServer

  • Finding: Both callers repeat the Strict construction from ServerOptions fields; building it in NewServer removes the nil-with-Hostname state.
  • Author defense: Refactor of two short call sites with no behavior change.
  • Panel closure: Pending. Luffy raised it.

CRF-25 (P4, request.go:320) - Agent route string is a third copy

  • Finding: /api/v0/previews/ is written in three places; a mount change would 404 every file preview with no compile error.
  • Author defense: A shared constant is a cross-package refactor with no behavior change.
  • Panel closure: Pending. Gon raised it.

CRF-36 (Nit, db.go:478) - Panic text no longer matches the Unwrap-chain condition

  • Finding: The panic says the writer "is not" a StatusWriter, but the check now walks the Unwrap chain.
  • Author defense: The panic marks a programming error and its text still names the missing writer.
  • Panel closure: Pending. Leorio raised it.

CRF-28 (Nit, db.go:162) - "wrapper" and "hop" undefined in comments

  • Finding: Comments in Issue and servePreview use "the wrapper" and "hop" without defining them.
  • Author defense: previewhost.Strict defines the wrapper as the dashboard page that frames the preview, and both comments sit in the sign-in flow a reader reaches from there. The reply does not address "hop".
  • Panel closure: Pending. Gon and Leorio raised it.

CRF-29 (Nit, preview.go:15) - servePreview doc opens by restating the name

  • Finding: The first sentence repeats the function name and parameter.
  • Author defense: Starting with the name is the Go doc convention; the sentence then states the non-obvious fact, and the proposed trim keeps the same content.
  • Panel closure: Pending. Gon raised it.

CRF-30 (Nit, previewhost.go:33) - sandbox field comment duplicates the Sandbox() doc

  • Finding: The field comment and the method doc state the same fact.
  • Author defense: The field comment serves readers of the struct and Sandbox() documents the exported contract; both are one line.
  • Panel closure: Pending. Gon raised it.

CRF-31 (Nit, previewhost.go:97) - URL doc repeats the value of maxHostnameLabelLength

  • Finding: The doc writes 63, which the constant holds.
  • Author defense: Callers need the 63-character DNS label limit stated, and the error message prints the constant, so runtime output cannot disagree with it.
  • Panel closure: Pending. Gon raised it.

CRF-33 (Nit, proxy.go:805) - removeCoderdAgentHeaders removes only chat headers

  • Finding: The name says agent headers but the function removes only chat headers.
  • Author defense: It removes headers coderd sets on its own agent requests, which today are the chat headers; the name says who owns them, so a future coderd-to-agent header still fits.
  • Panel closure: Pending. Gon raised it.

CRF-34 (Nit, previewhost.go:132) - responseWriter is called "preview policy writer" elsewhere

  • Finding: One type has two names across code and comments.
  • Author defense: responseWriter is unexported and the only writer in previewhost; comments in other packages describe its role because those readers never see the type name.
  • Panel closure: Pending. Gon raised it.

CRF-35 (Nit, coderd.go:2269) - One Hosting value has three names

  • Finding: previewHosting, Previews and previews name the same value.
  • Author defense: API.previewHosting names the type among many API fields, ServerOptions.Previews reads as an option, and renaming has no behavior change.
  • Panel closure: Pending. Gon raised it.

CRF-18 (P4, db_test.go:785) - R5 defense after re-raise

  • Finding: The public port share setup and its comment imply a covered regression that no assertion depends on; delete both.
  • Author defense: The share sets up the condition the 404 rows run under, so they show a public share on the same port opens nothing to others; the owner check, not the level, enforces it.
  • Panel closure: Pending. Bisky raised it.

CRF-21 (P4, previewhost.go:41) - R5 defense after re-raise

  • Finding: coderd and wsproxy build Hosting differently, and the divergence produces CRF-47, 48, 51 and the proxy gap in CRF-49; build it once in NewServer checking the serving process's own cookie config.
  • Author defense: The proxy's own cookie flag never affects the preview cookie (see CRF-49), and coderd's flag gates every region in Issue, so moving construction changes nothing any server serves.
  • Panel closure: Pending. Luffy raised it.

CRF-25 (P4, request.go:320) - R5 defense after re-raise

  • Finding: /api/v0/previews/ is a third copy and no test catches a mount change.
  • Author defense: TestAgentOpenPreviewIntegration fetches /api/v0/previews/<id>/ through the real agent, the same path request.go proxies to, so a mount change fails a test.
  • Panel closure: Pending. Gon raised it.

CRF-27 (Nit, coderd.go:2267) - R5 defense after re-raise

  • Finding: The field comment still restates the name and does not state that exactly one of two fields is set.
  • Author defense: "nil when previewsUnavailable says why not" already says one of them is set, and the only writer is the four-line switch below.
  • Panel closure: Pending. Gon raised it.

CRF-28 (Nit, db.go:162) - R5 defense on "hop"

  • Finding: "its cross-origin hop" is undefined.
  • Author defense: It refers to the auth redirect named earlier in the same sentence.
  • Panel closure: Pending. Gon and Leorio raised it.

CRF-49 (P3, wsproxy.go:324) - Proxy does not check its own host-prefix flag

  • Finding: Issue checks coderd's cookie config; a proxy with its own --host-prefix-cookie off keeps unprefixed cookies, so a tossed coder_preview_session_token breaks previews on that proxy.
  • Author defense: From feat: sign previews in from the dashboard with a host-bound token #32522 the preview host reads only __Host-coder_preview_session_token over HTTPS, which a sibling host cannot set with Domain, and a tossed plain cookie gets the same result through a real proxy with the flag on or off.
  • Panel closure: Pending. Kurapika and Hisoka raised it.

CRF-51 (P3, proxy.go:533) - Cause-less "does not serve previews" page

  • Finding: With the flag off, coderd shows a page that names no cause.
  • Author defense: In the stack the tool and the dashboard address endpoint refuse first with "Previews require --host-prefix-cookie. An administrator can enable it.", so only a hand-typed preview URL reaches this page.
  • Panel closure: Pending. Leorio raised it.

CRF-52 (P3, db.go:165) - Generic 404 for the proxy host-prefix refusal

  • Finding: Through a proxy the same refusal shows "does not exist".
  • Author defense: The dashboard asks the address endpoint first, which names the cause for every region, so the 404 is reachable only by framing a URL by hand; Issue keeps one generic page for every refusal.
  • Panel closure: Pending. Leorio raised it.

CRF-53 (P4, preview.go:51) - HTTPS message unreachable on plain-HTTP coderd

  • Finding: On plain-HTTP coderd with the flag off, users get the 404 instead; the warning names a flag that breaks HTTP sign-in.
  • Author defense: Plain-HTTP proxies and coderd with the flag on still show the HTTPS page, which is what the test builds, and the docs list HTTPS next to the flag.
  • Panel closure: Pending. Kite raised it.

CRF-54 (P4, cookie.go:32) - Comment describes #32522's naming rule

  • Finding: The comment describes scheme-based naming that does not exist at this head.
  • Author defense: The strip removes both names whatever decides the name; the sentence describes the stack as shipped with feat: sign previews in from the dashboard with a host-bound token #32522 and sits here so that PR need not touch cookie.go.
  • Panel closure: Pending. Gon, Mafuuu and Kite raised it.

CRF-56 (P4, previewhost.go:193) - Hijack doc "its writer"

  • Finding: "its writer" can be read as responseWriter, misdirecting readers about where the 101 policy is applied.
  • Author defense: It means the writer of the response on the hijacked connection; the Wrap doc above names the proxy and ApplyPolicy, and the WebSocket test fails if the ModifyResponse call is removed.
  • Panel closure: Pending. Gon raised it.

CRF-57 (Nit, previewhost.go:136) - ApplyPolicy comment

  • Finding: One sentence restates the loop.
  • Author defense: It says the strip covers only cookies the preview's server sends, which the loop cannot show, and contrasts with page-script cookies.
  • Panel closure: Pending. Gon raised it.

CRF-58 (Nit, previewhost.go:34) - CheckCookieConfig name

  • Finding: The name reads as a general validation but checks one field.
  • Author defense: The doc states the condition, the error names the flag, and the name stays true if the rule grows.
  • Panel closure: Pending. Gon raised it.

CRF-53 (P4, previewhost.go:30) - R6 defense after narrowed re-raise

  • Finding: ErrHostPrefixCookieOff says only "previews require --host-prefix-cookie"; on plain-HTTP coderd, an admin who follows it signs every user out. Name the HTTPS requirement in the same error.
  • Author defense: Signing users out when the flag is on over plain HTTP is how --host-prefix-cookie already behaves on main, and the previews docs list HTTPS next to the flag, so the error names only the setting it checks.
  • Panel closure: Pending. Kite raised it.

CRF-61 (Nit, preview.go:143) - isFromOtherPreview doc wording

  • Finding: The rewritten doc repeats its first sentence and "it" has no clear referent.
  • Author defense: The doc says what the function refuses and why the server check backs up the CSP, and "it" reads as the preview CSP.
  • Panel closure: Pending. Gon raised it.

CRF-60 (Note, previewhost.go:138) - Page-script Domain cookies across the app wildcard

  • Finding: With allow-same-origin, preview script can set Domain= cookies on the app wildcard (tossing coder_subdomain_app_session_token or other apps' cookies). The code comment records it as accepted; the review asked for a human decision.
  • Author accepted: PR comment IC_kwDOGkVX1s8AAAABrKbwDg (R7, posted by DanielleMaywood): "Confirmed for the experimental release (operator decision, no ticket)." Reasons given: ordinary workspace apps on the same wildcard can do the same, preview hosts strip Domain cookies their servers set, and the docs list it under what previews do not protect. Recorded as a human decision for the experimental release only.

Law analysis

Round 1. Effective LOC +1248 -10. Head f0bc2f2. Verdict: Don't split. Enforcement: Advisory.

Round log

Round 1

Netero (1 P1, 2 P3, 3 P4, 1 Nit, 1 Note) and Law (Don't split, advisory). No P0, so panel proceeds.
Round type: round 1, full panel. Multi-domain, security-sensitive (auth, cookies, origin matching): target 9-12. Specialists: ging-go, kurapika, ryosuke, melody, luffy. ging-ts excluded: the only .ts change is the generated typesGenerated.ts enum value. Killua excluded: no loops, caches or allocation changes beyond constant-size string checks. Core: pariston, mafuuu. Pool: bisky (tests), gon, leorio (floor), hisoka, kite. Wildcard (random from meruem, chopper, zoro, knov, razor): meruem.
Cross-check: 101 bypass raised by 7 reviewers, P1 kept (higher wins; Set-Cookie on 101 can set HttpOnly Domain cookies that document.cookie cannot). Gon comment findings rated P2 downgraded to Nit (keep-argument: AGENTS.md requires substantive comments; no behavior consequence, which fits Nit). Gon magic number P4 to Nit. CRF-8 raised from Note to P4 because it asks for a change. Bisky's Write-fallback coverage merged into CRF-4; Bisky's note on the TestHandleSubdomainPreviewIsolation assertion folded into CRF-5; Melody's Origin null note merged into CRF-12; Ryosuke's Hosting note is context for CRF-1, CRF-5 and CRF-21. Praise notes (Kite, Luffy, Kurapika) not recorded. ging-go: no findings. Reviewed against 4e4f638..f0bc2f2.

Round 2 update

BLOCKED. Churn guard: 20 addressed in 69ee6a9 (CRF-1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13, 14, 15, 16, 22, 23, 24, 26, 27, 32), 16 silent (CRF-6, 7, 17, 18, 19, 20, 21, 25, 28, 29, 30, 31, 33, 34, 35, 36). No reviewers ran; the fixes are author claims and are not verified by the panel. Round 1 post receipt was restored by the orchestrator from the existing GitHub review 6057764685 after the CLI got a 502 on a review that GitHub had created. Reviewed against d156c13..69ee6a9.

Round 3 update

BLOCKED. Head unchanged (69ee6a9). Author replied on all 16 round 2 silent findings. Churn guard: CRF-6 acknowledged (description edit), CRF-19 deferred to #32522, 7 contested (CRF-7, 17, 18, 20, 21, 25, 36), 7 silent because the replies are bare severity labels (CRF-28, 29, 30, 31: "Declined: wording nit."; CRF-33, 34, 35: "Declined: naming preference."). No reviewers ran. The round 2 fixes, including CRF-1 and CRF-9 (P1), are still unverified by the panel. Reviewed against d156c13..69ee6a9.

Round 4

Churn guard PROCEED: 14 contested (CRF-7, 17, 18, 20, 21, 25, 28, 29, 30, 31, 33, 34, 35, 36), CRF-19 deferred to #32522. Round type: restructure (exported signatures changed since R1: IsPreviewHostname replaced by ParsePreviewHostname; Hosting.ApplyPolicy, CheckCookieConfig, ErrHostPrefixCookieOff added). Law not run: effective additions grew 417 since R1. Netero runs (prior round was not Netero-only; CRF-7 contested). Full panel: specialists ging-go, kurapika, ryosuke, melody, luffy; core pariston, mafuuu; pool bisky, gon, leorio, hisoka, kite, meruem. Dispute check-in (previous agents): netero, meruem, bisky, kite, luffy, gon, leorio. Wildcard (random from chopper, zoro, knov, razor): chopper.
Panel results: CRF-7 closed by Netero; CRF-17 closed by Meruem; CRF-20 closed by Kite; CRF-29, 30, 31, 33, 34, 35 closed by Gon; CRF-36 closed by Leorio (all previous agents). Re-raised: CRF-18 by Bisky, narrowed to P4 (delete the setup that has no effect); CRF-21 by Luffy with new evidence (coderd and wsproxy constructions now diverge); CRF-25 by Gon (request.go already imports workspacesdk); CRF-28 by Gon and Leorio, narrowed to "hop". CRF-27 fix incomplete (Gon). Fix verification: CRF-9 verified by Meruem, Melody, Pariston, Mafuuu, Ryosuke, Kurapika with mutation tests; CRF-1 verified by Netero, but Bisky shows its regression test never reaches Covers (CRF-50); CRF-11 verified by Leorio and Pariston, with Kite's CRF-53 showing the branch unreachable in real HTTP deployments; CRF-13 holds on coderd only (CRF-49); CRF-12's new doc overclaims (CRF-55); CRF-16, 14, 15, 26, 32, 22, 23, 24, 4, 5 verified. Contradiction: Luffy says the Issue gate covers every server; Kurapika and Hisoka show it reads coderd's cookie config, not the proxy's. Both point at one construction that checks each server's own cookie config. Gon P2 comment findings downgraded to Nit (no behavior consequence); Gon's Hijack doc finding kept at P4 because it misdirects readers on the 101 policy path. Flake Check job 139552356292 was cancelled, not failed; its log is gone (BlobNotFound). Reviewed against d156c13..69ee6a9.

Round 5

Head e919721. Churn guard PROCEED: CRF-47, 50, 55 fixed in code, CRF-48 by description; 13 contested; CRF-19 deferred. Round type: fix round (interdiff +8 -6 in preview.go, proxy.go, proxy_test.go; comment and test edits only, no signature change). Panel: dispute check-in (previous agents) bisky, luffy, gon, leorio, kurapika, hisoka, kite, mafuuu; melody (CRF-55 code touched); ging-go and ryosuke (changed Go files); wildcard (random from meruem, chopper, zoro, knov, razor): meruem. Netero runs (new head). CI: the failed jobs (changes, lint, gen, check-build and dependents) were cancelled, not failed.
Panel results R5: CRF-18 closed by Bisky; CRF-21 closed by Luffy; CRF-25, 27, 56, 57, 58 closed by Gon; CRF-28 closed by Gon and Leorio; CRF-49 closed by Kurapika and Hisoka (verified against #32522: preview host reads only __Host-coder_preview_session_token over HTTPS, and the cookie is removed from cookiesToPrefix); CRF-51 and CRF-52 closed by Leorio (verified #32522 address endpoint message); CRF-54 closed by Gon, Mafuuu and Kite. All by previous agents. CRF-53 re-raised by Kite, narrowed to P4 on the ErrHostPrefixCookieOff text (previewhost.go:30): the only guidance names a flag that signs every user out on plain-HTTP coderd. Fixes verified: CRF-47 (Netero, Gon, Leorio, Melody, Ryosuke), CRF-50 (Netero, Bisky, Meruem by mutation; Ryosuke by coverage), CRF-55 (Melody). CRF-48 premise checked by orchestrator: #32522 reads api.previewsUnavailable with errors.Is(..., ErrHostPrefixCookieOff) and #32440 passes it to the tool. Gon's P2 on the rewritten isFromOtherPreview doc downgraded to Nit (doc matches code per Melody; wording only). CI failures on e919721 are cancelled jobs, not test failures. Reviewed against e68cd8b..e919721.

Round 6

Head 6747c02: rebase onto c6e31cc; git range-diff shows the PR commit identical to e919721 (only agent/agentpreview/preview_internal_test.go from base PR #32438 changed). Churn guard PROCEED: CRF-53 and CRF-61 contested, CRF-19 deferred. Round type: fix round, no PR code change. Panel: dispute check-in (previous agents) kite (CRF-53), gon (CRF-61); core mafuuu (minimum of 3); wildcard (random from meruem, chopper, zoro, knov, razor): chopper. Netero runs (SHA changed).
Panel results R6: CRF-53 closed by Kite (previous agent): the sign-out over plain HTTP is a property of --host-prefix-cookie on main, so the gap belongs to the flag's description (CRF-63, out of scope); Kite could not read #32442 to confirm the docs claim (HTTP 401). CRF-61 closed by Gon (previous agent). Mafuuu and Chopper: no findings. Netero: no findings. CI on 6747c02: cancelled jobs (check-build, sqlc-vet checked), not test failures. All findings closed except CRF-19 (deferred to #32522). Reviewed against c6e31cc..6747c02.

Round 7

Head unchanged (6747c02). New author comment IC_kwDOGkVX1s8AAAABrKbwDg records a human operator decision accepting CRF-60 for the experimental release, no ticket. Churn guard PROCEED: CRF-60 acknowledged, CRF-19 deferred, nothing else open. Round type: fix round with no code change since the R6 panel. Panel at the 3-reviewer minimum: pariston, mafuuu, kurapika; wildcard (random from meruem, chopper, zoro, knov, razor, kite): zoro. Netero runs (prior round was not Netero-only).
Panel results R7: Netero, Pariston, Mafuuu, Kurapika, Zoro: no findings. Pariston ran a scratch path-traversal test against the agent router (..%2F variants stay on the previews route). Kurapika: CRF-60 acceptance covers the experiment only; leaving the experiment needs a new decision, and no ticket records that. CI on 6747c02: Storybook job 139858108915 failed in the Pixel visual-diff step (pixel: build finished with status failed, no per-story diff in the log; the PR's only site/ change is generated typesGenerated.ts), linkspector was a runner fault, and the other failures are cancelled duplicates of jobs that passed in run 45805005859. Reviewed against c6e31cc..6747c02.

Round 8

Head 4cae110: rebase onto c78dfe7; git range-diff shows the PR commit identical to 6747c02 (base PR #32438 added 10 lines to agent/agentpreview/preview_test.go). No new author comments besides the review trigger. Churn guard PROCEED: CRF-60 acknowledged, CRF-19 deferred. Round type: fix round with no PR code change. Panel at the 3-reviewer minimum: pariston, mafuuu, hisoka; wildcard (random from meruem, chopper, knov, razor, kite): chopper. Netero runs (SHA changed).
Panel results R8: Netero, Pariston, Mafuuu, Hisoka, Chopper: no findings; all re-ran the preview tests at 4cae110. CI: the 18 failed jobs are cancelled zero-duration runs from 13:24:24Z; in the second run, 9 jobs have passed (fmt, offlinedocs, test-js, check-build, gen, lint, lint-docs, check-docs and one more), 3 were skipped, and 8 were still pending (test-go-*, Storybook, test-e2e, Flake Check) at review time. Reviewed against c78dfe7..4cae110.

Round 9

Head 327e5ed: rebase onto 5e517bd; git range-diff shows 4cae110787 = 327e5edcc3 (base PR #32438 changed agent/agentpreview/preview_test.go, +3 -2). No new author comments besides the review trigger. Churn guard PROCEED: CRF-60 acknowledged, CRF-19 deferred. Round type: fix round with no PR code change. Panel at the 3-reviewer minimum: pariston, mafuuu, melody; wildcard (random from meruem, chopper, knov, razor, kite, zoro): razor. Netero runs (SHA changed).
Panel results R9: Netero, Pariston, Mafuuu, Melody, Razor: no findings; Netero, Pariston, Mafuuu and Melody re-ran the preview tests at 327e5ed. CI: the 19 failed checks are cancelled zero-duration runs from 13:56:25Z plus the first run's required aggregate; in the second run required passed, every test-go-*, test-js, test-e2e, lint, gen, fmt, check-build, docs job and Flake Check passed, and Storybook was still running at review time. Reviewed against 5e517bd..327e5ed.

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 the hidden open-preview experiment and serves file and port previews on preview-- hosts with a CSP and header-filtering response writer, owner-only issuance and Origin refusal. Findings: 2 P1, 1 P2, 11 P3, 11 P4, 11 Nit.

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

  • coderd/httpapi/cookie.go:23: StripCoderCookies matches only the exact name coder_session_token, so after a deployment turns the host prefix off, __Host-coder_session_token is still forwarded to path apps on the dashboard host, which then receive the user's session token.
  • agent/api.go:20: the agent's preview file route sits behind agentchat.Middleware, which trusts Coder-Chat-Id and related request headers, so every caller that reaches a preview must strip them first.
  • coderd/workspaceapps/request.go:312: preview tokens carry the template's CorsBehavior, so a later change that reads token.CORSBehavior on preview hosts would apply passthru CORS to agent-written pages.
  • coderd/workspaceapps/appurl/appurl.go:175: the "---" prefix separator is an unnamed literal, and this PR adds two more copies.

Notes:

  • Hosting.Covers and appurl.IsPreviewHostname define "preview host" differently (any preview-- prefix versus a valid slug and five segments); a caller choosing one for a security check has to read both bodies.
  • The commit subject and PR title use "strict", which a git log reader cannot interpret without reading previewhost.Strict.
  • With this PR alone, every preview request gets the 401 "Reopen this preview from Coder to sign in again.", because the sign-in that sets coder_preview_session_token arrives in #32522. The experiment is hidden, so only deployments that name it are affected.
  • Nothing in this PR stops a preview frame from navigating itself to another app host; the dashboard wrapper's frame-src in #32441 carries that containment.

coderd/httpmw/cors.go:109

P4 [CRF-8] The PR description says WorkspaceAppCors refuses preview origins, but this PR does not change cors.go. (Netero)

What refuses those origins is isFromOtherPreview in HandleSubdomain, which runs before the CORS middleware, and WorkspaceAppCors would still allow a same-user preview origin because ParseSubdomainAppURL now parses preview hosts. If the isFromOtherPreview check moves, CORS will not refuse these origins. Correct the description, or add the refusal to WorkspaceAppCors.

🤖

🤖 This review was automatically generated with Coder Agents.

if i := strings.LastIndex(subdomain, "---"); i >= 0 {
subdomain = subdomain[i+len("---"):]
}
return strings.HasPrefix(subdomain, appurl.PreviewSlugPrefix)

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.

P1 [CRF-1] Covers claims every host whose label starts with preview--, which includes every existing subdomain app with slug preview, so those apps break on every deployment with a wildcard app hostname, with the experiment off. (Netero)

preview matches provisioner.AppSlugRegex, and coderd.go and wsproxy.go build Hosting whenever AppHostname is set, so preview--agent--workspace--user goes to servePreview, where Parse fails and the user gets a 400 "This is not a valid preview address." with the sandbox CSP. A scratch test with newPreviewServer reproduced status=400 for both the agent and agentless forms, and PreviewWithoutAgentIsAppSlug in appurl_test.go shows the host still parses as app preview. Make Covers require that the first two -- segments form a valid preview slug (as IsPreviewHostname does), or reserve the preview slug at template import, and add a regression case for an app named preview.

🤖

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 69ee6a9acf: Covers uses ParsePreviewHostname. The regression test written for this fix does not reach Covers; see the TestHandleSubdomainAppNamedPreview comment.

🤖


// Hijack hands over the connection for WebSocket upgrades, whose 101
// response does not load a page.
func (w *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, 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.

P1 [CRF-9] A preview server's WebSocket 101 response reaches the browser with Set-Cookie: ...; Domain= and Clear-Site-Data intact, because applyPolicy runs only from WriteHeader and httputil.ReverseProxy never calls it for a 101. (Melody, Pariston, Mafuuu, Ryosuke, Meruem, Hisoka, Kurapika)

handleUpgradeResponse calls Hijack, copies the upstream headers into rw.Header(), and writes them with res.Write(brw) on the hijacked connection (net/http/httputil/reverseproxy.go:853-882); a scratch test with Strict(...).Wrap around a ReverseProxy returned status=101 set-cookie=["x=1; Domain=apps.example.com"] clear-site-data="\"cookies\"". A port preview page can run new WebSocket(location.href) against its own server, which can then set an HttpOnly cookie for the whole app wildcard, including one named like the hashed coder_subdomain_app_session_token. Browser storage of handshake cookies is inferred from RFC 6455 and was not run in a browser. ReverseProxy calls ModifyResponse before handleUpgradeResponse, so apply the cookie, Link and Clear-Site-Data filter to res.Header in ModifyResponse for preview tokens, and assert the 101 headers in the WebSocket case of TestServePreviewPolicy.

🤖

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 69ee6a9acf: ModifyResponse applies the policy before ReverseProxy writes the 101, and TestServePreviewPolicy/WebSocket fails when that call is removed.

🤖


const (
maxHostnameLabelLength = 63
strictSandbox = "allow-scripts allow-same-origin allow-forms allow-modals allow-downloads"

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-10] The strict sandbox keeps allow-same-origin, so preview script can write Domain= cookies through document.cookie, which the Set-Cookie filter in applyPolicy never sees. (Kurapika, Mafuuu)

A page on preview--0123abcd--main--ws--alice.apps.example.com can run document.cookie = "x=1; Domain=apps.example.com; Path=/", and no CSP directive blocks it; when the wildcard is under the access URL host and EnableHostPrefix is off (the default), it can plant coder_session_token with Path=/api for the dashboard. This is inferred from browser cookie rules, not run in a browser. Header filtering cannot enforce the property the applyPolicy comment states while previews share a registrable domain with apps and the dashboard. Either drop allow-same-origin (previews lose same-origin storage and credentialed fetches to their own host), serve previews on a separate site, or state in the comment and the security review that preview script can still set cookies across the wildcard.

🤖

// so a request without it is treated as a page load. Chromium sends no
// fetch metadata with a WebSocket handshake, which never loads a page.
dest := r.Header.Get("Sec-Fetch-Dest")
if dest == "document" || (dest == "" && !httpapi.IsWebsocketUpgrade(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-11] On a deployment whose app hostname is plain HTTP and not localhost, every framed preview gets the 403 "Previews open only inside a Coder chat. Open this preview from its chat.", even when opened from the chat. (Pariston, Kite, Luffy, Leorio)

Browsers send Sec-Fetch-Dest only to potentially trustworthy origins, as the comment above states, so dest == "" holds for every iframe and fetch request on http://*.apps.example.com. The user is told to do what they already did, and the operator gets no log line naming the cause, because previewhost.Strict accepts an http access URL. Have Strict refuse or log for http with a non-localhost host so previews are reported as unavailable, or show a page that says previews need an HTTPS app hostname when no fetch metadata is present and r.TLS == nil.

🤖

Comment thread coderd/workspaceapps/preview.go Outdated
// of a link's ping attribute.
func isFromOtherPreview(r *http.Request, host string) bool {
origin, err := url.Parse(r.Header.Get(httpmw.OriginHeader))
if err != nil || origin.Host == "" || appurl.HostnamesMatch(origin.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.

P3 [CRF-12] isFromOtherPreview returns false for Origin: null, which a preview page can produce by framing one of its own pages with <iframe sandbox="allow-scripts" src="/p.html">. (Hisoka, Melody)

url.Parse("null") gives an empty Host, so the request passes on every app host and on path-based apps, and the nested frame passes frame-src 'self' and the Sec-Fetch-Dest: iframe check. The doc comment says the check covers <a ping>, but the Fetch spec puts pings under connect-src, so either CSP already blocks pings or, in a browser that does not, a null-origin ping reaches the user's other apps (with cookies when --samesite-auth-cookie=none). Not run in a browser. Refuse Origin: null on app hosts, or at minimum correct the comment so it does not claim the ping case.

🤖

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

parts := strings.Split(label, "--")
if len(parts) < 5 {

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-32] len(parts) < 5 is an unnamed count of hostname segments (preview, target, agent, workspace, user). (Gon)

Name it, for example const previewHostnameSegments = 5, so the check is tied to the ParseSubdomainAppURL grammar.

🤖

proxy.ServeHTTP(rw, r)
}

func removeCoderdAgentHeaders(h http.Header) {

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-33] removeCoderdAgentHeaders deletes only the three chat headers, which the test calls "chat headers". (Gon)

Rename to removeChatHeaders.

🤖

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: naming preference.

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.

Still open. The name says "agent headers", but the function removes only the three chat headers, and a reader deciding whether some other agent header is stripped will trust the name. Rename it, or say why the broader name is accurate.

🤖

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 function removes the headers coderd sets for its own agent requests, which today are the chat headers; removeCoderdAgentHeaders names who owns them, so a future coderd-to-agent header added there still fits the name.

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 &responseWriter{ResponseWriter: rw, csp: h.csp}
}

type responseWriter 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.

Nit [CRF-34] The type responseWriter is called "the preview policy writer" in preview.go, db.go and db_test.go. (Gon)

Rename the type to policyWriter so code and comments use one name.

🤖

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: naming preference.

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.

Still open. Comments in preview.go, db.go, db_test.go and proxy.go call this type "the preview policy writer", but the code names it responseWriter, so a search for one name misses the other. Use one name in both, or say why two names do not mislead.

🤖

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: responseWriter is unexported inside previewhost, where it is the only writer, and the comments in other packages describe its role (the preview policy writer) because those readers never see the type name.

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/coderd.go Outdated
mcpHTTPClient *http.Client
// previewHosting is how this server hosts agent-authored previews. It is
// nil without a wildcard app hostname.
previewHosting *previewhost.Hosting

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-35] The same *previewhost.Hosting value is previewHosting in API, Previews in ServerOptions, and previews in wsproxy.New. (Gon)

Rename API.previewHosting to previews to match the ServerOptions field.

🤖

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: naming preference.

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.

Still open. The same value is previewHosting, Previews and previews across coderd.go, ServerOptions and wsproxy.go, so a grep for one misses the others. Use one name, or say why each needs its own.

🤖

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: API already has many fields, and previewHosting says the value is a previewhost.Hosting there, while ServerOptions.Previews reads as an option; matching the names would rename a field used across coderd.go for 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: each name is read only in its own file.

🤖

sw, ok := w.(*tracing.StatusWriter)
sw, ok := statusWriterOf(w)
if !ok {
panic("dev error: http.ResponseWriter is not *tracing.StatusWriter")

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-36] The panic text "http.ResponseWriter is not *tracing.StatusWriter" no longer describes the failed condition. (Leorio)

statusWriterOf walks the Unwrap chain, so the panic fires when no writer in the chain is a *tracing.StatusWriter. Change it to "dev error: http.ResponseWriter does not wrap a *tracing.StatusWriter".

🤖

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 panic marks a programming error and its text still identifies the missing writer; 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: the panic names the type missing from the chain, and statusWriterOf is three lines above.

🤖

@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 head (69ee6a9) changes code or the PR description for 20 of the 36 round 1 findings, including both P1s (the 101 policy bypass and Covers claiming apps named preview). The panel has not yet checked these fixes. 16 findings have no code change and no reply, so further review is blocked until each one gets a fix or a reply on its thread: fix in this PR, a linked issue, or a reason it should not be fixed.

Unaddressed:

  • P3: chat-header denylist in removeCoderdAgentHeaders is a hand copy of what agentchat trusts (proxy.go:810).
  • P3: the public port share setup in PreviewSubdomain is not checked by any assertion (db_test.go:786).
  • P3: no test for previews served by a workspace proxy (wsproxy.go:324).
  • P4: Hosting.Sandbox, Hosting.URL and PreviewID.Slug have no production caller in this PR. The description now names #32522 and #32440 as callers; a reply on the thread closes it.
  • P4: "Back to site" on in-frame error pages cannot navigate the tab, and the new signed-out page adds another (preview.go:111, preview.go:132).
  • P4: coderd.go and wsproxy.go each build Hosting instead of NewServer building it (previewhost.go:58).
  • P4: /api/v0/previews/ is a third copy of the agent route string (request.go:322).
  • Nit: "__Host-" literal duplicates codersdk.cookieHostPrefix (cookie.go:34).
  • Nit: "wrapper" and "hop" are undefined in comments (db.go:170, preview.go:43).
  • Nit: the servePreview doc opens by restating the name.
  • Nit: the sandbox field comment duplicates the Sandbox() doc (previewhost.go:50).
  • Nit: the URL doc repeats the value of maxHostnameLabelLength (previewhost.go:101).
  • Nit: removeCoderdAgentHeaders removes only chat headers (proxy.go:810).
  • Nit: responseWriter is called "the preview policy writer" elsewhere (previewhost.go:159).
  • Nit: one Hosting value has three names (previewHosting, Previews, previews).
  • Nit: the panic text no longer matches the Unwrap chain condition (db.go:481).

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

No new commits since the last review. The thread replies answer 9 of the 16 findings that were open: one handled in the description, the proxy test deferred to #32522, and 7 declined with reasons, which the panel will judge when it next runs. Seven Nits still block the panel because their replies give only a label ("wording nit", "naming preference") and not a reason the code should stay. Each one needs a code change or one sentence on why the current text does not mislead a reader. The fixes pushed for round 1, including both P1s, have not yet been checked by the panel.

Still open:

  • "wrapper" and "hop" undefined in comments (db.go:170, preview.go:43).
  • servePreview doc opens by restating the name.
  • sandbox field comment duplicates the Sandbox() doc.
  • URL doc repeats the value of maxHostnameLabelLength.
  • removeCoderdAgentHeaders removes only chat headers.
  • responseWriter is called "the preview policy writer" elsewhere.
  • One Hosting value has three names (previewHosting, Previews, previews).

🤖 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 panel checked the round 1 fixes at 69ee6a9. Both P1 fixes hold: the 101 policy filter in ModifyResponse and Covers using ParsePreviewHostname were confirmed with mutation tests. The regression test for the Covers fix does not reach Covers, though (below). Of the 14 contested findings, 10 are closed and 4 are re-raised in their threads. New findings: 5 P3, 5 P4, 2 Nit; re-raised: 3 P4, 2 Nit.

Five findings share one cause: coderd leaves Previews nil without --host-prefix-cookie, and the workspace proxy always builds it and never checks its own cookie config. The five are the stale Previews doc, the unread previewsUnavailable, the cause-less "does not serve previews" page, the unreachable HTTPS message, and the proxy gap. One construction in NewServer that checks the serving process's own cookie config could address all five.

CI: the Flake Check job on this head was cancelled, not failed, and its log is no longer available.

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

  • coderd/workspaceapps/proxy.go:541: WebSocket handshakes to subdomain apps and port previews are refused only when Origin is another preview host, so a page on any same-site non-preview app (for example another user's public app) can open a credentialed WebSocket to the user's port app or port preview. Port URLs already allow this through the wildcard app cookie.

Notes:

  • Preview page script can still set Domain= cookies on the app wildcard (for example tossing coder_subdomain_app_session_token or other apps' cookies). The ApplyPolicy comment records this as accepted. Accepting it for the experiment is a human decision for the security review (coder/security-assessments#437), not one the code comment can make.

🤖 This review was automatically generated with Coder Agents.


var previews *previewhost.Hosting
if opts.AppHostname != "" {
previews, err = previewhost.Strict(opts.AppHostname, opts.AccessURL, opts.DashboardURL)

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-49] A workspace proxy serves previews whether or not its own --host-prefix-cookie is on, so the cookie-tossing fix holds only on coderd. (Kurapika, Hisoka)

Issue checks p.DeploymentValues.HTTPCookies, which is coderd's config, but the proxy reads cookies with its own cfg.HTTPCookies (enterprise/cli/proxyserver.go:267), and that flag defaults to off. With it off, HTTPCookieConfig.Middleware keeps unprefixed cookies, so a page on any app or preview host of the proxy can set coder_preview_session_token=x; Domain=<proxy wildcard>, and the user's previews on that proxy get the 401 page or the owner 404 until it expires (inferred from the cookie code paths, not run in a browser). Gate previews on the proxy's own cookie config here, in the same place coderd does.

🤖

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 proxy's own --host-prefix-cookie never applies to the preview cookie, since from #32522 the preview host reads only __Host-coder_preview_session_token over HTTPS, which a sibling host cannot set with Domain, and a tossed plain cookie gets the same result through a real proxy with that flag on or off.

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, checked against #32522: the preview host reads only __Host-coder_preview_session_token over HTTPS, and the cookie leaves cookiesToPrefix, so the proxy's flag does not affect it and a sibling host cannot set it with Domain. At this head nothing sets a preview cookie.

🤖

}))
t.Cleanup(upstream.Close)

dv := coderdtest.DeploymentValues(t)

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-50] TestHandleSubdomainAppNamedPreview never runs Hosting.Covers, so it cannot catch a regression of the fix for apps named preview. (Bisky)

dv does not set HTTPCookies.EnableHostPrefix, so coderd leaves previewHosting nil and HandleSubdomain skips Covers in both subtests. Putting the old prefix check back into Covers still passes; with dv.HTTPCookies.EnableHostPrefix = true, the unmutated test passes and the mutated one fails at line 277 (reproduced). Set EnableHostPrefix, and loop over it alongside the experiment, because it, not the experiment, decides whether coderd builds Hosting.

🤖

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 e919721: TestHandleSubdomainAppNamedPreview now enables the host prefix cookie so it reaches Covers, and fails when HandleSubdomain claims every preview-- 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.

Verified fixed in e919721399: with Covers replaced by the old preview-- prefix check, the test now fails at proxy_test.go:277.

🤖

site.RenderStaticErrorPage(rw, r, site.ErrorPageData{
Status: http.StatusNotFound,
Title: "Application Not Found",
Description: "This server 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-51] On coderd with open-preview on and --host-prefix-cookie off, every preview shows "This server does not serve previews.", which names no cause and no action. (Leorio)

This branch is now how coderd refuses previews without the host prefix, and only the startup warning names the flag. Put the cause on the page, as proxy.go:344 does for path apps, for example "Previews are off on this deployment because --host-prefix-cookie is not set. Ask an administrator to enable 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.

Declined: a user of this stack never reaches that page with the flag off, because the tool refuses with the --host-prefix-cookie reason and the dashboard shows the address endpoint's "Previews require --host-prefix-cookie. An administrator can enable it." before it loads any frame, so only a hand-typed preview URL sees this 404.

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: #32522's address endpoint returns "Previews require --host-prefix-cookie. An administrator can enable it." before any frame loads, so only a hand-typed URL reaches this page.

🤖

}
// This also refuses workspace proxies' previews, whose tokens coderd
// issues here.
if err := previewhost.CheckCookieConfig(p.DeploymentValues.HTTPCookies); isPreview && 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.

P3 [CRF-52] The same --host-prefix-cookie refusal, reached through a workspace proxy, renders "The application or workspace you are trying to access does not exist or you do not have permission to access it." (Leorio)

The proxy builds Hosting without the cookie check, so its preview requests reach this line, and WriteWorkspaceApp404 sends ErrHostPrefixCookieOff only to a debug log. One setting then shows two different pages, and the proxy one tells the owner the workspace may not exist. Use writePreviewError with a 403 and the same text as the coderd page.

🤖

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 dashboard asks the address endpoint before it frames a proxy preview, and that endpoint refuses every region without --host-prefix-cookie and names the cause, so this 404 is only reachable by framing a preview URL by hand, and Issue keeps the generic page it uses for every refusal.

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, for the same reason as the coderd page. Whether the dashboard in #32441 always asks the endpoint before framing was not checked here.

🤖

dest := r.Header.Get("Sec-Fetch-Dest")
if dest == "document" || (dest == "" && !httpapi.IsWebsocketUpgrade(r)) {
description := "Previews open only inside a Coder chat. Open this preview from its chat."
if dest == "" && s.AccessURL.Scheme == "http" && !isLocalhostName(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-53] On a plain-HTTP deployment where users can sign in, "Previews need an HTTPS access URL." is never shown, and the startup warning tells the operator to set a flag that breaks dashboard sign-in over HTTP. (Kite)

Coderd builds Hosting only with --host-prefix-cookie, which names the session cookie __Host-coder_session_token, and browsers refuse __Host- cookies from a non-secure origin (inferred from the cookie prefix rules, not run in a browser). With the flag off, as on every working HTTP deployment, the user gets the cause-less "does not serve previews" page instead. TestServePreviewPolicy/PlainHTTP builds Hosting directly, so it passes on a configuration coderd never builds. Check for HTTPS in the same gate as the host prefix and name both in its error, then drop this 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 coderd with the flag off shows the 404 instead of the HTTPS page, but every plain-HTTP workspace proxy and coderd with the flag on still show the HTTPS page, which is the configuration that test builds, and the docs list HTTPS as a requirement next to --host-prefix-cookie, so an operator on plain HTTP is told 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.

Partly accepted: a plain-HTTP workspace proxy behind HTTPS coderd with the flag on does reach the HTTPS page, so the "unreachable" part is withdrawn. Still open, narrowed (P4, previewhost.go:30): the only guidance this PR gives is ErrHostPrefixCookieOff's text, "previews require --host-prefix-cookie", and #32522 shows users the same requirement. On a plain-HTTP coderd, an admin who follows it turns on the flag, HTTPCookieConfig.Middleware then drops coder_session_token, and browsers refuse the non-Secure __Host-coder_session_token that replaces it, so every user is signed out until the flag is turned off (inferred from the __Host- rules, not run in a browser). The HTTPS requirement is documented in #32442, not next to this message. Make the error name both, for example "previews require an HTTPS access URL and --host-prefix-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: thanks for withdrawing the unreachable part. Signing users out when the flag is on over plain HTTP is how --host-prefix-cookie already behaves on main, and the previews page lists HTTPS as a requirement next to the flag, so the error keeps naming only the setting it checks.

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: the sign-out over plain HTTP is how --host-prefix-cookie behaves on main by any route, so the warning belongs in that flag's description, which is listed as out of scope in the review body.

🤖

_ = http.NewResponseController(w.ResponseWriter).Flush()
}

// Hijack hands over the connection for WebSocket upgrades. A response

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-56] The Hijack doc says "its writer applies the policy", and a reader can take "its writer" to be responseWriter, which never sees a proxied 101. (Gon)

The 101 policy is applied by ModifyResponse in proxy.go:745. A reader who believes this writer covers upgrades could remove that call, which reopens the WebSocket cookie bypass. Trim this doc to point at Wrap, which already states the fact, and drop the repeat from the servePreview doc.

🤖

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: "its writer" is the writer of the response sent on the hijacked connection, the Wrap doc just above names the proxy and ApplyPolicy for upgrades, and TestServePreviewPolicy/WebSocket fails if that ModifyResponse call 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.

Defense accepted: the Wrap doc names ApplyPolicy for upgrades, and the WebSocket test fails if the ModifyResponse call is removed.

🤖

Comment thread coderd/workspaceapps/proxy.go Outdated
HostnameRegex *regexp.Regexp
RealIPConfig *httpmw.RealIPConfig
// Previews decides which hosts serve agent-authored previews and the
// policy their responses carry. It is nil when Hostname is empty.

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-47] The ServerOptions.Previews doc says "It is nil when Hostname is empty", but coderd now also leaves it nil when Hostname is set and --host-prefix-cookie is off. (Netero)

TestPreviewsNeedHostPrefixCookie depends on that state. A reader who trusts the doc and treats Hostname != "" as Previews != nil could remove the s.Previews != nil check in HandleSubdomain and dereference nil on deployments without the host prefix. Update the doc to cover both cases.

🤖

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 e919721: the ServerOptions.Previews doc now covers the nil case.

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 e919721399: the doc's two nil cases match the New switch in coderd.go and wsproxy.New.

🤖

Comment thread coderd/coderd.go
options.Logger.Warn(ctx, "workspace previews are unavailable", slog.Error(api.previewsUnavailable))
}
case options.AppHostname == "":
api.previewsUnavailable = xerrors.New("the deployment has no wildcard app hostname")

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-48] API.previewsUnavailable is written and read only by the warning log in the same switch, and nothing compares against the exported previewhost.ErrHostPrefixCookieOff. (Netero)

The PR description names the later PRs that use Sandbox, URL and Slug, but not these two. Name the PR that reads them, or move them there.

🤖

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 e919721: the PR description now says this PR only logs previewsUnavailable at startup and that #32522 and #32440 read 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: #32522 reads api.previewsUnavailable with errors.Is(..., previewhost.ErrHostPrefixCookieOff), and #32440 passes it to the tool.

🤖

header.Del("Link")
// Clear-Site-Data clears cookies for the whole registrable domain.
header.Del("Clear-Site-Data")
// A cookie with a Domain attribute is sent to the user's other apps. This

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] "This strips the ones the preview's server sets" restates the Del/Add loop below it. (Gon)

Keep the reason and the page-script caveat, and drop the restatement.

🤖

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 sentence says the strip covers only cookies the preview's server sends, which the loop cannot show and which the next sentence contrasts with cookies that page script sets.

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.

🤖


// CheckCookieConfig returns ErrHostPrefixCookieOff unless cfg gives the
// session cookie the __Host- prefix.
func CheckCookieConfig(cfg codersdk.HTTPCookieConfig) 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.

Nit [CRF-58] CheckCookieConfig returns ErrHostPrefixCookieOff exactly when EnableHostPrefix is false, but its name and both call sites read as a general cookie validation. (Gon)

Name it for the one condition it checks, for example RequireHostPrefixCookie.

🤖

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 doc comment states the one condition and the returned error names --host-prefix-cookie, so callers see the rule at both call sites, and the name says which config previews check, which stays true if that rule grows.

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.

The panel checked e919721. The fixes for the ServerOptions.Previews doc, the TestHandleSubdomainAppNamedPreview host prefix, the isFromOtherPreview doc and the previewsUnavailable description hold; the test fix was confirmed by mutation. 12 of the 13 contested findings are closed by the reviewers that raised them. One is re-raised in its thread, narrowed to the text of ErrHostPrefixCookieOff. One new Nit. Nothing at P3 or above is open.

CI: the jobs marked failed on this head (changes, lint, gen, check-build and those that depend on them) were cancelled, not failed.

Notes:

  • proxyWorkspaceApp calls s.Previews.ApplyPolicy for every preview token, so a preview token reaching a server whose Previews is nil would panic. No server reaches it today, because checks in db.go, proxy.go, coderd.go and wsproxy.go agree, but no type enforces the rule.

🤖 This review was automatically generated with Coder Agents.

// isFromOtherPreview reports whether a page on a preview host other than host
// sent r. The browser sets Origin, so a preview page cannot forge it, and it
// adds the user's cookies for the target, so the request would act as the user.
// The preview CSP already blocks such requests; refusing them here also blocks

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-61] The rewritten isFromOtherPreview doc says the check "also blocks those whose Origin names another preview host", which repeats the doc's first sentence, and "it" in "where a browser does not enforce it" can mean the CSP, the Origin or the block. (Gon)

For example: // Where a browser does not enforce the preview CSP, this still refuses requests whose Origin is another preview host of s.

🤖

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 doc already says what the function refuses and why the server check backs up the CSP, and "it" reads as the preview CSP, so we are leaving the wording as it is.

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: a misread costs one look at a five-line function whose code shows what it refuses.

🤖

@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 PR's commit is unchanged since the last review (git range-diff shows e919721399 = 6747c02d09); the head moved because the base PR changed a test. The last two contested findings, the ErrHostPrefixCookieOff text and the isFromOtherPreview doc wording, are closed by the reviewers that raised them, and the panel found nothing new. No finding is open. The workspace proxy preview test is tracked in #32522.

CI: the jobs marked failed on this head are cancelled jobs (for example check-build and sqlc-vet), not test failures, so the PR still needs a completed CI run.

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

  • codersdk/deployment.go:3701: the --host-prefix-cookie description says "Recommended to be enabled" but not that over plain HTTP (other than localhost) browsers reject the non-Secure __Host-coder_session_token, so turning it on signs every user out. Previews now point admins at this flag.

Notes:

  • Still a human decision for the security review (coder/security-assessments#437): preview page script can set Domain= cookies on the app wildcard, which the ApplyPolicy comment records as accepted.

🤖 This review was automatically generated with Coder Agents.

@DanielleMaywood

Copy link
Copy Markdown
Collaborator Author

CRF-60 (review body note: preview scripts can set cookies on other apps' domains): Confirmed for the experimental release (operator decision, no ticket). This matches ordinary workspace apps on the same wildcard, preview hosts strip Domain cookies their servers set, and the docs page lists it under what previews do not protect.

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

No code change since the last review (head 6747c02). The author's PR comment records an operator decision accepting, for the experimental release, that preview page script can set Domain= cookies on the app wildcard; that closes the last item that needed a human decision. The panel found nothing new. No finding is open; the workspace proxy preview test is tracked in #32522.

CI on this head: the Storybook job failed in the Pixel visual-diff step ("pixel: build finished with status failed", with no per-story diff in the log), and this PR's only site/ change is the generated typesGenerated.ts, so the cause is unverified. The prepare-linkspector-browser failure is a runner that lost contact with the server, and the other failed checks are cancelled duplicates of jobs that passed in run 45805005859.

Notes:

  • The Domain= cookie acceptance covers the experiment only. Taking previews out of the experiment needs a new decision, and no ticket records that condition.
  • The round 1 "changes requested" review is still active because this account cannot dismiss it; a maintainer needs to dismiss it.

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

No change to this PR's commit since the last review: git range-diff shows 6747c02d09 = 4cae110787, and the head moved because base PR #32438 added a test. The panel re-ran the preview tests at this head and found nothing new. No finding is open; the workspace proxy preview test is tracked in #32522.

CI on this head: the failed checks are cancelled zero-duration runs. In the second run, fmt, gen, lint, check-build, test-js and the docs jobs have passed, and the test-go-* jobs, Storybook, test-e2e and Flake Check were still running when this review was written.

Notes:

  • The round 1 "changes requested" review is still active because this account cannot dismiss it; a maintainer needs to dismiss it.

🤖 This review was automatically generated with Coder Agents.

Adds the hidden open-preview experiment and serves file and port
previews on preview hosts under the wildcard app hostname, with the
hosting mode chosen by the new previewhost package. Every preview
response carries a sandboxing CSP, cross-preview origins and top-level
opens are refused, and token issuance requires the experiment, a
subdomain request and workspace ownership.

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.

No change to this PR's commit since the last review: git range-diff shows 4cae110787 = 327e5edcc3, and the head moved because base PR #32438 edited a test comment. The panel re-ran the preview tests at this head and found nothing new. No finding is open; the workspace proxy preview test is tracked in #32522.

CI on this head: the failed checks are the first run's cancelled zero-duration jobs and its required aggregate. In the second run, required and every test, lint, gen and build job have passed; Storybook was still running when this review was written.

Notes:

  • The round 1 "changes requested" review is still active because this account cannot dismiss it; a maintainer needs to dismiss it.

🤖 This review was automatically generated with Coder Agents.

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