fix(wizard): use Web Crypto (CSPRNG) for the gateway auth token#10
Open
kapelame wants to merge 1 commit into
Open
fix(wizard): use Web Crypto (CSPRNG) for the gateway auth token#10kapelame wants to merge 1 commit into
kapelame wants to merge 1 commit into
Conversation
SetupWizard generates the gateway auth token with 'Math.random().toString(36).slice(2) + Date.now().toString(36)'. Math.random() is a deterministic PRNG (V8 uses xorshift128+) and is not safe to derive auth secrets from — given a few outputs, the internal state can be recovered and subsequent outputs predicted. The Python installer at deployer/windows_setup.py:1601 already uses secrets.token_hex(24), so depending on which install path the user took the gateway ends up with very different token strength. This patch aligns the wizard path with the installer using crypto .randomUUID() (Web Crypto, CSPRNG) and strips the dashes so the output format matches the installer's hex string. The token is the bearer credential for the WebSocket handshake to the local OpenClaw Gateway (gateway-client.ts:305) and gates every RPC the desktop app issues, so the underlying entropy matters.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The first-launch SetupWizard generates the OpenClaw Gateway auth token using `Math.random()`. `Math.random()` is a deterministic PRNG (V8 uses xorshift128+ with public algorithm) and is not safe to derive auth secrets from — given a few outputs, internal state can be recovered and subsequent outputs predicted.
This is also internally inconsistent with the installer's path:
So the gateway's effective auth strength depends on which install path the user took, which is a real bug regardless of attacker model.
What the token actually protects
This isn't a throwaway request id — it's the bearer credential for the WebSocket handshake at `gateway-client.ts:305`:
```typescript
params.auth = { token: this.opts.token };
```
…and is read by `main.ts:1575` and used for every subsequent RPC. The OpenClaw Gateway exposes skill execution, file access, browser automation, and model invocation, so the token is real attack surface — local code (other user accounts on shared machines, or malware) that can fingerprint a few `Math.random()` outputs can predict the token and impersonate the desktop app to the local gateway.
Fix (one line)
```diff
```
Type of Change
Testing
Compatibility
Checklist