Skip to content

@W-22838968 Port Squatting — Token-Based Check with Flag-Gated Backward Compat#57

Merged
ankitsinghkuntal09 merged 6 commits into
mainfrom
ankit/W-22838968-port-squat-backward-compat
Jun 11, 2026
Merged

@W-22838968 Port Squatting — Token-Based Check with Flag-Gated Backward Compat#57
ankitsinghkuntal09 merged 6 commits into
mainfrom
ankit/W-22838968-port-squat-backward-compat

Conversation

@ankitsinghkuntal09

@ankitsinghkuntal09 ankitsinghkuntal09 commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

@W-22838968@

Fix — dual-acceptance with a kill switch

checkPortStatus returns one of four states; classifyOccupiedPort decides the action:

What's on the port Response Action
Nothing TCP-reachable: no available — spawn our dev server
Our server with right token 200 + X-Live-Preview-Token matches verified — silent reuse
OK but no token header 200 + header missing legacy — see below
Wrong token / non-OK mismatch or non-2xx foreign — abort with PortSquattingAbort

legacy is the backward-compat path. An old @salesforce/ui-bundle and a passive squatter are indistinguishable from the CLI side — the flag is the security boundary:

  • ALLOW_LEGACY_WEBAPPS_DEFAULT = true (this PR's default): proceed, emit one loud warning per webapp per CLI process. Warning surfaces as:
  • ALLOW_LEGACY_WEBAPPS_DEFAULT = false (or SF_UI_BUNDLE_ALLOW_LEGACY_WEBAPPS=false at runtime): strict mode — abort with PortSquattingAbort on legacy. Same hard error as foreign.

Once webapp adoption of the token-echoing release is high, flip the default to false;

Tested locally (5 scenarios, default mode + strict mode)

  • Both webapps NEW, no squatter → both verified, silent
  • Both webapps OLD, no squatter → both legacy, warning shown once per bundle, dev server reused
  • One OLD + one NEW, switch back and forth → each picks the correct state
  • One OLD + one NEW + squatter on 5173 → legacy (squatter indistinguishable from old), warning shown; strict mode aborts
  • Both NEW + squatter on 5173 → legacy (squatter answers first), warning shown; strict mode aborts with PortSquattingAbort

Uploading Screenshot 2026-06-10 at 12.50.14 PM.png…

@ankitsinghkuntal09 ankitsinghkuntal09 self-assigned this Jun 8, 2026
@ankitsinghkuntal09 ankitsinghkuntal09 force-pushed the ankit/W-22838968-port-squat-backward-compat branch from fcdb4e3 to ead9962 Compare June 9, 2026 12:32
@ankitsinghkuntal09 ankitsinghkuntal09 changed the title @W-22838968 Port Squatting — Token-Based Check with Backward Compat @W-22838968 Port Squatting — Token-Based Check with Flag-Gated Backward Compat Jun 9, 2026
@ankitsinghkuntal09 ankitsinghkuntal09 force-pushed the ankit/W-22838968-port-squat-backward-compat branch from ead9962 to 06a2c41 Compare June 9, 2026 12:38
Supersedes the version-gated approach (reading @salesforce/ui-bundle version from
node_modules) — fragile across lockfile + Code Builder layouts.

A server on port 5173 that responds OK but does NOT echo X-Live-Preview-Token is
now classified as "legacy" (old webapp, or a passive squatter — indistinguishable
to the CLI). Behavior under "legacy":
- ALLOW_LEGACY_WEBAPPS_DEFAULT=true (current default): proceed, emit one loud
  warning per webapp per process (stderr structured JSON + SfCommand.warn()).
- false / SF_UI_BUNDLE_ALLOW_LEGACY_WEBAPPS=false: abort with PortSquattingAbort.

Once webapp adoption of the token-echoing release is high, flip the default to
false; the liberal branch then becomes a one-line removal.

Changes:
- 4-state checkPortStatus: available | verified | legacy | foreign
- classifyOccupiedPort centralizes the abort-vs-warn decision (shared by
  pre-flight one-shot and post-spawn polling)
- emitLegacyWebappWarning emits {"warn":"LEGACY_WEBAPP_DETECTED",...} on stderr
  (consumed by the VS Code extension) + this.warn() to the terminal
- Removed: MIN_TOKEN_SUPPORTED_VERSION, compareVersions,
  getWebappUiBundleVersion, isNewWebapp, isUrlReachable, pollUntilReachable,
  fs/path imports — all version-gating dead code

Co-authored-by: Cursor <cursoragent@cursor.com>
@ankitsinghkuntal09 ankitsinghkuntal09 force-pushed the ankit/W-22838968-port-squat-backward-compat branch from 06a2c41 to fc79710 Compare June 9, 2026 12:41
ankitsinghkuntal09 and others added 2 commits June 10, 2026 12:01
Replace verbose mechanism-leaking warning with a concise, actionable one.
Per code review feedback — keep it minimal, no implementation details.
…838968

Per code review (round 2): drop 'outdated dependency' framing and adopt
authenticity-verification wording. Honest about what the CLI can actually
assert (couldn't verify the server) without naming the verification
mechanism. Mirrored on the VS Code extension side.

Co-authored-by: Cursor <cursoragent@cursor.com>

@deepu-mungamuri94 deepu-mungamuri94 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

@ankitsinghkuntal09 ankitsinghkuntal09 merged commit 61021d1 into main Jun 11, 2026
14 checks passed
@ankitsinghkuntal09 ankitsinghkuntal09 deleted the ankit/W-22838968-port-squat-backward-compat branch June 11, 2026 04:35
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.

3 participants