Skip to content

feat: route preview app hostnames to agent previews - #31283

Draft
DanielleMaywood wants to merge 2 commits into
feat/agents-open-preview-agentfrom
feat/agents-open-preview-routing
Draft

DanielleMaywood wants to merge 2 commits into
feat/agents-open-preview-agentfrom
feat/agents-open-preview-routing

Conversation

@DanielleMaywood

@DanielleMaywood DanielleMaywood commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

Subdomain app hostnames shaped preview--<id>--<agent>--<workspace>--<owner> now proxy to http://127.0.0.1:4/api/v0/previews/<id> on the agent, and preview--<port>--… proxy to that port. Previews are subdomain-only, use the owner sharing level (application_connect on the workspace) and ignore port shares. Only file previews may reach a reserved port, and only the agent API. Because preview pages are agent-authored:

  • Every proxied preview response gets Content-Security-Policy: sandbox allow-scripts allow-same-origin allow-forms allow-modals allow-downloads; default-src 'self' 'unsafe-inline' 'unsafe-eval' data: blob:; frame-src 'self'; object-src 'none'; form-action 'self'. The page can't navigate the top-level page, open popups, or load or send anything (scripts, images, frames, fetch, WebSocket, forms) from or to another host.
  • Preview responses drop Clear-Site-Data and any Set-Cookie with a Domain attribute (matched on the raw header, case-insensitively and with spaces around the name), so a preview server can't log the user out of the registrable domain or set cookies on the owner's other apps.
  • A redirect that would make the browser resend a POST, PUT or similar request to another host is replaced with 403.
  • A preview request with the coder_preview_sign_in query parameter gets an empty 200 from coderd once the browser is signed in, and never reaches the preview. The dashboard loads it in a hidden frame so the sign-in redirects, which the wrapper's frame-src blocks, finish before the preview is shown, without the preview's server answering that frame.
  • A CSP can't stop a page from navigating itself to another host. That is left to whatever embeds the preview: the dashboard (feat(site): add a Preview tab for open_preview #31286) uses a wrapper frame with frame-src <preview origin>. A preview opened directly by its URL can navigate to the owner's other apps.
Decision log
  • Double-hyphen marker. coder_app slugs cannot contain --, so the five-part preview hostname cannot collide with any existing app or port URL. A single-hyphen preview-<id> slug would have shadowed (and broken) a coder_app with that slug. The preview pattern is matched first and requires the agent name; every hostname that parsed before parses the same way.
  • Separate preview--<port> host. Previews are always owner sharing level, even if a port share exists for the agent API port or for the previewed port. Port previews get their own hostname rather than reusing the port-forward hostname, so the preview CSP applies to them. Preview ports start at appurl.PreviewMinimumPort (1000) and have no leading zeros, so preview--0005 cannot name a reserved port.
  • Chat headers dropped on file previews. The agent API saves and replays a response for an hour per Coder-Chat-Id and Coder-Tool-Call-Id, so the proxy drops those headers (and Coder-Ancestor-Chat-Ids) on file-preview requests. Otherwise a preview page could fill that store or answer in place of a real tool call.
  • default-src 'self'. Without it, <img> and <script> GETs reach other apps with the user's app cookie (confirmed in Chromium, Firefox and WebKit). Cost: previews can't load assets from a CDN or call external APIs from the browser.
  • Redirect check. A preview could send a credentialed POST to another app through a redirect: the browser repeats it with the app cookie. form-action 'self' blocks it in Chromium, but Firefox applies form-action only to a form's first URL, so the proxy refuses those redirects itself.
  • Self-navigation. Rejected alternatives: an opaque-origin sandbox (WebKit still sends cookies) and credentialless or fenced frames (Chromium only). Serving previews from a separate registrable domain is the stronger follow-up.
  • application_connect, not literal owner. Users the workspace is shared with, and site owners unless --disable-owner-workspace-access is set, can view previews, the same as other owner-level apps.
  • Known limitations:
    • Workspace proxies on an older version will not route previews.
    • Connection logs record preview traffic as port forwarding.
    • Scripts can still set parent-domain cookies through document.cookie, which is why the docs recommend --host-prefix-cookie.
    • The whole app subdomain is one DNS label (max 63 characters). File previews use 23 characters (preview--, an 8-character ID and the separators) before names, so long agent, workspace and owner names can exceed it, as they already can for coder_app slugs.

Stack (proof of concept for the embedded previews RFC, review bottom-up):

  1. feat: serve published file previews from the workspace agent over tailnet #31282 Agent file previews over tailnet
  2. feat: route preview app hostnames to agent previews #31283 Preview app hostname routing ← this PR
  3. feat(coderd): add open_preview chat tool #31284 open_preview chat tool
  4. feat: add chat previews endpoint #31285 Chat previews endpoint
  5. feat(site): add a Preview tab for open_preview #31286 Preview tab UI
  6. docs(docs/coder-agents): document embedded previews #31287 Docs
  7. feat: open coder_app tabs from open_preview #31484 Open coder_app tabs
  8. feat: gate open_preview behind an experiment #32259 open-preview experiment

🤖 This PR was written by Coder Agents on behalf of @DanielleMaywood.

@ibetitsmike ibetitsmike left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Adversarial security review — #31283 (preview hostname routing / CORS)

Part of the stack review; the stack-level roll-up (findings S1/S2, method, verified negatives) is on #31282. Line numbers at stack head 678b80103.

Contributes to S1 (P1, contested; validated) — the CORS mitigation is keyed on hostname shape, only withholds response headers, and is skipped for passthru

  1. Keyed on preview-- slug, not on content provenance. coderd/httpmw/cors.go:126 denies only origins whose slug parses as a preview ID. open_preview(port) (#31284) lands the same LLM-authored content on <port>--agent--ws--user, which this function still allows with AllowCredentials: true (cors.go:140) for every app of the same username — including other workspaces. Validated end-to-end through the real proxy: ACAO: <port origin> + ACAC: true against victim--agent--w2--testuser.
  2. CORS does not block the request. go-chi/cors always calls next for non-preflight requests; it only withholds Access-Control-Allow-*. Validated: a form POST with only the ambient coder_subdomain_app_session_token_<hash> cookie (Domain=.<wildcard> — proxy.go:277; SameSite=Lax, strict not selectable — codersdk/deployment.go:3665) and Origin: https://preview--0123456789abcdef--agent--ws--owner.<wildcard> was token-issued by ResolveRequest and delivered to the sibling upstream with its body. There is no Origin/Sec-Fetch-*/Referer gating anywhere in coderd/workspaceapps/*.go. The PR body ("agent-authored pages cannot make credentialed requests to the owner's other apps") and the comment at cors.go:124-125 describe a property the code does not have — please reword to "cannot read responses".
  3. cors_behavior=passthru bypasses the check entirely. proxy.go:406 case codersdk.CORSBehaviorPassthru: next.ServeHTTP(...); ModifyResponse leaves upstream headers intact. Validated: with the template set to passthru and a reflecting upstream, ACAO: http://preview--… + ACAC: true reached the client unchanged; switching back to simple stripped them. (Voted P3 on its own; it matters because dev servers that reflect Origin are exactly the ones where reads become possible.)
  4. "Previews are always owner-only. Port shares do not apply" (request.go:327-330) is true only for path mode; port-mode previews take the port branch (request.go:357-400) and a public share serves the LLM-authored page unauthenticated (validated 303 → 200).

Suggested fix: move the preview-origin rule out of WorkspaceAppCors into an unconditional step in determineCORSBehavior (also strip ACAO/ACAC from passthru responses when Origin is a preview host), and consider a hard 403 in HandleSubdomain when Origin parses as a preview host that is not the request host (closes the CSRF vector for everything that sends Origin, i.e. all cross-origin POST/PUT/PATCH/DELETE and no-cors fetches). Coordinate with #31284 so port-mode previews also get a preview---class slug (e.g. preview--p<port>--…), otherwise the origin check cannot distinguish them.

Contributes to S2 (P2; validated) — "owner-only" means application_connect

appSharingLevel = Owner (request.go:330) resolves to Authorize(ActionApplicationConnect, workspace) at db.go:370. Validated principals that pass for another user's workspace: site owner role (unless --disable-owner-workspace-access), workspace-ACL use/admin, and premium custom org roles granting workspace.application_connect (which can be granted without ssh). Org admins and same-org members are correctly denied. Nothing new is exposed to SSH-capable principals, but the wording in the PR body and request.go:327 is inaccurate. If literal owner-only is intended, add dbReq.Workspace.OwnerID.String() != roles.ID → deny for isPreview in authorizeRequest, analogous to the path-app owner check at db.go:328-339.

Unverified (single reviewer) — P3 / nit

  • nit Path-based /@owner/<ws>.<agent>/apps/preview--<id>/ returns 500 after the workspace lookup but before authz (existence/state oracle for any authenticated user). Same pre-existing pattern as port slugs (request.go:337-340 TODO); cheap to fix by checking AccessMethod before the DB lookups.
  • nit Preview accesses are connection-logged as port_forwarding with slug_or_port = preview--<id> (db.go:478-486); acknowledged in the PR body, but auditors filtering on port forwarding will see preview traffic mixed in.

Verified negatives (no action)

  • Hostname parsing regression: a 104,868-hostname corpus (2–6 segments over {preview, <16hex>, PREVIEW, 8080, 8080s, 0005, 00005, …} with/without p--- prefix) parsed with the pre-PR and new parsers → zero meaning changes; only 5-segment preview--<16hex>--agent--ws--user shapes newly parse. preview--<16hex>--ws--user keeps its old meaning. Mixed-case → 400. X-Forwarded-Host honoured only from trusted origins.
  • coder_app slugs can never contain -- (provisioner.AppSlugRegex, enforced on every insert path), so isPreview is never true for a DB app; reserved-port exception is sound (isPreview from hostname, AppURL only http://127.0.0.1:5/<id> for preview slugs, MatchesRequest binds slug/agent/prefix, signed-token cookie is host-only, terminal/path access can't reach proxyWorkspaceApp with a preview).
  • Leading-zero ports 0005/00005/0005s/0004 pass PortRegex and get a token (even anonymously with a DB-injected public share) but still hit 400 Coder reserves ports… — pre-existing, unchanged.
  • Traversal to the agent (/../x, /%2e%2e/x, //x, /\x, /;x, ?coder_signed_app_token=) all end at the agent's 404; Coder cookies stripped before proxying; smuggling redirect is same-origin.

@DanielleMaywood
DanielleMaywood force-pushed the feat/agents-open-preview-routing branch 2 times, most recently from 0528b71 to b4c1433 Compare October 28, 2026 12:00
@DanielleMaywood
DanielleMaywood force-pushed the feat/agents-open-preview-routing branch from b4c1433 to b2de574 Compare October 28, 2026 13:06
@DanielleMaywood
DanielleMaywood force-pushed the feat/agents-open-preview-routing branch from b2de574 to b78fe61 Compare October 28, 2026 13:20

@DanielleMaywood DanielleMaywood left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This review was performed by ai-review, an automated review bot.

1 inline finding.

Coverage
Coverage: 6 of 6 files reviewed; 22 rules.
Candidates: 136 found, 121 outside changed lines, 0 already discussed, 15 evaluated.
Findings: 1 (2 sites, 0 pre-existing sites), 0 over budget, 0 failed.
Model: deepseek/deepseek-v4.1-flash; 15 questions, 15 answered, 0 abstained, 0 cached; 0 uncalibrated findings held back; 15881 input and 4725 output tokens.

Comment thread coderd/workspaceapps/appurl/appurl.go Resolved
@DanielleMaywood
DanielleMaywood force-pushed the feat/agents-open-preview-routing branch from b78fe61 to ae91195 Compare October 28, 2026 16:42
@DanielleMaywood
DanielleMaywood force-pushed the feat/agents-open-preview-routing branch from ae91195 to bd769f9 Compare October 28, 2026 16:43
@DanielleMaywood
DanielleMaywood force-pushed the feat/agents-open-preview-routing branch from bd769f9 to 00465e4 Compare October 29, 2026 09:57

@ibetitsmike ibetitsmike left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Follow-up (re-checked at 2c52e96): the new isFromOtherPreview gate has three bypasses — P2, validated

First: the rebase addressed the substance of my earlier S1 — preview--<port> slugs, hard 403 on preview Origin, CSP sandbox, Origin check ahead of cors_behavior. Thanks. Re-testing the new gate end-to-end (real coderd + agent + Postgres, upstream records every delivered request) shows it is still bypassable in three ways. (a) and (b) were also flagged by a second, independent review of the rebased stack; (c) surfaced while comparing the two.

case request proxy upstream
(c) path app POST /@owner/ws.agent/apps/pathapp/do, Origin: http://preview--0123…--agent--ws--owner.<wildcard>, only coder_session_token 200 POST /do body="a=1"
control same POST to <port>--agent--ws--owner.<wildcard>/do with the subdomain cookie 403 "Preview pages cannot send requests to other apps." none
(a) no Origin subdomain POST /do / GET /img.png, no Origin header 200 delivered
(b) Origin: null subdomain POST /do, Origin: null 200 POST /do Origin="null" body="a=1"
control Origin: …preview--0123456789abcdef… and …preview--8080… 403 none

Why:

  • isFromOtherPreview (coderd/workspaceapps/proxy.go:545-547) returns false (= allow) when origin.Host == "". A missing header and the literal null both parse to an empty host (url.Parse("null") → Host="", Path="null"). Browsers omit Origin on no-cors GETs (<img>, <script>, <iframe>, <link>), and emit Origin: null from a nested <iframe sandbox> without allow-same-origin — which the preview page can create itself — or after a no-referrer policy on a form POST. So an agent-authored page can still make the browser deliver authenticated GETs and null-origin POSTs to every app the viewer can reach, with the ambient Domain=<wildcard> cookie. Responses stay opaque (no-cors), so this is blind CSRF/resource loading, not a read primitive.
  • The check is only called from HandleSubdomain (proxy.go:494). workspaceAppsProxyPath (proxy.go:317) never looks at Origin; path apps authenticate via coder_path_app_session_token falling back to the full coder_session_token (cookies.go:84-93); and the CSRF middleware exempts everything outside /api and /oauth2/authorize (httpmw/csrf.go:71-73). The preview origin is same-site with the dashboard in a typical deployment, so SameSite=Lax does not withhold that cookie on a form POST. A well-formed preview Origin is forwarded verbatim and the request is served. Path apps are enabled by default. This is pre-existing for any same-site page, but the docs now say "Coder rejects cross-origin requests from a preview page to other workspace apps, such as form posts and fetch calls" (#31287), which this falsifies.

Suggested fixes:

  1. Apply the same gate in workspaceAppsProxyPath (and the terminal path if applicable).
  2. For subdomain and path apps, fail closed on unsafe methods when Origin is absent or null: Sec-Fetch-Site/Sec-Fetch-Mode/Sec-Fetch-Dest are sent by all evergreen browsers and let you reject same-site + navigate|no-cors initiations from a preview without breaking first-party navigations (Sec-Fetch-Site: none). Note Sec-Fetch-* cannot name the initiating host, so this is defence in depth.
  3. The structural fix is still credential scoping: previews on a separate site, or a preview-specific host-only cookie, so the wildcard app cookie is never ambient on a preview page. With the current design the Origin/Fetch-Metadata gate can only ever be best-effort.
  4. Reword the docs/PR claim to what is enforced (see #31287).

Service worker on the stable preview origin can observe the app-auth handoff — P2, mechanism verified, browser-unverified (credit: second independent review)

  • Preview responses get only Content-Security-Policy: sandbox allow-scripts allow-same-origin … (proxy.go:724); the sandbox directive does not restrict workers and there is no worker-src/default-src, and the agent serves .js from the published tree with the correct type. A prompt-injected page can therefore register a service worker scoped to its origin, which is stable (preview--<sha256(path)[:8]>… and preview--<port>…).
  • On a later cookie-less visit (expiry, new browser profile, --disable-… rotation) the proxy redirects through /api/v2/applications/auth-redirect and lands back on the preview host with ?coder_application_connect_api_key_35e783=<JWE> (proxy.go:43,209). A controlling worker sees that navigation URL before handleAPIKeySmuggling strips it (proxy.go:308). The JWE has a 1-minute expiry (token.go:61) but no one-time-use and no binding to the target host (audience is the generic wsproxy, token.go:60,71), so it is replayable from another browser within the window to mint the viewer's application_connect cookie. Workers also persist across the daemon restart that invalidates the publication.
  • Fixes: add worker-src 'none' (a separate CSP header; the sandbox directive won't do it) and consider Clear-Site-Data: "storage" on preview 404s; make the smuggled payload single-use and bound to the exact redirect host; salt the preview ID per agent process (#31282) so the origin is not stable across restarts.

I can share the validation test source if useful.

@DanielleMaywood

Copy link
Copy Markdown
Collaborator Author

@codex review

🤖 Posted by Coder Agents on behalf of @DanielleMaywood.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T14:29:46.823427Z f62bbde Manual request
ℹ️ 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: 3b09300be0

ℹ️ 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 coderd/workspaceapps/proxy.go Resolved
@DanielleMaywood
DanielleMaywood force-pushed the feat/agents-open-preview-routing branch from 3037b2b to 331f425 Compare November 3, 2026 12:21

@DanielleMaywood DanielleMaywood left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This review was performed by ai-review, an automated review bot.

1 inline finding.

Coverage
Coverage: 6 of 6 files reviewed; 53 rules.
Candidates: 323 found, 265 outside changed lines, 6 already discussed, 52 evaluated.
Findings: 2 (2 sites, 0 pre-existing sites), 0 over budget, 0 failed.
Model: deepseek/deepseek-v4.1-flash; 52 questions, 48 answered, 4 abstained (unsure 1, truncated 3), 18 cached; 0 uncalibrated findings held back; 46763 input and 78442 output tokens.

Comment thread coderd/workspaceapps/proxy_test.go Resolved
@DanielleMaywood
DanielleMaywood force-pushed the feat/agents-open-preview-routing branch from 331f425 to 9e79cb8 Compare November 3, 2026 14:07
@DanielleMaywood
DanielleMaywood force-pushed the feat/agents-open-preview-routing branch from 9e79cb8 to 1923f51 Compare November 3, 2026 15:22
@DanielleMaywood
DanielleMaywood force-pushed the feat/agents-open-preview-routing branch from dfb4b45 to 0380d38 Compare November 4, 2026 10:11
@DanielleMaywood
DanielleMaywood force-pushed the feat/agents-open-preview-routing branch from 0380d38 to f5aa92e Compare November 4, 2026 10:25
@DanielleMaywood
DanielleMaywood force-pushed the feat/agents-open-preview-routing branch from f5aa92e to 2ff8731 Compare November 4, 2026 10:55
Comment thread coderd/workspaceapps/proxy.go Resolved
@DanielleMaywood

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review

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

Copy link
Copy Markdown
Contributor

Chat: Review posted | View chat
Requested: 2026-11-06 09:38 UTC by @DanielleMaywood
Spend: $63.63 / $100.00

Review history
  • R1 (2026-11-04): 13 reviewers, 3 Nit, 1 P1, 2 P2, 9 P3, 9 P4, REQUEST_CHANGES. Review
  • R2 (2026-11-05): 14 reviewers, 3 Nit, 1 P1, 3 P2, 14 P3, 10 P4, COMMENT. Review
  • R3 (2026-11-05): 12 reviewers, 4 Nit, 1 P1, 3 P2, 14 P3, 12 P4, COMMENT. Review
  • R4 (2026-11-06): 5 reviewers, 4 Nit, 1 P1, 3 P2, 14 P3, 12 P4, APPROVE. Review
  • R5 (2026-11-06): 4 reviewers, 4 Nit, 1 P1, 3 P2, 14 P3, 12 P4, APPROVE. Review

deep-review v0.13.0 | Round 5 | f85cc0d..caf373e

Last posted: Round 5, 34 findings (1 P1, 3 P2, 14 P3, 12 P4, 4 Nit), APPROVE. Review

Finding inventory

Findings

# Sev Status Location Summary Round Reviewer Posted
CRF-1 P3 Author contested; panel closed R2 (1/1 accept) appurl.go:195 IsPreviewHostname treats a suffixed four-part coder_app host as a preview R1 Netero Yes
CRF-2 P4 Author fixed (886faee) request.go:317 Path-based preview slug returns 500 instead of 4xx R1 Netero Yes
CRF-3 P4 Author fixed (886faee) proxy.go:786 No test covers dropping Coder-Ancestor-Chat-Ids R1 Netero Yes
CRF-4 Note Note (body) appurl.go:153 IsPreviewID exported with no caller outside appurl until #31285 R1 Netero No
CRF-5 OOS Out of scope (body) request.go:336 Path-based port slug returns 500 per existing TODO R1 Netero No
CRF-6 P1 Author fixed (886faee) proxy.go:66 Preview page escapes all preview restrictions by navigating itself to the port-forward or app host R1 Kurapika P1, Melody P1, Pariston P1, Hisoka P1, Luffy P2 Yes
CRF-7 P2 Author contested; panel closed R2 (1/1 accept) request.go:322 preview-- drops port shares and cross-origin calls for rules CRF-6 bypasses R1 Luffy Yes
CRF-8 P2 Author fixed (886faee) proxy.go:836 Port preview passes Clear-Site-Data through, clearing dashboard session cookies R1 Hisoka Yes
CRF-9 P3 Author fixed (886faee) appurl.go:190 IsPreviewHostname misses previews when the wildcard suffix contains --- R1 Kite Yes
CRF-10 P3 Author fixed (886faee) proxy.go:841 Blocked repost is reported as 502 Bad Gateway with Retry R1 Mafuuu P3, Leorio P3, Ryosuke P4, Zoro P4 Yes
CRF-11 P3 Author fixed (886faee); fix bypassable, see CRF-34 proxy.go:59 Preview can set parent-domain cookies and shadow the dashboard session R1 Mafuuu P3, Hisoka Note Yes
CRF-12 P3 Author fixed (886faee) proxy_test.go:439 No test covers CSP and repost check under passthru CORS R1 Bisky Yes
CRF-13 P4 Author contested; panel closed R2 (2/2 accept) db_test.go:780 PreviewSubdomain adds public port shares to the shared test workspace R1 Bisky P4, Hisoka P4 Yes
CRF-14 P4 Author fixed (886faee) proxy.go:741 Preview rules derive from hostname app, not the authorizing token R1 Ryosuke Yes
CRF-15 P3 Author fixed (886faee) proxy.go:62 previewPolicy comment claims it blocks requests to any other host R1 Leorio Yes
CRF-16 P3 Author fixed (886faee) proxy.go:779 Chat-header comment names a vague harm instead of the response store R1 Gon P3, Leorio P4 Yes
CRF-17 P3 Author fixed (886faee) proxy.go:756 isPreviewPort is true only for file previews R1 Gon Yes
CRF-18 P3 Author fixed (886faee) appurl.go:179 Preview port lower bound 1000 is unnamed and undocumented R1 Gon P3, Leorio P4 Yes
CRF-19 P4 Author fixed (886faee) appurl.go:30 Preview ID width duplicated with agent format string R1 Gon Yes
CRF-20 P4 Author fixed (886faee) proxy.go:58 Comment cites a dashboard iframe that does not exist at this head R1 Gon P2, Leorio Note, Zoro Note Yes
CRF-21 P4 Author contested; panel closed R3 (1/1 accept) proxy.go:632 Untrusted-agent and Origin-null rationale repeated across five comments R1 Gon P2 Yes
CRF-22 Nit Author fixed (96a0777) appurl.go:151 IsPreviewID doc says static preview, rest of PR says file preview R1 Gon Yes
CRF-23 Nit Author fixed (886faee) proxy.go:581 isRepostToOtherHost names *http.Response r R1 Gon Yes
CRF-24 Nit Author fixed (886faee) proxy.go:741 ParsePreviewSlug call sits under the port-check comment R1 Gon Yes
CRF-25 P4 Author fixed (886faee) request.go:320 Commit body says owner-only and no credentialed requests R1 Leorio Yes
CRF-26 P4 Author contested; panel closed R2 (1/1 accept) proxy.go:526 Known limitations omit that older proxies skip the Origin check R1 Kite Yes
CRF-27 OOS Out of scope (body) proxy.go:291 Subdomain app cookie is scoped to the whole app wildcard R1 Kurapika, Luffy, Pariston, Mafuuu No
CRF-28 OOS Out of scope (body) httpmw/apikey.go:1030 Session cookie lacks __Host- prefix; first cookie wins R1 Mafuuu No
CRF-29 OOS Out of scope (body) httpmw/cors.go:124 WorkspaceAppCors allows credentialed reads from any same-owner port origin R1 Melody No
CRF-30 OOS Out of scope (body) coderd/tailnet.go:227 ServerTailnet.ReverseProxy uses deprecated Director R1 Ging-Go No
CRF-31 OOS Out of scope (body) proxy.go:835 Non-preview apps pass Clear-Site-Data and parent-domain Set-Cookie R1 Hisoka No
CRF-32 P3 Author fixed (96a0777) agent/agentpreview/preview_internal_test.go:16 PR title scope coderd excludes the agent test file; title CI fails R2 Netero Yes
CRF-33 P4 Author fixed (96a0777) proxy.go:852 ModifyResponse comment still cites the dashboard iframe R2 Netero Yes
CRF-34 P2 Author fixed (96a0777) proxy.go:865 Set-Cookie filter trusts Go's parse and forwards raw lines; Domain = reaches browsers R2 Kurapika P2, Bisky P3, Hisoka P3, Mafuuu P3 Yes
CRF-35 P3 Author contested; panel closed R3 (2/2 accept) proxy.go:850 103 Early Hints bypass ModifyResponse preview header rules R2 Hisoka P3, Melody P4 Yes
CRF-36 P3 Author contested; panel closed R3 (1/1 accept) proxy.go:600 isRepostToOtherHost decides no request outcome after the wrapper frame R2 Pariston Yes
CRF-37 P3 Author contested; panel closed R4 (1/1 accept) appurl.go:164 PreviewMinimumPort doc claims port-forward range equivalence that is false R2 Leorio Yes
CRF-38 P3 Author contested; panel closed R3 (1/1 accept; docs ask moved to CRF-43) request.go:322 Port previews are HTTP only; HTTPS dev servers fail with no hint R2 Chopper Yes
CRF-39 Nit Dropped by orchestrator (no repo rule on comment width; no consequence) proxy.go:590 isRepostToOtherHost doc first line is 87 columns R2 Gon No
CRF-40 OOS Out of scope (body) coderd/tracing/status_writer.go:58 StatusWriter records the first 1xx status as the response status R2 Melody No
CRF-41 OOS Out of scope (body) coderd/x/chatd/chattool/openpreview.go open_preview tool description omits port-preview CSP limits (#31284) R2 Luffy No
CRF-42 P4 Author fixed (be60b96) proxy.go:584 Sign-in comment cites a dashboard hidden frame and wrapper policy absent at this head R3 Netero Yes
CRF-43 OOS Out of scope (body) #31287 docs, #31284 open_preview port description No user-facing text says port previews are HTTP only R3 Chopper No
CRF-44 P4 Author fixed (be60b96) proxy_test.go:459 No test line uses a lowercase domain attribute; case-insensitive match untested R3 Bisky Yes
CRF-45 Nit Author fixed (be60b96) proxy.go:667 hasDomainAttribute uses strings.Split only to loop; GO.md says SplitSeq R3 Ging-Go Yes

Contested and acknowledged

CRF-1 (P3, appurl.go:195) - IsPreviewHostname over-matches a suffixed four-part app host

  • Finding: Under a *--apps wildcard, a coder_app slug preview on an agent named like an 8-hex ID or a port has five -- parts, so its requests to the owner's other apps get 403. Proposed: match against the configured patterns or strip the suffix.
  • Author defense (R2): Won't fix. Needs slug preview, an 8-hex or port-shaped agent name, and a suffixed wildcard; the only effect is that this app's cross-origin requests to the owner's other apps get 403.
  • Panel closure (R2, 1/1): Netero, the agent that raised it (same agent, reused), accepted. Terraform resource names must start with a letter or underscore, so a port-shaped agent name cannot occur; only an 8-hex name like deadbeef triggers it. The check fails closed (403), so preview isolation is unaffected; the cost is one oddly named app losing cross-origin calls to sibling apps.

CRF-7 (P2, request.go:322) - Separate preview-- host

  • Finding: preview--<port> ignores port shares and its CSP blocks cross-origin calls, while its stated purpose (preview rules) is bypassed by self-navigation. Proposed: open the plain <port>--agent--ws--owner URL for port previews and keep preview--<id> for files.
  • Author defense (R2): Won't fix. The plain port host passes WorkspaceAppCors for same-owner origins, so serving port previews there would drop the Origin check and the preview CSP. The preview--<port> host keeps them apart. Containment against self-navigation moved to a frame-src wrapper in feat(site): add a Preview tab for open_preview #31286.
  • Panel closure (R2, 1/1): Luffy, the agent that raised it (reused), accepted. feat(site): add a Preview tab for open_preview #31286 PreviewFrame.tsx wraps the preview in a srcdoc frame with frame-src <exact preview origin>, so the dashboard frame cannot navigate to the plain port host; the preview rules are hostname-keyed, so the plain host would lose them. Remaining cost (CDN assets and other-port calls break in the Preview tab) is stated in the PR description and docs(docs/coder-agents): document embedded previews #31287.

CRF-13 (P4, db_test.go:780) - Port shares on the shared test workspace

  • Finding: PreviewSubdomain creates public port shares for ports 4 and 8080 on the workspace shared by all parallel Test_ResolveRequest subtests, so a future subtest on those ports becomes order-dependent. Proposed: own workspace or unique ports.
  • Author defense (R2): Won't fix. No sibling subtest resolves those ports, so the order dependency is hypothetical.
  • Panel closure (R2, 2/2): Bisky and Hisoka, the agents that raised it (both reused), accepted. Every Test_ResolveRequest subtest that resolves port 4 or 8080 by subdomain is PreviewSubdomain itself, and PortPathBlocked fails on access method before port-share lookup. No production behavior is affected.

CRF-22 (Nit, appurl.go:151) - IsPreviewID doc says "static preview"

  • Finding: The doc says "agent static preview ID"; the rest of the PR says "file preview".
  • Author defense (R2): "Already says 'a file preview ID' at 84a1927." Churn guard observed that head 886faee35f line 151 still reads "agent static preview".
  • Panel re-raise (R2): Gon, the agent that raised it (reused), re-raised. git cat-file -t 84a19279af and git fetch origin 84a19279af both fail; line 151 at 886faee35f still says "static".

CRF-26 (P4, proxy.go:526) - Known limitations omit older-proxy Origin check gap

  • Finding: Apps served by an older workspace proxy do not run the Origin check, so only the preview CSP blocks those requests; proposed adding this to the known limitations.
  • Author defense (R2): Won't fix. Mixed-version workspace proxies already can't route previews, and the preview CSP still blocks those requests in the browser.
  • Panel closure (R2, 1/1): Kite, the agent that raised it (reused), accepted. With default-src 'self' the CSP blocks fetch, WebSocket, subresources, frames and forms to other hosts; the remaining redirected reposts arrive with Origin: null, which the Origin check could not attribute on a new proxy either, and the repost check runs on the preview host's own proxy.

CRF-21 (P4, proxy.go:632) - Repeated untrusted-agent rationale; request.go:318 copy

  • Finding: The untrusted-agent rationale was repeated in five comments; R2 re-raise listed the remaining copies at proxy.go:54-55 and request.go:318.
  • Author defense (R3): Fixed the previewSandbox copy in 96a0777. Not changing request.go:318: that sentence is the only stated reason previews use the owner sharing level and ignore port shares, which is specific to that call site.
  • Panel closure (R3, 1/1): Gon, the agent that raised it (reused), accepted. request.go:318 is the only explanation of why that switch case uses the owner sharing level and ignores port shares; the remaining copies on isRepostToOtherHost and isFromOtherPreview each open the attack that function blocks.

CRF-35 (P3, proxy.go:850) - 103 Early Hints skip ModifyResponse

  • Finding: httputil.ReverseProxy forwards 1xx headers before ModifyResponse, so a 103 from a port preview server carries Link, Set-Cookie, Clear-Site-Data without previewPolicy. Proposed: drop 1xx (other than 101) for preview requests.
  • Author defense (R3): Browsers act on a 103 only for top-level navigations and only on its Link header (and the CSP for that hint); no evidence they apply Set-Cookie or Clear-Site-Data from a 103. A preload is a credentialed GET a top-level preview can already make by navigating itself, which is the self-navigation gap the human author accepted.
  • Panel closure (R3, 2/2): Hisoka and Melody, the agents that raised it (both reused), accepted. Early Hints preloads apply only to top-level navigations, which can already make the same credentialed GET by self-navigation (accepted gap); Chromium ignores them in subframes, so the wrapper is unaffected. Neither Chromium docs nor MDN describe applying Set-Cookie or Clear-Site-Data from a 103 (inferred from the Fetch spec; not run in a browser).

CRF-36 (P3, proxy.go:600) - isRepostToOtherHost decides no outcome

  • Finding: With the feat(site): add a Preview tab for open_preview #31286 wrapper and the documented self-navigation limit, the repost check blocks nothing the wrapper or a self-navigation would not; delete it or name the scenario where it is the only control.
  • Author defense (R3): The human author decided to keep it. Firefox applies form-action only to a form's first URL, so for a preview opened in its own tab in Firefox, this check is the only control that blocks a form repost redirected to another app. The hostname swap to the plain port host is a top-level self-navigation, the accepted gap.
  • Panel closure (R3, 1/1): Pariston, the agent that raised it (reused), accepted. The defense names the scenario the finding asked for (Firefox, preview in its own tab, form repost redirected to another app); the human author decided to keep the control, whose only cost is maintenance.

CRF-38 (P3, request.go:322) - Port previews HTTP only

  • Finding: Port previews proxy only over HTTP; HTTPS dev servers fail with a 502 or a passed-through 400 and no hint. Proposed: accept an s suffix, or state the HTTP-only limit in the open_preview tool description and docs.
  • Author defense (R3): HTTP only by design. ParsePreviewSlug accepts only a bare port, request.go:321 proxies to http://127.0.0.1:<port>, and the open_preview tool asks for the port of an existing HTTP server. An s variant would add a second hostname form across routing, the tool and the UI for a rare setup. (The reply does not address the documentation option.)
  • Panel closure (R3, 1/1): Chopper, the agent that raised it (reused), accepted HTTP-only as a design choice. The remaining ask (state HTTP-only in docs(docs/coder-agents): document embedded previews #31287 docs and the feat(coderd): add open_preview chat tool #31284 port description) changes files outside this PR, recorded as CRF-43 (out of scope).

CRF-37 (P3, appurl.go:164) - PreviewMinimumPort doc and the 1000 floor

  • Finding: R2: the doc claimed 1000 matched the port-forward range (false). R3 re-raise: the new doc restates the bound without a reason; reserved-port safety holds for any floor >= AgentMinimumListeningPort, and tests pass with 9. Proposed: write the reason and add a preview--999 rejection case, or lower the floor.
  • Author defense (R4): 1000 is a product bound, published in the open_preview port description and the docs, and the doc on the constant states that contract. Reserved-port safety does not depend on the number: leading zeros are rejected (preview--0005 in appurl_test.go) and the proxy checks AgentMinimumListeningPort. A preview--999 case would only pin the number.
  • Panel closure (R4, 1/1): Leorio, the agent that raised it (reused), accepted. 1000 is a product bound that feat(coderd): add open_preview chat tool #31284 publishes ("between 1000 and 65535") and enforces with an error naming the range; reserved-port safety is enforced by the leading-zero rejection (PortPreviewLeadingZero) and the AgentMinimumListeningPort check, independent of the value.

Law analysis

Not run. Effective additions 733 (threshold 1000). Head 2209295.

Round log

Round 1

Round type: round 1, full panel. Netero first pass: 1 P3, 2 P4, 1 Note, 1 OOS; no P0, panel proceeded. Panel (13): ging-go, kurapika, ryosuke, melody, luffy (specialists); pariston, mafuuu (core); bisky, hisoka, gon, leorio, kite (pool); zoro (wildcard, random from distilled set). Size target 9-12 for security-sensitive code plus wildcard.

Cross-check decisions:

  • CRF-6: five reviewers converged on the self-navigation escape (four P1, Luffy P2). Keep-argument for P1: the restrictions are the security boundary this PR adds, and the PR description and comments state a containment property that one line of agent JavaScript defeats. Lower-severity argument: docs(docs/coder-agents): document embedded previews #31287 docs already state the limit ("A preview page can navigate itself to the workspace's other ports and apps"). The PR description and code comments here do not, and accepting the limit is a human decision. P1 kept.
  • CRF-8: keep-argument for P2: a one-line strip closes the direct path and the dashboard loads previews automatically in feat(site): add a Preview tab for open_preview #31286. Spec check: W3C Clear Site Data clears cookies across the registered domain (HTTPS only). Navigation via CRF-6 can still send the header from a port host; linked, P2 kept.
  • CRF-10: four reviewers, P3 and P4; higher wins, P3.
  • CRF-18: Gon P3, Leorio P4; higher wins, P3.
  • CRF-20: Gon raised as P2 together with comment bloat. Keep-argument for P2: after feat(site): add a Preview tab for open_preview #31286 the two flag lists can drift and the frame behaves differently from the tab. Downgrade reason: the fix is one sentence, the consequence of drift is the intersection of two sandboxes, no security loss. P4.
  • CRF-21: Gon raised six comment-bloat P2s (proxy.go:54, 60, 521, 571, 607, 632; appurl.go:26), merged into one finding. Keep-argument for P2: CRF-6 forces rewording of exactly these comments and five copies must change together. Downgrade reason: the comments are accurate why-comments the author asked for in PRRT_kwDOGkVX1s6zkZJA, and Leorio judged them clear; the cost is maintenance only. P4, posted as a reply on that thread.
  • CRF-25: commit-message finding has no file location; placed at request.go:320 (owner sharing level comment, listed in Gon's audit).
  • Dropped without rows: verified negatives and praise notes (Kurapika agent API reach, Luffy marker and header notes, Bisky test authenticity, Kite table praise, Leorio comment praise, Melody pairing walk).
  • CI Flake Check: cancelled by workflow concurrency ("Canceling since a higher priority waiting request ... exists"), not a test failure.

Reviewed against 58fb989..2209295.

Round 2

Round type: fix round. All changes since round 1 respond to findings; the added agent/agentpreview/preview_internal_test.go change is the CRF-19 fix, no exported signature was rewritten, the PR goal is unchanged, effective additions grew 70. Churn guard: PROCEED (19 addressed, 5 contested, 0 silent). Netero (reused agent) accepted CRF-1 and raised CRF-32, CRF-33. Panel (14): contested raisers luffy, bisky, hisoka, gon, kite (all reused agents); raisers of fixed findings kurapika, melody, pariston, mafuuu, leorio, ryosuke, zoro (new agents); specialist ging-go (new); wildcard chopper (random from meruem, chopper, knov, razor).

Cross-check decisions:

  • CRF-34: four reviewers on the same line. Kurapika reproduced Domain =apps.test in Chromium and Firefox with Playwright (cookie sent to a sibling host); Bisky verified Go keeps Domain=x; Domain= as Domain ""; Mafuuu reported Chromium storing a fullwidth Domain value while Kurapika's run had both browsers reject fullwidth (contradiction unresolved; the fix is the same). Higher severity wins with empirical evidence: P2. New row instead of re-raising CRF-11 because the bypass is in the new filter code and the severity is higher.
  • CRF-35: Hisoka P3, Melody P4. Keep-argument for P3: 103 responses skip the whole preview header layer (CSP, Clear-Site-Data and Set-Cookie filters), and whether browsers apply Set-Cookie or Clear-Site-Data from a 103 is unverified; inability to verify does not lower severity. Melody's counter (Early Hints preloads only matter top-level, where self-navigation is already accepted) covers preloads but not the header filters. P3.
  • CRF-36: Pariston P3. Keep-argument: about 60 production lines plus a test matrix whose outcome is decided by frame-src in the wrapper and is bypassable by navigation in a direct tab. Downgrade argument: defense in depth if feat(site): add a Preview tab for open_preview #31286's wrapper changes. The finding offers "name the scenario" as an alternative, so kept at P3.
  • CRF-37: our round 1 CRF-18 comment stated the PortRegex equivalence; Leorio showed PortRegex accepts leading zeros, so port forwarding reaches ports below 1000. The comment acknowledges the round 1 error.
  • CRF-21: Gon re-raised; of the copies listed in the round 1 comment, proxy.go:54 and request.go:318 remain. Posted as a re-raise reply on the existing thread.
  • CRF-39: dropped. Keep-argument: every other comment line in the file wraps before 80 columns. Drop reason: no repository rule on comment width, gofmt does not enforce it, no reader is misled.
  • CRF-6: author fixed by disclosure plus the feat(site): add a Preview tab for open_preview #31286 wrapper. Kurapika, Melody, Pariston, Hisoka, Luffy verified the disclosure matches the code. Directly opened previews stay uncontained, and the decision log calls a separate registrable domain "the stronger follow-up" with no ticket: needs a human decision (review body).
  • CRF-12: Bisky reported the round 1 mutation never ran (mise python shim failure); the finding held because no row set CORSBehavior. Bisky ran the mutation this round and both passthru rows fail. Posted a confirmation with the correction.
  • Notes without an ask (Pariston on isFromOtherPreview as defense in depth, Kurapika port scoping, Ryosuke layering, Chopper test table, Leorio message) recorded here only.
  • CI: 19 of 22 failing jobs cancelled by concurrency; both title jobs fail on the scope rule (CRF-32); one remaining failure not identified (GitHub API rate limit).

Reviewed against 57dfcfb..886faee.

Round 3

Round type: fix round. Changes since round 2 address CRF-21, 22, 32, 33, 34, 37 and add a PreviewSignInParam branch (empty 200 for an authorized preview request carrying coder_preview_sign_in). No files added, no exported signature rewritten, goal unchanged, effective additions grew 42. The new branch is new behavior rather than a fix; covered by Kurapika, Hisoka, Melody, Ryosuke, Pariston, Bisky. Churn guard: PROCEED (6 addressed, 3 contested plus CRF-21 contested in part, 0 silent). Netero (new agent): CRF-32 verified (later title run 127392168004 passed), CRF-33 and CRF-34 verified, raised CRF-42. Panel (12): contested raisers hisoka, melody, pariston, chopper, gon (reused agents); kurapika, bisky, mafuuu, leorio (raisers of findings whose code changed, new agents); ging-go, ryosuke (specialists, new); wildcard razor (random from meruem, zoro, kite, knov, razor).

Cross-check decisions:

  • All four contested findings closed by their raisers; CRF-38's remaining docs request targets docs(docs/coder-agents): document embedded previews #31287 and feat(coderd): add open_preview chat tool #31284, so it moved to out of scope (CRF-43).
  • CRF-37: Leorio re-raised at P4. The round 2 comment offered "keep 1000 and write the actual reason"; the new doc restates the bound. Verified by Leorio: tests pass with the floor at 9. Posted as a re-raise reply.
  • CRF-44: Bisky mutation (EqualFold replaced by == "Domain") passed the tests. P4 kept: the regression would reopen CRF-34.
  • CRF-45: Nit kept; .claude/docs/GO.md:115 names this pattern.
  • CRF-34 fix verified by Kurapika, Hisoka, Melody, Bisky, Netero; every divergence from browser parsing drops extra lines.
  • Sign-in branch: Kurapika, Ryosuke, Melody verified it runs after isFromOtherPreview and ResolveRequest, and coder_preview_sign_in survives handleAPIKeySmuggling. No findings beyond CRF-42.
  • Razor: corpus of 8 subdomain shapes x 7 wildcard patterns found no host routed as a preview that IsPreviewHostname misses; all 11 mismatches fail closed.

Reviewed against 2d9f1f6..96a0777.

Round 4

Round type: fix round. Range-diff 96a0777..be60b96 changes only the CRF-42 comment deletion, the CRF-45 SplitSeq, and the CRF-44 test line; the rest of the full diff is a rebase onto 5537640. Churn guard: PROCEED (3 addressed, 1 contested, 0 silent). Netero (reused agent): no findings; CRF-42, CRF-44 (mutation now fails), CRF-45 verified. Panel (5): leorio (contested raiser, reused); bisky, ging-go (raisers of fixed findings, new agents); gon (comment lines touched, new agent); wildcard meruem (random from distilled set). All reported no findings. CRF-37 closed 1/1.
Human decisions recorded (IC_kwDOGkVX1s8AAAABjTUlHg): the direct-URL self-navigation gap is accepted without a ticket (separate registrable domain stays a possible follow-up); CRF-40 (StatusWriter 1xx) and CRF-41 (open_preview CDN limit) accepted. CRF-43 (HTTP-only docs) fixed in #31284 9554451, #31484 56b1985, #31287 f318f98 per author.
No open findings remain. Reviewed against 5537640..be60b96.

Round 5

Round type: fix round with no fixes; pure rebase. git range-diff 5537640916..be60b96f0c f85cc0dae2..caf373e385 prints =; #31282 base also patch-identical. Six main commits (#31815, #31768, #31740, #31745, #31814, #31773) touch no code on this PR's paths. Churn guard (reused): PROCEED, 0 open findings. Netero (reused): no findings; package tests pass on the new base. Panel (4): mafuuu, kurapika, melody (core and specialists, reused agents), wildcard kite (random from meruem, chopper, kite, zoro, knov, razor). All no findings.
No new findings. Prior status unchanged. Reviewed against: f85cc0d..caf373e.

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 routes preview--<id> and preview--<port> app hostnames to agent file previews and ports, and adds a CSP, an Origin check, a repost check, a service-worker block and chat-header stripping for those hosts. Findings: 1 P1, 2 P2, 9 P3, 9 P4, 3 Nit.

The failed Flake Check was cancelled by workflow concurrency ("Canceling since a higher priority waiting request ... exists"), not by a test failure.

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

  • coderd/workspaceapps/request.go:336: path-based port slugs return 500 instead of 400 (existing TODO), so client errors are logged as server warnings.
  • coderd/workspaceapps/proxy.go:291: the subdomain app session cookie is scoped to the whole app wildcard, so a page on any app or port host can send credentialed requests to the user's other apps.
  • coderd/httpmw/apikey.go:1030: the session cookie has no __Host- prefix and token extraction takes the first coder_session_token, so a page on any subdomain app host can shadow the dashboard session.
  • coderd/httpmw/cors.go:124: WorkspaceAppCors allows credentialed CORS reads from any port-forward origin of the same owner, including other workspaces.
  • coderd/tailnet.go:227: ServerTailnet.ReverseProxy uses the deprecated ReverseProxy.Director, whose headers a client can strip through Connection.
  • coderd/workspaceapps/proxy.go:835: non-preview apps and port forwards pass Clear-Site-Data and parent-domain Set-Cookie through, so any workspace server the user opens can clear or set cookies for the registrable domain.

Notes:

  • coderd/workspaceapps/appurl/appurl.go:153: IsPreviewID has no caller outside appurl until #31285.

🤖 This review was automatically generated with Coder Agents.

Comment thread coderd/workspaceapps/proxy.go Resolved
Comment thread coderd/workspaceapps/request.go Resolved
Comment thread coderd/workspaceapps/proxy.go Resolved
Comment thread coderd/workspaceapps/appurl/appurl.go Resolved
Comment thread coderd/workspaceapps/appurl/appurl.go Resolved
Comment thread coderd/workspaceapps/appurl/appurl.go Resolved
Comment thread coderd/workspaceapps/proxy.go Resolved
Comment thread coderd/workspaceapps/proxy.go Resolved
Comment thread coderd/workspaceapps/request.go Resolved
Comment thread coderd/workspaceapps/proxy.go Resolved
@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.

Round 2 of the review of preview hostname routing at 886faee35f. New: 1 P2, 5 P3, 1 P4. Re-raised: one P4 and one Nit.

Addressed and verified: the 500 for path-based preview slugs, the ancestor chat-header test, Clear-Site-Data on previews, the --- suffix origin miss, the 502 for blocked reposts, the passthru test gap, the token-derived preview rules, the previewPolicy, chat-header and commit-message wording, the isPreviewPort rename, the port-bound constant, the ID-width test link, and the three nits. The four contested findings on the -- suffix over-match, the separate preview--<port> host, the shared test port shares, and the older-proxy limitation are closed: each reviewer that raised one accepted the defense. Two findings are re-raised on their threads: the IsPreviewID doc still says "static", and two copies of the untrusted-agent rationale remain.

The self-navigation P1 is closed by disclosure plus the #31286 wrapper frame. A preview opened directly by its URL can still reach the owner's other apps, and the decision log calls a separate registrable domain "the stronger follow-up" without a ticket. This needs a human decision: file a ticket or explicitly accept the gap.

The failing title check is the PR title scope finding below; 19 of the other failing jobs were cancelled by workflow concurrency.

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

  • coderd/tracing/status_writer.go:58: StatusWriter records the first status passed to WriteHeader, so request logs and metrics for any proxied app that sends a 1xx show 103, not the final status.
  • coderd/x/chatd/chattool/openpreview.go (#31284): the open_preview tool description does not tell the model that port previews cannot load CDN assets or call other origins, so the model opens previews that render broken without a way to tell why.

🤖 This review was automatically generated with Coder Agents.

Comment thread coderd/workspaceapps/proxy.go Resolved
Comment thread coderd/workspaceapps/proxy.go Resolved
Comment thread coderd/workspaceapps/proxy.go Resolved
Comment thread coderd/workspaceapps/appurl/appurl.go Resolved
Comment thread coderd/workspaceapps/request.go Resolved
Comment thread coderd/workspaceapps/proxy.go Resolved
@DanielleMaywood

Copy link
Copy Markdown
Collaborator Author

Decisions on the body items, all made by @DanielleMaywood: the top-level self-navigation gap when a preview is opened directly by its URL is accepted without a ticket, and a separate registrable domain stays a possible follow-up. StatusWriter recording 103 instead of the final status (coderd/tracing/status_writer.go:58) is accepted. The open_preview tool description not mentioning that port previews cannot load CDN assets or call other origins is accepted.

🤖 Posted by Coder Agents on behalf of @DanielleMaywood.

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

Round 3 of the review of preview hostname routing at 96a07777d1. New: 2 P4 and 1 Nit. Re-raised: one P4.

Addressed and verified: the Set-Cookie filter bypass (hasDomainAttribute drops every line with a domain attribute, and every case where it differs from browser parsing drops more lines, never fewer), the IsPreviewID doc, the title scope (a later title run on this head passed), and the iframe reference in ModifyResponse. The four contested findings (103 Early Hints, the repost check, HTTP-only port previews, and the request.go:318 rationale) are closed: each reviewer that raised one accepted the defense. The new coder_preview_sign_in branch runs after the Origin check and token resolution, and the parameter survives the API key redirect.

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

  • #31287 docs and the #31284 open_preview port description: no user-facing text says port previews connect over plain HTTP, so a user who previews an HTTPS dev server gets a 502 or the server's own 400 with no explanation.

🤖 This review was automatically generated with Coder Agents.

Comment thread coderd/workspaceapps/proxy.go Resolved
Comment thread coderd/workspaceapps/proxy_test.go Resolved
Comment thread coderd/workspaceapps/proxy.go Resolved
@DanielleMaywood

Copy link
Copy Markdown
Collaborator Author

On the out-of-scope item in the review body (port previews are HTTP only): fixed. The open_preview port description now says "plain HTTP (not HTTPS) server" (#31284 at 9554451, #31484 at 56b1985), and the docs say Coder connects to the port over HTTP, not HTTPS (#31287 at f318f98).

🤖 Posted by Coder Agents on behalf of @DanielleMaywood.

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

Round 4 of the review of preview hostname routing at be60b96f0c. No new findings, and no findings remain open.

This round verified the fixes to the sign-in comment, the lowercase domain test line (making the attribute match case-sensitive now fails TestHandleSubdomain), and strings.SplitSeq in hasDomainAttribute. The PreviewMinimumPort finding is closed: the reviewer that raised it accepted 1000 as a product bound that #31284 publishes and enforces, with reserved-port safety enforced independently by the leading-zero rejection and the AgentMinimumListeningPort check.

The human decisions in the PR conversation are recorded: the self-navigation gap for a preview opened directly by its URL is accepted without a ticket, and the StatusWriter 1xx and open_preview CDN-limit items are accepted. The HTTP-only port preview item is reported fixed in #31284, #31484 and #31287.

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

Round 5 of the review of preview hostname routing at caf373e385. No new findings, and no findings remain open.

The commit is patch-identical to round 4 (git range-diff prints be60b96f0c = caf373e385), and the base commit from #31282 is also unchanged. The six new main commits do not touch any code on this PR's request paths, and the coderd/workspaceapps, appurl and agentpreview tests pass on the new base.

🤖 This review was automatically generated with Coder Agents.

Subdomain app hostnames shaped preview--<id>--<agent>--<workspace>--<owner>
proxy to http://127.0.0.1:4/api/v0/previews/<id>, the agent API route that
serves published files, and preview--<port>--... proxy to that port. The
double hyphen keeps them disjoint from coder_app slugs, which cannot contain
one, so no existing app URL changes meaning.

Previews use the owner sharing level, so only users who can connect to the
workspace's apps can open them, and port shares do not apply. Previews are
subdomain-only, and only file preview hostnames may reach the agent API's
reserved port.

Preview responses carry a sandbox and a CSP that keep every request on the
preview's own host, drop Clear-Site-Data and cookies with a Domain
attribute, and refuse redirects that resend form data to other hosts. App
requests whose Origin is another preview are rejected. A preview page can
still navigate itself to another app, so whatever embeds a preview must
prevent that with frame-src.

A preview request with the coder_preview_sign_in query parameter gets an
empty page from coderd once the browser is signed in to apps, and never
reaches the preview. An embedder whose frame-src blocks the sign-in
redirects can load it in a hidden frame first, without the preview's server
answering that frame.
Preview requests keep the same origin protections as other subdomain apps:
WorkspaceAppCors and the app's own hostname. The proxy no longer refuses
requests whose Origin is another preview host, so the removed
isFromOtherPreview check and IsPreviewHostname helper are gone with it.

Generated by Coder Agents on behalf of @DanielleMaywood.
@DanielleMaywood

Copy link
Copy Markdown
Collaborator Author

🤖 Posted by Coder Agents on behalf of @DanielleMaywood.

Removed the preview-origin request refusal, per review feedback. Requests from preview pages now get the same origin protections as any other subdomain app: the usual WorkspaceAppCors handling and the app's own hostname. The isFromOtherPreview check, the IsPreviewHostname helper, and their tests are gone. The CSP, header stripping, service worker refusal, sign-in frame, and redirect check are unchanged.

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