Skip to content

fix(ssh): a GatewayPorts yes setting publishes the tunnel on every interface - #1658

Merged
larroy merged 1 commit into
openclaw:mainfrom
SebTardif:fix/f105-ssh-loopback-forward
Oct 16, 2026
Merged

larroy merged 1 commit into
openclaw:mainfrom
SebTardif:fix/f105-ssh-loopback-forward

Conversation

@SebTardif

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: an SSH tunnel forward follows GatewayPorts yes and listens on every interface.

User Impact

User impact: the gateway forward and the browser-proxy forward stay on 127.0.0.1. A wildcard listener on that port no longer counts as a successful tunnel.

Why This Change Was Made

The forward was -L <local>:<remote> with no bind address, and ownership treated 0.0.0.0 and :: as loopback. The command now binds 127.0.0.1, sets GatewayPorts=no, and rejects a wildcard listener.

Evidence

SshTunnelCommandLine.BuildArguments on head 7776b4c1a13ecf45d0c2c046b9b3bb6dd2b3a353 reported built_has_gatewayports_no=True, built_binds_loopback=True, and built_has_unbound_forward=False.

A disposable sshd on 127.0.0.1:19293 accepted one local forward. The client config set GatewayPorts yes. The previous form -L 19291:127.0.0.1:19290 listened on 0.0.0.0. The new form -L 127.0.0.1:19292:127.0.0.1:19290 with GatewayPorts=no listened on 127.0.0.1. Both processes were running when those addresses were read. The user's .ssh directory was not changed.

old_bind=0.0.0.0
new_bind=127.0.0.1
old_running=True
new_running=True

Change Type

  • Bug fix
  • Feature
  • Refactor
  • Docs or instructions
  • Tests or validation
  • Security hardening
  • Chore or infrastructure

Scope

  • Tray or WinUI UX
  • Windows node capability
  • Local MCP or winnode
  • Gateway, connection, or pairing
  • Setup or onboarding
  • Permissions, privacy, or security
  • Tests, CI, or docs

Required proof pools

none: the changed behavior is the local bind address of an SSH forward. The named pools do not set GatewayPorts or read that listener.

Validation

  • ./build.ps1 exit 0 (Shared, Cli, WinNodeCli, SetupEngine, WinUI).
  • dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj --no-restore: 4262 passed, 33 skipped, 0 failed, 4295 total.
  • dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj: 3990 passed, 0 skipped, 0 failed.
  • dotnet test ./tests/OpenClaw.Connection.Tests/OpenClaw.Connection.Tests.csproj --filter FullyQualifiedName~SshTunnelServiceTests: 23 passed, 0 failed.

Real behavior proof

  • Behavior or issue addressed: An unbound local forward with GatewayPorts yes listened on 0.0.0.0. The product forward now listens on 127.0.0.1.
  • Real environment tested: Windows, .NET SDK 10.0.401, OpenSSH client, disposable sshd on 127.0.0.1:19293. Head 7776b4c1a13ecf45d0c2c046b9b3bb6dd2b3a353.
  • Exact steps or command run after this patch: Built the product arguments, then started the old -L 19291:127.0.0.1:19290 and the new -L 127.0.0.1:19292:127.0.0.1:19290 with -o GatewayPorts=no, both under a client config of GatewayPorts yes.
  • Evidence after fix:
old_bind=0.0.0.0
new_bind=127.0.0.1
old_running=True
new_running=True
built_has_gatewayports_no=True
built_binds_loopback=True
  • Observed result after fix: The new forward's listener address was 127.0.0.1. The previous forward's listener address was 0.0.0.0.
  • What was not tested: The tray SSH connect button was not clicked. A machine-wide ssh_config was not edited.
  • Environment tested: Windows, .NET SDK 10.0.401.
  • PR head or commit tested: 7776b4c1a13ecf45d0c2c046b9b3bb6dd2b3a353
  • Exact steps or command run: product BuildArguments, then the two ssh -N -L processes above.
  • Evidence after fix: new_bind=127.0.0.1 and old_bind=0.0.0.0.
  • Observed result: the product forward form stays on loopback when GatewayPorts yes is set.
  • Screenshot or artifact links verified? No
  • Not verified or blocked: the tray button. No machine ssh_config change.

Security Impact

  • New permissions or capabilities? No
  • Secrets or tokens handling changed? No
  • New or changed network calls? Yes
  • Command or tool execution surface changed? No
  • Data access scope changed? No
  • If any answer is Yes, explain the risk and mitigation: Local forwards bind 127.0.0.1 and pass GatewayPorts=no. A wildcard listener fails ownership instead of being treated as the tunnel. No keys or tokens were printed.

Compatibility and Migration

  • Backward compatible? Yes
  • Config or environment changes? No
  • Migration needed? No
  • If yes, list the exact upgrade steps: none

Review Conversations

  • I replied to or resolved every bot review conversation addressed by this PR.
  • I left unresolved only conversations that still need maintainer judgment.

An ssh_config GatewayPorts yes made an unbound -L listen on every
interface, and ownership treated that wildcard listener as loopback.
Forwards now bind 127.0.0.1, set GatewayPorts=no, and a wildcard
listener fails the ownership check.

Signed-off-by: Sebastien Tardif <[email protected]>
@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 7, 2026
@clawsweeper

clawsweeper Bot commented Oct 7, 2026

Copy link
Copy Markdown

Codex review: needs maintainer review before merge. Reviewed October 6, 2026, 8:07 PM ET / October 7, 2026, 00:07 UTC.

ClawSweeper review

What this changes

The PR binds gateway and browser-proxy SSH forwards to 127.0.0.1, overrides GatewayPorts, and rejects wildcard listeners during tunnel ownership checks.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main and v2026.9.4 retain the unbound SSH forward. The focused patch has no identified blocking defect, and the supplied Windows before/after output demonstrates the intended listener restriction.

Priority: P2
Reviewed head: 7776b4c1a13ecf45d0c2c046b9b3bb6dd2b3a353

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, maintainable fix with direct before/after runtime evidence and relevant regression coverage.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Current-head product argument inspection and real Windows OpenSSH listener output show the changed forward form remains on 127.0.0.1 under GatewayPorts yes while the old form binds 0.0.0.0. This covers the changed bind boundary; wildcard-validator tests are supplemental. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Current-head product argument inspection and real Windows OpenSSH listener output show the changed forward form remains on 127.0.0.1 under GatewayPorts yes while the old form binds 0.0.0.0. This covers the changed bind boundary; wildcard-validator tests are supplemental. No stored-data contract changes.
Evidence reviewed 9 items Verified introduced change: The pinned main-to-head diff changes only the SSH command builder, listener ownership validation, and their tests. Both local forwards use the same updated builder.
Current main still needs the fix: The main command builder emits an unbound -L forward without GatewayPorts=no. Main listener validation also accepts wildcard addresses when the process identity matches.
Latest release retains the previous behavior: The v2026.9.4 command builder likewise has no GatewayPorts override and emits -L without an explicit local bind address.
Findings None None.
Security None None.

How this fits together

Managed SSH tunnels let the Windows app reach a remote gateway and its browser-control endpoint through local ports. The connection layer verifies the SSH listener before using that endpoint for authenticated connections.

flowchart TD
    A[Saved SSH connection] --> B[Build local forwards]
    B --> C[OpenSSH process]
    C --> D[Loopback listeners]
    D --> E[Verify listener ownership]
    E --> F[Gateway connection]
    D --> G[Browser proxy connection]
Loading

Before merge

None.

Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production and test LOC production +16/-4, tests +32/-3 The production growth adds a focused wildcard guard and explicit loopback command policy, supported by regression coverage.

Technical review

Best possible solution:

Keep managed gateway and browser-proxy forwards explicitly local, with wildcard rejection as a second check against unintended exposure.

Do we have a high-confidence way to reproduce the issue?

Yes. Main emits the unbound forward and accepts its wildcard listener; the supplied Windows OpenSSH comparison demonstrates the GatewayPorts yes trigger. The reviewer did not execute that scenario.

Is this the best way to solve the issue?

Yes. Updating the existing shared builder and ownership validator fixes the local-only contract without introducing a competing tunnel implementation or persisted setting.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 839dad2936c7.

Labels

Label changes:

  • add P2: This is a bounded security hardening fix for managed SSH forwards affected by GatewayPorts yes, with no demonstrated active exploitation or urgent regression.
  • add proof: sufficient: Contributor real behavior proof is sufficient. Current-head product argument inspection and real Windows OpenSSH listener output show the changed forward form remains on 127.0.0.1 under GatewayPorts yes while the old form binds 0.0.0.0. This covers the changed bind boundary; wildcard-validator tests are supplemental. No stored-data contract changes.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Current-head product argument inspection and real Windows OpenSSH listener output show the changed forward form remains on 127.0.0.1 under GatewayPorts yes while the old form binds 0.0.0.0. This covers the changed bind boundary; wildcard-validator tests are supplemental. No stored-data contract changes.

Label justifications:

  • P2: This is a bounded security hardening fix for managed SSH forwards affected by GatewayPorts yes, with no demonstrated active exploitation or urgent regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Current-head product argument inspection and real Windows OpenSSH listener output show the changed forward form remains on 127.0.0.1 under GatewayPorts yes while the old form binds 0.0.0.0. This covers the changed bind boundary; wildcard-validator tests are supplemental. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. Current-head product argument inspection and real Windows OpenSSH listener output show the changed forward form remains on 127.0.0.1 under GatewayPorts yes while the old form binds 0.0.0.0. This covers the changed bind boundary; wildcard-validator tests are supplemental. No stored-data contract changes.

Evidence

What I checked:

  • Verified introduced change: The pinned main-to-head diff changes only the SSH command builder, listener ownership validation, and their tests. Both local forwards use the same updated builder. (src/OpenClaw.Shared/SshTunnelCommandLine.cs:16, 7776b4c1a13e)
  • Current main still needs the fix: The main command builder emits an unbound -L forward without GatewayPorts=no. Main listener validation also accepts wildcard addresses when the process identity matches. (src/OpenClaw.Shared/SshTunnelCommandLine.cs:92, 839dad2936c7)
  • Latest release retains the previous behavior: The v2026.9.4 command builder likewise has no GatewayPorts override and emits -L without an explicit local bind address. (src/OpenClaw.Shared/SshTunnelCommandLine.cs, 3c43751b2bac)
  • Listener rejection preserves existing ownership checks: Wildcard listeners now throw before success; loopback listeners must still match the launched process ID and start time. Existing tests cover ordinary loopback success, conflicting owners, incomplete snapshots, and unrelated non-loopback listeners. The added regression covers IPv4 and IPv6 wildcard rejection. (src/OpenClaw.Connection/SshTunnelService.cs:748, 7776b4c1a13e)
  • Documented connection boundary: The architecture documents managed SSH as a local forward checked before gateway connection and credential handoff. The patch leaves lifecycle-generation binding and credential authorization intact, narrows listener exposure, and changes no persisted configuration schema. (docs/CONNECTION_ARCHITECTURE.md:760, 7776b4c1a13e)
  • Current-head real OpenSSH proof: The complete supplied PR body identifies head 7776b4c and Windows OpenSSH with a disposable sshd. Under GatewayPorts yes, copied runtime output reports old_bind=0.0.0.0 and new_bind=127.0.0.1 while both processes remain running; product argument inspection confirms the override and explicit bind. This directly demonstrates the changed network-listener behavior. The tray button was explicitly not exercised. (7776b4c1a13e)

Likely related people:

  • shanselman: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • SebTardif: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@karkarl

karkarl commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

Global triage: NEEDS_HUMAN_TEST. Take confidence 55%; recommendation confidence 97%; effort small; risk high.

Reviewed exact head 7776b4c1a13e. GitHub currently reports CLEAN with 25 passing, 0 failing, and 0 pending checks. proof label is sufficient. Durable automated signal: Codex review: needs maintainer review before merge..

Maintainer or proof-pool owner: run every declared Windows proof pool at this exact head and replace blocked or historical evidence with current-head results.

This is a triage classification, not a merge action. No branch changes were made.

@larroy

larroy commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator

LGTM, running @shanselman review skill...

@larroy

larroy commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator

Independent review: approve, no findings at P0–P3

Reviewed head 7776b4c1 (single commit, merge-base 839dad29).

Method

Shared autoreview helper, branch mode, --max-priority P3 per the repo review gate. Engine: Codex CLI (gpt-6.1-sol, medium reasoning). Result: scoped-clean, 1 complete pass, "patch is correct (0.91)". I then verified the diff independently against the call graph and re-ran the targeted tests at this head.

What I verified beyond the bot

  • Coverage of the fix. All four production consumers of SshTunnelCommandLine (SshTunnelService.StartProcess, GatewayTerminalLauncher, the setup dry-run validation, BrowserProxySshTunnelForwardPolicy) share the single builder, so -o GatewayPorts=no plus the explicit -L 127.0.0.1:<local>:... bind reaches every managed tunnel invocation, including the browser-proxy companion forward. Argument-injection safety is unchanged: the bind address is a fixed literal; user/host charset validation is untouched.
  • Fail-closed, not crash. Both callers of ValidateListenerOwnership (WaitForOwnedLocalListenerAsync in StartOwnedAsync, and IsOwnedListenerReadyAsync during credential-handoff reauthorization) treat the new wildcard InvalidOperationException as a connection failure. A wildcard listener can no longer count as a successful tunnel even when it belongs to the ssh process itself, which is exactly the case the old CanServeLoopback wrongly accepted.
  • No regression for legit topologies. A non-loopback, non-wildcard listener on the same port still returns false and is ignored, preserving the documented invariant in docs/CONNECTION_ARCHITECTURE.md (same-number listeners bound only to non-loopback interfaces are irrelevant to the local forward). EnsurePortIsUnoccupied keeps rejecting wildcards as before.
  • No stale-config risk. Tunnel reuse is keyed on the port/user/host spec, not the ssh argument string, so the changed arguments can't strand a stale listener; an upgrade leaves the app process with a fresh SshTunnelService, and any pre-existing port occupant is rejected by EnsurePortIsUnoccupied either way.
  • Tests updated, not just added. The three BuildArguments assertions were rewritten to the new exact string (they fail against the old builder), and the new ownership test covers IPv4 and IPv6 wildcards owned by the ssh process.

Validation re-run at this head

  • dotnet test ./tests/OpenClaw.Connection.Tests/OpenClaw.Connection.Tests.csproj --filter FullyQualifiedName~SshTunnelServiceTests: 23 passed, 0 failed (includes the new wildcard-rejection test).
  • dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj --filter FullyQualifiedName~SshTunnelCommandLineTests: 17 passed, 0 failed (includes the three rewritten assertions).

Notes on prior signals

  • ClawSweeper's platinum-hermit review and the live OpenSSH before/after in the PR body are consistent with what the code does; I have no finding to add.
  • On the NEEDS_HUMAN_TEST triage: this PR declares none for proof pools with a defensible reason (no named pool sets GatewayPorts or reads that listener), and live current-head listener evidence exists. I don't see a proof gap that should block merge; the risk: high classification reflects the severity of the exposure being fixed, not patch risk.
  • Out of scope by design (consistent with the PR contract): a user's own manual ssh -L forward or GatewayPorts on unrelated tools.

@larroy
larroy merged commit d0c8b32 into openclaw:main Oct 16, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants