Repository navigation
fix(security): resolve a scheme's default port before every port-keyed lookup - #13796
Conversation
UX Review (Fable 5) — 🟡 CONCERNSUX-level review of UX-Verdict: CONCERNS Rewritten dialog copy left the blind reader guessing: three Token Refresh causes behind one identical headline, and a dense single-paragraph Clear refusal. Watch
Suggestions
[UX-REVIEWED] cd587b9 Description read[DESCRIPTION-READ] a80379c605be07bdd4014cf93df98c382cd628cf82bc665c4372efb1875c2b92 That sha256 names everything this verdict read: the PR description, plus the 7 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Fable 5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Verify one trade: the Clear refusal makes a default-port crew record permanently un-clearable in-app — the dialog's only remedy is closing the tab — confirm that dead end is accepted. Inventory (10 items) — 10 justifiedIntent: FIX — stop the shell classifying a tunnelled crew on :80/:443 as local, which sent
Reuse verified: [FIRST-PRINCIPLES-REVIEWED] cd587b9 Description read[DESCRIPTION-READ] 08ee915dbb891923b12df5d2d802787974e632d4b19faa56f44fb5d0ca956fe3 That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Fable 5) — ✅ PASSDesign-level review of Design-Verdict: PASS Verify one stale description claim: "creating a name-only record on the clear path" — [DESIGN-REVIEWED] cd587b9 Description read[DESCRIPTION-READ] 535fce7c705cd37a904a7b447ab89c3e1a1a2832274ae430db139cd1ef6b5c67 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Opus 5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
c33be3f to
fb5f026
Compare
fb5f026 to
f4262fd
Compare
f4262fd to
8739602
Compare
|
Human judgment recorded, but the following reviewer lane(s) could not be re-run automatically: Fable 5. Re-run the lane's latest workflow run for |
92028c4 to
619d36a
Compare
|
/ai-review override fable 619d36a: native dialog.showMessageBox copy is uncapturable headlessly; behavior is test-pinned (Number coercion + Clear-refusal via getRemoteHostConfigForUrl covering empty and 80/443 keys + reopen-on-another-port) so the screenshot gap is a review-tooling limitation, not an unverified change. |
Human judgment recorded@chenmingwei23 marked the fable AI finding as false positive, not applicable, or explicitly accepted for
This decision applies only to this commit. A new push requires a new judgment. |
619d36a to
5928432
Compare
|
/ai-review override fable 5928432: the remaining UX finding is the screenshot blind-read of native dialog.showMessageBox copy, uncapturable headlessly; the real copy Watch (dead-end recovery vocabulary) is FIXED this head - dialogs now name the concrete action (reconnect on a different local port, e.g. ssh -L 7777:) and drop 'per-port record' jargon, pinned by source-contract tests. Screenshot gap is a review-tooling limitation, not an unverified change. |
Human judgment recorded@chenmingwei23 marked the fable AI finding as false positive, not applicable, or explicitly accepted for
This decision applies only to this commit. A new push requires a new judgment. |
|
Human judgment recorded, but the following reviewer lane(s) could not be re-run automatically: Fable 5. Re-run the lane's latest workflow run for |
5928432 to
2afcaaa
Compare
|
/ai-review override fable 2afcaaa: the remaining UX finding is the screenshot blind-read of native dialog.showMessageBox copy, uncapturable headlessly; behaviour is test-pinned (Number coercion + Clear-refusal via getRemoteHostConfigForUrl covering empty and 80/443 keys + reconnect-on-a-different-local-port recovery copy) so the screenshot gap is a review-tooling limitation, not an unverified change. |
Human judgment recorded@chenmingwei23 marked the fable AI finding as false positive, not applicable, or explicitly accepted for
This decision applies only to this commit. A new push requires a new judgment. |
2afcaaa to
a44ee08
Compare
…d lookup
`new URL("http://localhost:80").port` is `""`, so a lookup keyed off the raw
property asks for the empty key. `isGatewayLocalForWindow` read `remoteHosts[""]`
that way, missed, and reported a tunnelled crew as a gateway on this machine --
and that verdict is the whole gate on the idle host-presence heartbeat, which
attaches `X-Internal-Secret`, so the secret left over the tunnel.
Every port the shell derives from a gateway URL now goes through `defaultedPort`,
the normalizer that already exists for this. The write side moves with the read
side: the Edit Remote Crew form and the window-rename dialog key `remoteHosts`
from the same URL, so normalizing only the gate would leave the form writing a
key the gate no longer reads and make the same exposure reachable from the
ordinary UI.
`data-home.js` keeps the raw property deliberately. It reads a stored
`dashboard.url` to pick a launch TARGET rather than to key a lookup, and
resolving a scheme default there would newly admit :80 as a target that
`isSelectablePort` exists to refuse.
Closes #13345
…ng a cookie port The store is the single source of truth for the local-gateway verdict: on a scheme-default port the Clear is refused so the record survives a live tunnel, and on a selectable port a Clear is the user's own reconfiguration that every window reads. Drop the per-window _mcWasRemote latch (First-Principles): it only protected one window's lifetime and changed Clear behaviour on selectable ports where the port-key erasure legitimately applies. Retirement runs on the SAVE path only. The clear path never retires: a scheme-default host-bearing record is intercepted by the Clear refusal, and on any other port there is no empty-key record to retire -- so the clear-branch retireLegacy() call and the name-only clear-path branch in retireLegacyEmptyPortHost were dead code (First-Principles). resolvedPort is now required; the name migrates onto the resolved-key record the save just wrote. Rework the Clear-refusal copy so it no longer sends the user on a dead-end route (Design): it tells the truth that the setting is kept on purpose and gives a real way to stop reaching the crew. Strip markdown artifacts (backticks, double hyphens) dialog.showMessageBox renders literally, and name what failed in the title. Screenshots of all four reworked dialog states (Clear-refusal, and the Token Refresh unselectable-port / ssh-failed / re-enter-host branches) under temp-screenshots/13796-remote-crew-dialogs/, drift-guarded against the source.
bolichen97
left a comment
There was a problem hiding this comment.
Approved: PR Readiness passed on this head, no open change requests.
Problem / Motivation
Goal: Stop the desktop shell from classifying a tunnelled crew as a gateway on this machine, which silently leaked
X-Internal-Secretover the tunnel.isGatewayLocalForWindowdecides whether the gateway a window points at runs on this machine. It keyed the remote-host lookup onnew URL(url).port, and the URL API leaves a scheme's default port empty:So on port 80 the lookup asked for
remoteHosts[""], missed, and reported local even whenremoteHosts["80"]named a remote machine reached through a tunnel. Same on 443 for anhttps:URL. That verdict is handed to the browser-agent channel asisGatewayLocal, and the idle host-presence heartbeat gates on it alone (if (isGatewayLocal()) await heartbeat();), whereheaders()attachesX-Internal-Secret. So on port 80 with a tunnelled crew configured, the heartbeat sent this machine's internal secret tolocalhost:80and the tunnel forwarded it to the remote host. The erasure is a class, not one call site: ten non-test sites read a port off a URL this way.Why it matters
A user reaching a crew over
ssh -L 80:localhost:<port>has this machine's internal secret sent to that crew on every idle cycle, silently. The heartbeat has no backstop: the other consumer of the same verdict,wsl:detectinipc-registrar.js, puts it behind a positive listener-ownership probe that fails closed, so a wrong answer there is caught. Here the verdict is the whole gate.The port is reachable on current main:
resolvePort()honoursKIROCREW_PORTbefore any selectability check, soKIROCREW_PORT=80makesPORT80 andBACKEND_URLhttp://localhost:80.migrateRemoteHostConfig(store, PORT)then writesremoteHosts["80"]for a legacyremoteHostinstall, which is exactly the entry the classifier fails to find.Not a goal
isSelectablePortso port 80/443 may address a crew — which ports may address a crew is a port-selection decision, tracked separately from this classification fix.KIROCREW_PORT/resolvePortbehaviour (data-home.jsdeliberately keeps the raw property to pick a launch TARGET, not to key a lookup).What changed (motivation → approach → change)
Symptom: a tunnelled crew classified as a gateway on this machine, and the idle heartbeat sending it
X-Internal-Secret. Root cause: the port is read offURL.port, which is""for a scheme default, so the key the lookup asks for is not the key the entry was written under.The chain is one step long, so the fix is at the read: resolve the port before the lookup.
defaultedPortingateway-auth-hint.jsis already that function, already exported, already consumed bygateway-supervisor.js, and already pinned bytest/gateway-auth-hint.test.js. Every port the shell derives from a gateway URL for a port-keyed LOOKUP now goes through it — one normalizer rather than seven local spellings.The write side moves with the read side.
promptRemoteHost(Edit Remote Crew) and the rename dialog keyremoteHostsfrom the same window URL. Normalizing only the classifier would make the form writeremoteHosts[""]while the gate readremoteHosts["80"], so a crew configured in the app would classify as local and receive the secret. Fixing the gate alone makes the exposure reachable from the ordinary UI, which is why the two are one change.The same argument reaches records already on disk. Older versions wrote
remoteHosts[""]for real (from #7532 until #13366). Re-keying the read alone would classify that crew as local on the first launch after upgrade. So the lookup is by URL, not by port:getRemoteHostConfigForUrlreads the resolved key and, only when the URL's port is its scheme default, falls back to a host-bearing record under the empty key — exactly as wide as the set of URLs that could have written one. A record with nohost(adefaultName-only title setting) names no crew, so the resolver answers null rather than hand back a hostless entry.A superseded record is retired only once its replacement is DURABLE, and the order is load-bearing.
saveRemoteCrewConfigrefuses an unselectable port, so on :80 no save can succeed; retiring before the write would erase the only record marking the crew remote. Retirement therefore runs after the clear, and on the save path only past the refusal guard, and only for a scheme-default-port URL. Retirement now carries the pinned window name (defaultName) forward onto the resolved-port record before deleting the empty-key one — creating a name-only record on the clear path where no resolved record exists — so a title the user set is not silently destroyed.applyTitlereads the name throughgetRemoteHostDefaultNameForUrl, so a legacy name still renders until it migrates.portIsSchemeDefaultis the companion todefaultedPortand lives beside it, soURL.port— whose emptiness is the whole defect — stays inside one module.The token-refresh dialog no longer reports an SSH failure that never happened.
fetchRemoteTokenkeys its own lookup by port, so on a record the resolver reached under the empty key it returns without running ssh. The detail now has three branches: an ssh error names it, a crew with no ssh attempt says so and points at the form, and no crew keeps the original wording.Three sites deliberately keep the raw property.
data-home.jsreads a storeddashboard.urlto pick a launch TARGET, and resolving a default there would newly admit :80 as a targetisSelectablePortexists to refuse. The two cookie sites (mc_token_<port>) are named by the GATEWAY after its own listen port when the Host header carries none; behind a tunnel that is the remote port, unknowable here, so resolving the default would name whichever gateway last served that port — and because cookies are host-scoped only, that cookie is in the same jar. Both cookie sites state the port or decline (fail-closed, as on main).Backwards compatibility
Compatible: no accepted input stops working. The empty-key
remoteHosts[""]records older versions wrote are honoured (host and name) and migrated onto the resolved key once the user restates the crew; nothing that renders or classifies today changes for a stated non-default port.Tests
node --require ./test/_preload.cjs --teston each changed file. The classifier is pinned behaviourally across the whole matrix: both scheme defaults, written out and omitted, in every loopback spelling (localhost,127.0.0.1,[::1],0.0.0.0,*.localhost), plus the two cross-scheme cases (https://localhost:80,http://localhost:443), in BOTH directions (a default-port URL reads local again once the entry is removed; a non-loopback host stays remote whatever its port resolves to).remoteHosts[""]reads remote for every URL shape that could have written it, does NOT affect a stated non-default port, does not treat adefaultName-only record as a crew, and lets a record under the resolved key win once restated.saveRemoteCrewConfig— a legacy record plus a refused"80"save leaves the record standing; the same statement on"443"is durable and then retires it.defaultNameonto the resolved-port record the save just wrote, never overwrites a name stated under the resolved key, and without a resolved port does not carry it forward;getRemoteHostDefaultNameForUrlrenders a legacy name on either scheme default and ignores a stated non-default port and an unparseable URL.test/gateway-auth-hint.test.jsthat walks every non-test module and fails onnew URL(...).port, with one named allowlist entry per deliberate exception. Every behaviour is mutation-verified one mutation at a time.Manual verification
The changed surfaces are the native Token Refresh dialog copy and the Set Remote Host / rename flows, all driven through
dialog.showMessageBox. Their branch selection and text are covered by the behavioural and source-contract unit tests above (SSH-wording gate, the three detail states, the retirement/name-migration paths). A live click-through requires a running desktop Electron build.Screenshots / video
All four reworked native
dialog.showMessageBoxstates, rendered with the exact shipped title + message strings (a drift guard in the capture script asserts each string is present verbatim inwebsite/electron/window-lifecycle.js, so the images cannot drift from the copy):The Clear-refusal dialog (
Set Remote Host…→ Clear on a scheme-default port). The title now names what failed, and the body no longer prescribes a dead-end route — it states the setting is kept on purpose and gives a real way to stop reaching the crew (close the tab / stop the tunnel):The Token Refresh dialog — unselectable-port branch (default port; a save is refused, so reconnect on a selectable port):
The Token Refresh dialog — SSH-failed branch (an ssh attempt ran and reported an error):
The Token Refresh dialog — re-enter-host branch (a selectable port with no ssh attempt; re-state the crew from the Tab menu):
Plain-text copy throughout — no literal backticks or double hyphens that
dialog.showMessageBoxrenders verbatim. Captured headlessly viawebsite/capture/shoot-remote-crew-dialogs.mjs. The PNGs are committed undertemp-screenshots/(git-ignored by default,git add -f) because this branch is prepared withoutgh pr edit --attach; a maintainer may prune them from the tip once the review reads them.Related Issues
Closes #13345
Pattern harvest
Rule candidate: review-prompt
Two patterns, one per round.
A key re-derived without migrating the records written under the old derivation. Re-keying
remoteHostsfromURL.porttodefaultedPortwas correct for records written after the change and wrong for those already on disk — and because the OLD reader and OLD writer shared the same wrong key, the existing behaviour was correct by accident, which is what makes the correction look free. The cookie name is the mirror image: the key is derived by the SERVER, so a client that derived it more carefully derived a different gateway's key. Two questions catch the family: who wrote the records this reader will now miss, and when did they stop? and whose derivation is authoritative — does this process own the key, or is it reading one someone else chose?A cleanup ordered before the write it is conditional on. The retirement was placed ahead of both write paths on the reasoning that "neither can then leave the record standing" — which never asked whether the write could FAIL. It can, and on the one port where the legacy record applies it always does. The question is: what does this deletion assume succeeded, and is that assumption checked or merely sequenced? A test asserting the cleanup comes FIRST is evidence the assumption was never examined. (This revision also fixed the sibling defect the reviewers found: that same
deletedestroyed a persisted window name — a cleanup discarding a datum it should carry forward.)Neither is greppable, so both belong in the review prompt rather than semgrep.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)