openclaw - ✅(Solved) Fix Bug: pre-auth device-signature verify allows CPU-amplification DoS without rate limit [1 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#77979Fetched 2026-05-06 06:18:24
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
2
Timeline (top)
cross-referenced ×2commented ×1

Fix Action

Fixed

PR fix notes

PR #77492: security fix(gateway): defend pre-auth device-signature verify against CPU DoS

Description (problem / solution / changelog)

Closes #77979

Summary

  • Pre-auth WS handshakes that include a device block ran crypto.createPublicKey plus a v3-then-v2 crypto.verify per request, gated only by frame-size limits. An unauthenticated remote attacker could pin a single Gateway core: PoC against a real running gateway hits ~510 forged handshakes/s/IP, degrading legit handshake p50 by 48.7× (1.16 ms → 56.6 ms) and p99 by 94.7×.
  • Fix is layered: schema cap on device.publicKey (1024) and device.signature (256); shape pre-check on verifyDeviceSignature / deriveDeviceIdFromPublicKey / normalizeDevicePublicKeyBase64Url rejecting inputs that cannot decode to a 32-byte raw key or 64-byte signature; new AUTH_RATE_LIMIT_SCOPE_DEVICE_SIGNATURE bucket gating the verify per IP. The browser-origin rate limiter is always constructed (server.impl.ts:424), so the gate fires for browser-origin clients even when no gateway.auth.rateLimit is configured. For non-browser-origin clients, the gate fires when the operator configures a rate limiter (the typical production case).
  • Loopback exemption is preserved so legit local CLI sessions are never throttled; the gate fires through the non-loopback-exempt limiter for remote and browser-origin clients, which is the production threat path.

Reproduction

The PoC (scripts/poc-preauth-flood-ws.mjs) opens N concurrent WS connections, each completing the connect-challenge handshake with a real Ed25519 PEM public key and a random 64-byte signature. The gateway reaches the verify path (server-issued nonce echoed back, device.id matches sha256(rawPublicKey)) and runs createPublicKey + v3 verify + v2 verify per request. A separate measurement client probes time-to-first-event in parallel.

Against a vulnerable gateway:

pnpm gateway:watch                                    # in another terminal

node scripts/poc-preauth-flood-ws.mjs \
     --gateway ws://127.0.0.1:18789 \
     --attackers 32 \
     --legit-iters 30 \
     --duration-ms 3000

Observed:

baseline:     n=30 p50=1.16ms  p90=1.80ms  p99=2.04ms
under-attack: n=30 p50=56.58ms p90=64.24ms p99=193.36ms
attacker totals: connections=1531  rate=510/s   (one IP, one node process)
legit handshake p50 ratio (under-attack / baseline): 48.69x
legit handshake p99 ratio: 94.73x

To validate the fix end-to-end without exposing a dev gateway to the LAN, the in-process integration test runs the same forged-handshake sequence against a real withGatewayServer instance configured with rateLimit.maxAttempts: 1, exemptLoopback: true:

pnpm test src/gateway/server.preauth-signature-rate-limit.test.ts

The test asserts:

  1. The first N forged signatures fail with error.details.reason === "device-signature" (the verify ran).
  2. The (N+1)th attempt fails with error.details.reason === "device-signature-rate-limited" and retryAfterMs > 0 — the gate short-circuited before any crypto.

Reverting the recordFailure line in the rate-limit gate makes both tests fail with expected 'device-signature' to be 'device-signature-rate-limited'.

Test plan

  • src/gateway/server.preauth-signature-rate-limit.test.ts — new in-process WS integration test (2 cases). Both fail when the fix is disabled.
  • src/infra/device-identity.test.ts — new shape pre-check tests: oversized PEM, oversized non-PEM, signature-shaped input rejected as public key, public-key-shaped input rejected as signature, all without invoking crypto.
  • src/gateway/protocol/connect-device-bounds.test.ts — new schema-cap tests: validateConnectParams rejects oversized device.publicKey and device.signature; accepts them at the documented bounds.
  • Existing src/gateway/server/ws-connection/handshake-auth-helpers.test.ts — 27/27 pass, no regression.
  • Live PoC reproduction confirms the 50× p50 / 95× p99 degradation pre-fix.

Verification

  • Targeted pnpm test of the four affected files: 41/41 pass.
  • Build: dist contains the new rate-limit gate (grep AUTH_RATE_LIMIT_SCOPE_DEVICE_SIGNATURE on the bundle).
  • Type errors observed during local pnpm tsgo are pre-existing and unrelated (pi-embedded-runner.* AgentMessage casts and missing web-tree-sitter dep).

Changed files

  • CHANGELOG.md (modified, +1/-0)
  • scripts/poc-preauth-flood-ws.mjs (added, +341/-0)
  • src/gateway/auth-rate-limit.ts (modified, +5/-0)
  • src/gateway/protocol/connect-device-bounds.test.ts (added, +63/-0)
  • src/gateway/protocol/schema/frames.ts (modified, +9/-3)
  • src/gateway/protocol/schema/primitives.ts (modified, +16/-0)
  • src/gateway/server.auth.browser-hardening.test.ts (modified, +12/-2)
  • src/gateway/server.auth.control-ui.suite.ts (modified, +12/-2)
  • src/gateway/server.preauth-signature-rate-limit.test.ts (added, +310/-0)
  • src/gateway/server/ws-connection/message-handler.ts (modified, +48/-1)
  • src/infra/device-identity.test.ts (modified, +73/-0)
  • src/infra/device-identity.ts (modified, +72/-3)
RAW_BUFFERClick to expand / collapse

Problem

The gateway's pre-auth device-signature verify path runs cryptographic verify work for every connect attempt, with no rate limit on the unauthenticated request stream. An attacker can amplify CPU use on the gateway by sending bogus signatures faster than legitimate clients, since each signature triggers expensive verify work before any auth bound is enforced.

Defense-in-depth fix: rate-limit pre-auth device-signature verify so an unauthenticated attacker cannot pin gateway CPU.

Tracking PR

Fix in #77492.

extent analysis

TL;DR

Implement rate-limiting on the pre-auth device-signature verification process to prevent CPU amplification attacks.

Guidance

  • Identify the current implementation of the pre-auth device-signature verification process and locate where rate-limiting can be applied.
  • Consider using a token bucket or leaky bucket algorithm to implement rate-limiting, allowing for a controlled number of verification requests within a given time frame.
  • Evaluate the optimal rate limit threshold to balance security with legitimate client connectivity, ensuring that the limit is low enough to prevent attacks but high enough to accommodate expected traffic.
  • Review the fix implemented in PR #77492 for guidance on how to apply rate-limiting to the pre-auth device-signature verification process.

Example

No code snippet is provided as the issue does not contain specific implementation details.

Notes

The effectiveness of this fix relies on accurately determining the optimal rate limit threshold, which may require monitoring and adjustment based on production traffic patterns.

Recommendation

Apply workaround: Implement rate-limiting on the pre-auth device-signature verification process, as described in the guidance section, to mitigate the CPU amplification attack vector until a more comprehensive fix can be applied.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix Bug: pre-auth device-signature verify allows CPU-amplification DoS without rate limit [1 pull requests, 1 comments, 2 participants]