Skip to content

fix(mobile): stop pinning the Windows pairing firewall rule to one port (STA-7672) - #21077

Closed
Jinwoo-H wants to merge 1 commit into
mainfrom
sta-7672-windows-firewall-port
Closed

Jinwoo-H wants to merge 1 commit into
mainfrom
sta-7672-windows-firewall-port

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​33 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​32
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​7 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​6

ELI5

Orca normally listens on port 6768. When it asks Windows for firewall permission, the rule it creates says "allow traffic on port 6768."

But Orca doesn't always stay on 6768 — if something else grabs that port, it moves to 6769 and remembers that choice permanently. Now the firewall is guarding a door Orca no longer uses, so the phone knocks and Windows blocks it.

The rule now says "allow traffic to the Orca app" instead of naming a port, so Orca can move and the firewall follows.

What Changed

One line in buildRepairScript: the Allow rule is written with -LocalPort Any instead of the port that happened to be bound when the user ran repair. Plus a comment explaining why, and two tests.

Why

buildRepairScript wrote -LocalPort <port> for whichever port was bound at repair time, but the desktop's listen port is not stable:

  • a persisted mobile-ws-fallback-port.json, which ws-transport.ts prefers over the pinned port forever (deliberately, for STA-1511 — devices paired while the fallback was active would otherwise strand)
  • a pairing widen rebind (runtime-rpc-network-exposure.ts)
  • an OS-assigned port when both candidates fail

Nothing reconciled the rule with the new bind. The phone then knocked on a port the firewall did not cover, and LAN/direct pairing failed with nothing pointing at the firewall as the cause.

Inspection was never the problem — it reads the live endpoint via getWebSocketEndpoint() and already accepted 'Any' (buildInspectionScript matches -eq 'Any' -or -eq '<port>'). Only the written rule was pinned, so making it port-agnostic closes the desync permanently.

The rule stays scoped to this program, the Private profile, and -EdgeTraversalPolicy Block. The port still scopes which conflicting Block rules the repair removes. This is the same shape Windows itself creates when it auto-prompts "allow this app through the firewall."

Why not fix the port drift instead. Preferring the pinned port once it is free again would regress STA-1511. With the rule no longer port-pinned, the drift no longer breaks pairing — the QR carries the live endpoint. Worth its own ticket, not a drive-by flip.

The drift itself is cross-platform, but only Windows writes a per-port permission: macOS approves per app, and Linux does not filter inbound LAN traffic by default. Hence a Windows-only change for a cross-platform root cause.

Linked Issue

STA-7672 — https://linear.app/stably/issue/STA-7672

Split out of the same ticket as #21076 (the relay half-open socket defect). The reporter hit both at once; they are independent and land separately.

Visual Proof

N/A — no UI change. The WindowsFirewallNotice copy, trigger conditions, and rendering are untouched; only the PowerShell the repair button generates changed.

Testing

pnpm tc, oxlint, and pnpm run check:code-quality:changed clean. windows-mobile-firewall.test.ts + mobile.test.ts: 55 passed.

New coverage:

  • writes a port-agnostic allow rule so a drifting bind port cannot outrun it
  • matches a port-agnostic rule whatever port the transport landed on

Verified against a live Windows firewall (Windows host running 1.4.204, the build from the report), read-only and -WhatIf only — no rule was created or modified:

Check Result
LocalPort value for a port-agnostic rule literal string Any, System.String
Production inspection predicate vs. that value, at ports 6768 / 6769 / 51234 True / True / True
Exact generated New-NetFirewallRule line with full production parameter set, -WhatIf binds cleanly, no error

That closes the real risk — that -LocalPort Any might serialize to something inspection would not match, silently breaking the check it is meant to satisfy.

Still unverified: actually creating the rule needs UAC elevation, and end-to-end phone pairing needs a physical device. Neither was done. A reviewer with an elevated Windows session should confirm the repair button produces a working rule and that pairing survives a port change.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

…rt (STA-7672)

buildRepairScript wrote the Allow rule with -LocalPort <port> for whichever
port happened to be bound when the user ran repair, but the desktop's listen
port is not stable. A persisted mobile-ws-fallback-port.json (preferred over
the pinned port for STA-1511), a pairing widen rebind, or an OS-assigned port
all move it, and nothing reconciled the rule with the new bind. The phone then
knocked on a port the firewall did not cover and LAN/direct pairing failed with
no diagnosis pointing at the firewall.

The Allow rule is now written with -LocalPort Any. Inspection already accepted
'Any' (buildInspectionScript matches -eq 'Any' -or -eq '<port>'), so the two
halves can no longer desync. The rule stays scoped to this program, the Private
profile, and -EdgeTraversalPolicy Block; the port still scopes which
conflicting Block rules the repair removes.

The port drift itself is cross-platform, but only Windows writes a per-port
permission: macOS approves per app and Linux does not filter inbound LAN
traffic by default.
@coderabbitai

coderabbitai Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 11 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: ab526885-6176-4dd1-ab80-5f40d682c104

📥 Commits

Reviewing files that changed from the base of the PR and between 71e308e and 00a4f04.

📒 Files selected for processing (2)
  • src/main/runtime/windows-mobile-firewall.test.ts
  • src/main/runtime/windows-mobile-firewall.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

ℹ️ No critical issues — the fix is sound; one stale-copy follow-up inline.

Reviewed changes

  • Port-agnostic Allow rule — buildRepairScript now emits -LocalPort Any for the Orca.MobilePairing rule instead of the port bound at repair time (src/main/runtime/windows-mobile-firewall.ts:235), with a comment explaining the drift (persisted fallback, pairing widen rebind, OS-assigned port).
  • Tests — replaced the pinned-port assertion with coverage that the new rule is port-agnostic while still program/Private/TCP/edge scoped, that port still scopes the Block-rule removal, and that the inspection predicate accepts Any for drift ports.

The root cause and the broadening trade-off both check out: the Allow rule stays scoped to this program, the Private profile, and -EdgeTraversalPolicy Block, and inspection already accepted LocalPort 'Any', so the written rule and the check agree. The only gap is the user-facing wording, noted inline.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

}
Get-NetFirewallRule -Name ${quotePowerShell(FIREWALL_RULE_NAME)} -ErrorAction SilentlyContinue | Remove-NetFirewallRule
New-NetFirewallRule -Name ${quotePowerShell(FIREWALL_RULE_NAME)} -DisplayName ${quotePowerShell(FIREWALL_RULE_DISPLAY_NAME)} -Description 'Allows Orca Mobile to connect to this Orca desktop on private networks.' -Direction Inbound -Action Allow -Enabled True -Profile Private -Protocol TCP -LocalPort ${port} -Program ${quotePowerShell(executablePath)} -EdgeTraversalPolicy Block | Out-Null`
New-NetFirewallRule -Name ${quotePowerShell(FIREWALL_RULE_NAME)} -DisplayName ${quotePowerShell(FIREWALL_RULE_DISPLAY_NAME)} -Description 'Allows Orca Mobile to connect to this Orca desktop on private networks.' -Direction Inbound -Action Allow -Enabled True -Profile Private -Protocol TCP -LocalPort Any -Program ${quotePowerShell(executablePath)} -EdgeTraversalPolicy Block | Out-Null`

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.

-LocalPort Any is the right shape for a program-scoped rule, but the user-facing copy still describes a port-scoped one, so the notice now misstates the firewall's actual scope. WindowsFirewallNotice tells the user the action "allows port {{port}}" and to add "TCP port {{port}}" — neither matches the rule this button now writes.

Technical details
# Stale firewall copy after the Allow rule stopped being port-pinned

## Affected sites
- `src/renderer/src/components/mobile/WindowsFirewallNotice.tsx:170` — `blocked-description` fallback: "...then allows port {{port}} on Private networks."
- `src/renderer/src/components/mobile/WindowsFirewallNotice.tsx:175` — `missing-description` fallback: "Add a rule for this Orca app and TCP port {{port}}..."
- `src/renderer/src/i18n/locales/en.json:13928,13934`, `es.json:12097,12103`, `fr.json:13340`, `ko.json:12140,12146`, `ja.json:12097,12103`, `zh.json:12177,12183` — same two strings in every catalog, so the code fallback alone will not change what users see.

## Required outcome
- Copy should stop promising a single port for the rule the repair button writes. `firewallStatus.port` still describes the live pairing endpoint the phone dials, so it can remain if the wording is about connecting to Orca rather than the rule's scope (e.g. drop "and TCP port {{port}}" from `missing-description`, and "then allows port {{port}}" from `blocked-description`).

@Jinwoo-H

Copy link
Copy Markdown
Contributor Author

Closing unmerged — the fix buys less than I priced it at, and it is a security widening.

The existing code already recovers from this case. inspectWindowsMobileFirewall reads the live bound port via getWebSocketEndpoint(), so a rule pinned to 6768 while the transport is on 6769 returns ruleAllowed: false. Trace that through the render condition in WindowsFirewallNotice.tsx:68-75 and the notice renders, and its repair button deletes and recreates the rule at the current port. Drift is already one click from healed, on the pairing screen the user is necessarily looking at.

So -LocalPort Any closes no genuinely-broken path. It saves one UAC prompt after a port change. Against that it widens the rule from the mobile port to every Orca listener bound to 0.0.0.0 on private networks — a scope I never enumerated. Not a trade worth making.

The two cases the notice does not cover are the domain and public network profiles, and a Private-profile allow rule is inapplicable on both, so this change would not have helped there either.

This also corrects the framing this ticket started with: the port drift explains the "nothing listening on 6768" observation, but it is not a standalone broken path. #21076 (the relay half-open socket) is the real defect.

Port-drift analysis preserved for a follow-up ticket; branch left in place.

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.

1 participant