Skip to content

fix(security): resolve a scheme's default port before every port-keyed lookup - #13796

Merged
bolichen97 merged 2 commits into
mainfrom
fix/gateway-default-port-13345
Oct 1, 2026
Merged

bolichen97 merged 2 commits into
mainfrom
fix/gateway-default-port-13345

Conversation

@chenmingwei23

@chenmingwei23 chenmingwei23 commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Stop the desktop shell from classifying a tunnelled crew as a gateway on this machine, which silently leaked X-Internal-Secret over the tunnel.

isGatewayLocalForWindow decides whether the gateway a window points at runs on this machine. It keyed the remote-host lookup on new URL(url).port, and the URL API leaves a scheme's default port empty:

$ node -e 'console.log("80=["+new URL("http://localhost:80").port+"] 443=["+new URL("https://localhost:443").port+"] 7777=["+new URL("http://localhost:7777").port+"]")'
80=[] 443=[] 7777=[7777]

So on port 80 the lookup asked for remoteHosts[""], missed, and reported local even when remoteHosts["80"] named a remote machine reached through a tunnel. Same on 443 for an https: URL. That verdict is handed to the browser-agent channel as isGatewayLocal, and the idle host-presence heartbeat gates on it alone (if (isGatewayLocal()) await heartbeat();), where headers() attaches X-Internal-Secret. So on port 80 with a tunnelled crew configured, the heartbeat sent this machine's internal secret to localhost:80 and 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:detect in ipc-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() honours KIROCREW_PORT before any selectability check, so KIROCREW_PORT=80 makes PORT 80 and BACKEND_URL http://localhost:80. migrateRemoteHostConfig(store, PORT) then writes remoteHosts["80"] for a legacy remoteHost install, which is exactly the entry the classifier fails to find.

Not a goal

  • Widening isSelectablePort so port 80/443 may address a crew — which ports may address a crew is a port-selection decision, tracked separately from this classification fix.
  • Changing the launch path's KIROCREW_PORT/resolvePort behaviour (data-home.js deliberately keeps the raw property to pick a launch TARGET, not to key a lookup).
  • The cross-port tunnel cookie case (a remote gateway listening on a different port than the local one): neither the raw property nor a resolved default recovers that remote port, so this PR does not change it in either direction — the cookie path simply no longer guesses.

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 off URL.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. defaultedPort in gateway-auth-hint.js is already that function, already exported, already consumed by gateway-supervisor.js, and already pinned by test/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 key remoteHosts from the same window URL. Normalizing only the classifier would make the form write remoteHosts[""] while the gate read remoteHosts["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: getRemoteHostConfigForUrl reads 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 no host (a defaultName-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. saveRemoteCrewConfig refuses 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. applyTitle reads the name through getRemoteHostDefaultNameForUrl, so a legacy name still renders until it migrates.

portIsSchemeDefault is the companion to defaultedPort and lives beside it, so URL.port — whose emptiness is the whole defect — stays inside one module.

The token-refresh dialog no longer reports an SSH failure that never happened. fetchRemoteToken keys 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.js reads a stored dashboard.url to pick a launch TARGET, and resolving a default there would newly admit :80 as a target isSelectablePort exists 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 --test on 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).

  • Upgrade case: a store holding only remoteHosts[""] reads remote for every URL shape that could have written it, does NOT affect a stated non-default port, does not treat a defaultName-only record as a crew, and lets a record under the resolved key win once restated.
  • Retirement ORDER: driven through the real saveRemoteCrewConfig — a legacy record plus a refused "80" save leaves the record standing; the same statement on "443" is durable and then retires it.
  • Name migration (this revision): retirement carries defaultName onto 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; getRemoteHostDefaultNameForUrl renders a legacy name on either scheme default and ignores a stated non-default port and an unparseable URL.
  • The class is pinned by a sweep in test/gateway-auth-hint.test.js that walks every non-test module and fails on new 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.showMessageBox states, rendered with the exact shipped title + message strings (a drift guard in the capture script asserts each string is present verbatim in website/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):

Can't clear remote host from this tab

The Token Refresh dialog — unselectable-port branch (default port; a save is refused, so reconnect on a selectable port):

Token Refresh — unselectable port

The Token Refresh dialog — SSH-failed branch (an ssh attempt ran and reported an error):

Token Refresh — SSH failed

The Token Refresh dialog — re-enter-host branch (a selectable port with no ssh attempt; re-state the crew from the Tab menu):

Token Refresh — re-enter host

Plain-text copy throughout — no literal backticks or double hyphens that dialog.showMessageBox renders verbatim. Captured headlessly via website/capture/shoot-remote-crew-dialogs.mjs. The PNGs are committed under temp-screenshots/ (git-ignored by default, git add -f) because this branch is prepared without gh 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 remoteHosts from URL.port to defaultedPort was 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 delete destroyed 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

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@chenmingwei23
chenmingwei23 requested review from a team and hoang-phan98 September 25, 2026 11:16
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Sep 25, 2026
@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Fable 5) — 🟡 CONCERNS

UX-level review of cd587b9120af1d2c3f28dc4ea5b90190b2c2f785 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

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

  • The Clear refusal (shot-01) packs ~70 words into message with no detail or breaks; the reader got only the gist and rated the meaning "a guess". Rare path but every hit. Fix: keep sentence one as message, move the why/remedy to detail with \n\n, as the Token Refresh dialog already does.
  • Shots 02–04 share title and headline, and shot-02's detail opens by restating it ("No token could be fetched for…"); the reader "could not tell, from any one of them alone, which situation I'm in". Fix: front-load each detail with its differentiator, e.g. "This tab's port (80) can't store a token for crew.example.test. Reconnect…".
  • Screenshots are HTML facsimiles from website/capture/shoot-remote-crew-dialogs.mjs — copy is drift-guarded to source, but the frame is simulated and shows a warning glyph for the type: "error" refusal; a human should eyeball the real native dialogs once.

Suggestions

  • In shot-02's string, "then open that tab" names a tab that doesn't exist yet (the reader couldn't connect the procedure's halves); say "then open a new tab at that port".

[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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 25, 2026
@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — ✅ PASS

Premise-level review of cd587b9120af1d2c3f28dc4ea5b90190b2c2f785 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

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 justified

Intent: FIX — stop the shell classifying a tunnelled crew on :80/:443 as local, which sent X-Internal-Secret over the tunnel (reproduction in description; new tests fail on base).

  1. A tunnelled crew on a scheme-default port now reads as remote, so the idle heartbeat no longer sends the internal secret over the tunnel — justified
  2. The Edit Remote Crew and rename forms now write under the same resolved port the gate reads — justified
  3. A crew an older version stored under the empty key still reads as remote after upgrade, and pre-fills the form — justified
  4. A legacy pinned window title still renders on a default-port tab — justified
  5. The legacy empty-key record is retired only after a durable save, carrying the pinned name forward — justified
  6. Clearing the remote host from a default-port tab is now refused with an explanatory dialog — justified
  7. The Token Refresh failure dialog distinguishes ssh-failed / no-attempt / unselectable-port states — justified
  8. A sweep test forbids raw URL.port reads shell-wide outside four named exceptions (counted: 0 offenders in website/electron, 0 in website/src) — justified
  9. The cookie-borrow sites keep the raw port, now with pinning tests; base already failed closed (if (!port) return "" is untouched base code) — justified
  10. Four dialog screenshots plus a capture script under temp-screenshots/13796-* — rides along: UX-review evidence convention (131 existing files in temp-screenshots/)

Reuse verified: defaultedPort pre-exists with base consumers (gateway-supervisor.js:1949, runtime/gateway/token-sources.js:118); the rewritten UNSELECTABLE_PORT comment keeps its decision (80 stays unselectable) and itself asked for this classifier fix.

[FIRST-PRINCIPLES-REVIEWED] cd587b9

Description read

[DESCRIPTION-READ] 08ee915dbb891923b12df5d2d802787974e632d4b19faa56f44fb5d0ca956fe3

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

Design-level review of cd587b9120af1d2c3f28dc4ea5b90190b2c2f785 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Verify one stale description claim: "creating a name-only record on the clear path" — retireLegacyEmptyPortHost and its test pin simple deletion, and the clear path never retires.

[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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of cd587b9120af1d2c3f28dc4ea5b90190b2c2f785 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] cd587b9

False positive or not applicable? A repository writer can comment:
/ai-review override gpt cd587b9120af1d2c3f28dc4ea5b90190b2c2f785: <one-sentence reason>

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 25, 2026
@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5 Review — ✅ no blocking findings

Reviewed cd587b9120af1d2c3f28dc4ea5b90190b2c2f785 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] cd587b9

Verdict parsed from the review's SHA-scoped output markers for commit cd587b9120af1d2c3f28dc4ea5b90190b2c2f785.

False positive or not applicable? A repository writer can comment:
/ai-review override fable cd587b9120af1d2c3f28dc4ea5b90190b2c2f785: <one-sentence reason>

@chenmingwei23
chenmingwei23 force-pushed the fix/gateway-default-port-13345 branch from c33be3f to fb5f026 Compare September 25, 2026 13:08
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 25, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/gateway-default-port-13345 branch from fb5f026 to f4262fd Compare September 28, 2026 05:56
@chenmingwei23
chenmingwei23 requested a review from a team as a code owner September 28, 2026 05:56
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 28, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/gateway-default-port-13345 branch from f4262fd to 8739602 Compare September 28, 2026 06:14
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Sep 28, 2026
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Sep 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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 92028c49cc6683ff31d3b7b6a422ed3921616187 manually from the Actions tab.

@chenmingwei23
chenmingwei23 force-pushed the fix/gateway-default-port-13345 branch from 92028c4 to 619d36a Compare September 28, 2026 15:17
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

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

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@chenmingwei23 marked the fable AI finding as false positive, not applicable, or explicitly accepted for 619d36a9f2c4a7019bd02c3d650cb38e49ba1b68.

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.

This decision applies only to this commit. A new push requires a new judgment.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 28, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/gateway-default-port-13345 branch from 619d36a to 5928432 Compare September 28, 2026 16:00
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

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

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@chenmingwei23 marked the fable AI finding as false positive, not applicable, or explicitly accepted for 59284327403ae12f3f457941e78242172a55aeb8.

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.

This decision applies only to this commit. A new push requires a new judgment.

@github-actions

Copy link
Copy Markdown
Contributor

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 59284327403ae12f3f457941e78242172a55aeb8 manually from the Actions tab.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: checking Automated validation is still running labels Sep 28, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/gateway-default-port-13345 branch from 5928432 to 2afcaaa Compare September 29, 2026 01:44
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

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

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@chenmingwei23 marked the fable AI finding as false positive, not applicable, or explicitly accepted for 2afcaaa8b2c85f875c7e4845fdf814fc795a731a.

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.

This decision applies only to this commit. A new push requires a new judgment.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Sep 29, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/gateway-default-port-13345 branch from 2afcaaa to a44ee08 Compare September 30, 2026 15:29
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 30, 2026
…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 bolichen97 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.

Approved: PR Readiness passed on this head, no open change requests.

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.

security(electron): a scheme-default port erases the remote-host lookup, so the idle heartbeat sends X-Internal-Secret to a tunnelled crew

2 participants