Skip to content

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

Open
DanielleMaywood wants to merge 10 commits into
open-preview/agentfrom
open-preview/routing
Open

DanielleMaywood wants to merge 10 commits into
open-preview/agentfrom
open-preview/routing

Conversation

@DanielleMaywood

@DanielleMaywood DanielleMaywood commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Agent-written pages are untrusted, because a prompt-injected agent can write any HTML. The security review (coder/security-assessments#437) showed that serving them like ordinary apps lets them reach the user's apps in every workspace. Previews therefore get their own strict host mode instead of the app path: a sandboxing CSP, framing only by the dashboard, no shared app cookie, and no top-level loads.

Preview hosts sit under the existing wildcard app hostname, so operators need no new DNS or certificates. The experiment stays out of the safe experiments, so --experiments='*' does not enable it, until we have more experience running previews. That is a rollout choice, not a known safety problem.

Implementation details

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/x/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

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.

🤖

Comment thread coderd/x/previewhost/previewhost.go Outdated

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

🤖

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Was this P2 considered?

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.

Yes. It's accepted for the experiment: with allow-same-origin, page script can set Domain= cookies, and no header filter can stop that while previews share a site with apps. Two things limit it. --host-prefix-cookie is required (coderd refuses preview tickets without it), so a preview can't replace the Coder session cookie. And the ApplyPolicy comment and the docs state that a preview can still overwrite cookies of the user's other apps.

🤖 This reply was drafted by an AI agent (Claude Code) and posted with my approval.

Comment thread coderd/workspaceapps/preview.go Outdated
// 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.

🤖

Comment thread coderd/x/previewhost/previewhost.go Outdated
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

@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 <noreply@anthropic.com>
@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.

@DanielleMaywood DanielleMaywood removed the experimental Changes that might not necessarily be merged, until its approved to proceed with. label Nov 26, 2026
@DanielleMaywood
DanielleMaywood marked this pull request as ready for review November 26, 2026 22:04
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T22:10:14.296682Z 327e5ed Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 327e5edcc3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codersdk/deployment.go
var cookiesToPrefix = map[string]struct{}{
SessionTokenCookie: {},
SessionTokenCookie: {},
PreviewSessionTokenCookie: {},

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve preview authentication on HTTP localhost

When previews run on the explicitly supported plain-HTTP localhost setup, adding this cookie to cookiesToPrefix makes authentication impossible: previews require EnableHostPrefix, so Apply emits a __Host-coder_preview_session_token, but a __Host- cookie requires Secure and cannot normally be used over HTTP; meanwhile the middleware deletes the only usable plain-name cookie before ResolveRequest can read it. Consequently localhost previews remain on the 401 sign-in page. The preview cookie needs scheme-aware naming/normalization rather than unconditional host-prefix handling.

Useful? React with 👍 / 👎.

@mafredri
mafredri self-requested a review December 1, 2026 09:54

@mafredri mafredri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Feels like this change enables a lot of behavior irrespective of the experiment being enabled or not?

)

// PreviewSlugPrefix starts the app slug of every preview.
const PreviewSlugPrefix = "preview--"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Considering apps use -- as a separator for other things where we have [foo]--[bar]--[qux]. Isn't this adding one more dimension between foo and bar: [foo](--[thing])--[bar]--[qux]. This adds a new gotcha into the parsing, where we can't trust the positional arguments unless we always check "is this a preview".

Just a thought, but is there an alternative character we could use, that is otherwise illegal as a positional argument? Like preview+thing--[bar]--?

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.

I don't believe you can have + in a domain. https://www.rfc-editor.org/info/rfc1035/#section-2.3

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, I figured + wasn't allowed, it was a lazy example. But indeed, it looks like there aren't any options outside of --.

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.

We could possibly do --preview at the very end? That might resolve your worry about positional arguments.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would that not possibly match a user named preview?

Comment thread coderd/workspaceapps/db.go Outdated

// The owner sharing level still lets site owners and users the
// workspace is shared with connect, but a preview runs agent-written
// code as whoever opens it, so only the workspace owner may.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Perhaps ASD-STE100 would be helpful here. I get that "may" refers to "opens it", but this doesn't read well.

@@ -0,0 +1,214 @@
// Package previewhost decides how a Coder server hosts agent-authored

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this be under /x/?

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.

Makes sense, moved it under that

Comment thread coderd/x/previewhost/previewhost.go Outdated
return &responseWriter{ResponseWriter: rw, hosting: h}
}

type responseWriter struct {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the bots are kind of right about this name (CRF-34). It has a more important role than just being a responseWriter. And it sounds weird if it's being described in other packages..

Comment thread coderd/workspaceapps/proxy.go Outdated
// Previews decides which hosts serve agent-authored previews and the
// policy their responses carry. It is nil when the server serves no
// previews: without Hostname, or on coderd without --host-prefix-cookie.
Previews *previewhost.Hosting

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This naming feels a bit confusing. previewhost.Hosting, called as Previews. Especially the Hosting doesn't tell me much about the type behind it.

Comment thread coderd/workspaceapps/preview.go Outdated
// writes goes through the preview policy writer, and proxyWorkspaceApp
// applies the same policy to proxied responses, WebSocket upgrades included.
func (s *Server) servePreview(rw http.ResponseWriter, r *http.Request, host string, middlewares []func(http.Handler) http.Handler) {
rw = s.Previews.Wrap(rw)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder if workspaceapps.Server is being granted too much knowledge of preview internals here? Would s.Previews.Serve(…) be potentially better? The token issuing should probably stay here, and that could be solved by either passing the token issuing as an inline func or making rw, …, ok = s.Previews.Prepare(…) do more.

Further if we move to /x/ then it'd be more clear that even this validation is part of the experimental code that should be vetted before promotion.

Comment thread coderd/workspaceapps/proxy.go Outdated
proxy.ModifyResponse = func(r *http.Response) error {
// ReverseProxy writes a WebSocket upgrade response to the hijacked
// connection, so the preview policy writer never sees it.
if isPreview {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure if this would be a better design, but before serving the proxy we could do something like this:

if isPreview {
    proxy = s.Previews.WrapProxy(proxy)
}

It'd contain the experimental code, and allow the previewhost package to ensure the proxy is invoked correctly.

Comment thread coderd/workspaceapps/proxy.go Outdated
site.RenderStaticErrorPage(rw, r, site.ErrorPageData{
Status: http.StatusNotFound,
Title: "Application Not Found",
Description: "This server does not serve previews.",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this exposing the experiment in normal requests?

Comment thread coderd/workspaceapps/proxy.go Outdated
}

// This runs before the app's CORS setting, so it also refuses
// requests that a passthru template would let through.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Saying "passthru tempalte" is wrong here, no such template exists.

Comment thread coderd/workspaceapps/proxy.go Outdated

// This runs before the app's CORS setting, so it also refuses
// requests that a passthru template would let through.
if s.isFromOtherPreview(r, host) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think "other preview" is confusing terminology here.

@DanielleMaywood
DanielleMaywood force-pushed the open-preview/routing branch 2 times, most recently from 6f16128 to ab51e38 Compare December 2, 2026 12:21
DanielleMaywood and others added 2 commits December 2, 2026 12:25
Previews are experimental, so the package that decides how they are
hosted lives with the other experimental code under coderd/x. Only the
package path and its imports change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Without the experiment, coderd builds no preview hosting, so a
preview-shaped host gets the same "Invalid Application URL" response as
main instead of the preview path. A server without preview hosting no
longer mentions previews in that response.

The cross-preview Origin refusal stays on: a preview page already open
in a browser keeps running after the experiment is switched off.
Workspace proxies are not gated, because they do not learn coderd's
experiments; coderd's ticket check still refuses every preview there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DanielleMaywood and others added 7 commits December 2, 2026 13:38
Brings in the agent review changes (#32438) without rewriting the commits
already under review here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The checks that only preview hosts need now live in the experimental
previewhost package, so the code to vet before previews leave the
experiment is in one place. Hosting.Prepare wraps the writer and
decides whether to refuse service workers, requests from other previews
and top-level loads, and returns the app the host names. It returns a
Refusal rather than writing the page, so previewhost does not import
the site package. Hosting.WrapProxy applies the policy to proxied
responses before the proxy's own ModifyResponse, which replaces the
isPreview branch inside it.

workspaceapps keeps what needs its own state: error pages, the smuggled
API key refusal, the ticket, and the proxy. The cross-preview Origin
check stays a package function, because ordinary app requests run it
even when the server has no preview hosting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comments elsewhere already call it the preview policy writer, and the
name now says what it does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The type is the set of preview hostnames under one wildcard and the
policy their responses carry, so call sites now read as
s.PreviewHosts.Covers(host) and hosts.URL(app, path). The workspaceapps
field Previews becomes PreviewHosts, and coderd's previewHosting
becomes previewHosts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in main through the agent branch, so this PR no longer conflicts
with its base, without rewriting the commits already under review here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- db.go: state the owner-only rule in short sentences.
- proxy.go: name the template setting, cors_behavior set to passthru.
- previewhost.FromOtherPreview: say exactly what it checks.

Comments only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in the junction test fix from #32438.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants