openclaw-windows-node icon indicating copy to clipboard operation
openclaw-windows-node copied to clipboard

[deep-review] C10: v3→v2 signature fallback is sticky-permanent (downgrade attack)

Open codemonkeychris opened this issue 6 months ago • 3 comments

Summary

The connect handshake supports both v3 and v2 device-identity signature payloads. The client attempts v3; if the gateway responds with code: "DEVICE_AUTH_SIGNATURE_INVALID" or an error containing "device signature invalid", the client flips an instance flag (_useV2Signature = true) and retries with v2 on the next reconnect. The flag is never reset to false. Once tripped, the client uses v2 forever for that session.

_useV2Signature is also persisted across reconnects in GatewayConnectionManager._gatewayNeedsV2Signature (per-gateway, in-memory only; cleared on process exit).

Where

  • src/OpenClaw.Shared/OpenClawGatewayClient.cs:51, 881-899, 1494-1499 (operator)
  • src/OpenClaw.Shared/WindowsNodeClient.cs:37, 568-575, 828-830 (node)
  • Per-gateway persistence: src/OpenClaw.Tray.WinUI/Services/Connection/GatewayConnectionManager.cs:32, 234-237, 240-241

Why it matters

A MITM (or briefly-compromised) gateway can return DEVICE_AUTH_SIGNATURE_INVALID once. After that the client uses v2 even after the gateway is back to normal v3 operation. v2 drops platform and deviceFamily from the signature payload — narrower attack surface for the signature, but also narrower binding to the client. The downgrade itself is the attack: a permanent signature-payload downgrade weakens the per-session binding.

This is the same shape as the well-known v3-to-v2 protocol downgrade attacks (TLS, OAuth, etc.).

Proposed fix

  • After N (suggest 3) consecutive successful v2 handshakes, attempt v3 on the next reconnect. If v3 succeeds, clear the flag. If v3 fails again with DEVICE_AUTH_SIGNATURE_INVALID, stay on v2 and double N for the next probe (exponential backoff).
  • Alternatively, attempt v3 on every reconnect that follows a process restart. v2 should be a runtime fallback within a session, not a sticky setting.
  • Add a diagnostic counter so operators can see "this gateway is forcing v2" in the Connection Status window.

Severity

High — protocol downgrade attack.

codemonkeychris avatar May 13 '26 23:05 codemonkeychris


[!WARNING] The create_pull_request operation failed: Failed to apply bundle. The code changes were not applied.

🤖 This is an automated response from Repo Assist.

I've verified the issue against the current codebase. Here's the precise picture:

Current state (confirmed):

  • OpenClawGatewayClient._useV2Signature (line 51) and WindowsNodeClient._useV2Signature (line 37): per-instance flag, never reset to false once tripped.
  • GatewayConnectionManager._gatewayNeedsV2Signature (line 32): in-memory per-gateway persistence; propagated to new client instances at reconnect (line 241), and passed via useV2Signature: parameter (line 610). Cleared only when a new gateway URL is set (lines 318, 349), not on successful v2 handshakes.

So the sticky window is: within a single app session, once a gateway trips the v2 flag, all subsequent reconnects to that gateway use v2 — permanently, without any probe for v3 recovery.

Simplest effective fix (aligns with the "process-restart semantics" alternative in the issue):

In GatewayConnectionManager, count consecutive successful v2 handshakes. After N successes (suggest 5), attempt v3 on the next reconnect. If v3 succeeds, clear _gatewayNeedsV2Signature; if it fails with DEVICE_AUTH_SIGNATURE_INVALID again, stay v2 and reset the counter with exponential backoff.

This requires wiring a "handshake succeeded with v2" notification from OpenClawGatewayClient/WindowsNodeClient back to GatewayConnectionManager. The existing Connected event could carry a bool usedV2Signature payload, or a dedicated event could be added.

I don't have a PR ready for this (the protocol-level change is more invasive), but happy to work on it if it's prioritised.

Generated by 🌈 Repo Assist, see workflow run. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@97143ac59cb3a13ef2a77581f929f06719c7402a

github-actions[bot] avatar May 14 '26 19:05 github-actions[bot]

🤖 This is an automated response from Repo Assist.

I've created a draft PR implementing the exponential-backoff v3 probe approach described in this issue.

Implementation:

  • Added _v2SuccessCount, _v2ProbeThreshold (default 3), and _v3ProbeActive to GatewayConnectionManager
  • After 3 consecutive successful v2 handshakes, the next reconnect probes v3 (UseV2Signature = false)
  • If v3 is rejected again, the threshold doubles (3 → 6 → 12 ... capped at 96) — exponential backoff
  • A _v3ProbeActive flag distinguishes the initial v3→v2 fallback from a probe failure, ensuring the threshold only doubles on actual probe rejections (not the first fallback)
  • Gateway switch or new-gateway setup resets all state
  • 4 new unit tests covering all paths

Note: PR #400 (by Copilot) also addresses this issue — the maintainer may want to compare approaches before merging.

Generated by 🌈 Repo Assist, see workflow run. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@97143ac59cb3a13ef2a77581f929f06719c7402a

github-actions[bot] avatar May 15 '26 13:05 github-actions[bot]

Closing this one-off deep-review issue as consolidated, not necessarily fixed. The useful signal is preserved in #372: v3→v2 fallback is still useful security signal, but stale generated PRs were closed. We will take these one at a time from #372 after verifying against current master instead of keeping the issue list flooded.

shanselman avatar May 18 '26 00:05 shanselman