Skip to content

Resolve Unsigned Authentication Bypass and Forgeable Sessions in agent-spend-permissions - #139

Open
mozluk wants to merge 1 commit into
base:masterfrom
mozluk:mozluk-patch-1
Open

Resolve Unsigned Authentication Bypass and Forgeable Sessions in agent-spend-permissions#139
mozluk wants to merge 1 commit into
base:masterfrom
mozluk:mozluk-patch-1

Conversation

@mozluk

@mozluk mozluk commented Sep 2, 2026

Copy link
Copy Markdown

Description

This pull request completely overhauls the session and authentication layer of agent-spend-permissions to close multiple critical and high-severity access control vulnerabilities (F-02, F-04)[cite: 30]. Previously, the application authorized mainnet USDC spending based on an unsigned, trivial-to-forge base64 session token, and verified SIWE signatures without asserting domain bindings or tracking nonces safely[cite: 30].

Key Changes & Remediations

1. Forgeable Session Mitigation (F-02)

  • Cryptographic Signatures: The application no longer relies on an unsigned Buffer.from("0xADDRESS:TIMESTAMP").toString('base64') cookie to authorize operations[cite: 30]. src/lib/session.ts now wraps payloads with a strict v1.<payload>.<mac> standard authenticated by a constant-time HMAC-SHA256 signature using a mandatory SESSION_SECRET[cite: 30].
  • Route Protection: All endpoints (/api/wallet/create, /api/search, /api/chat) that manipulate or spend on behalf of server wallets have been strictly transitioned to read exclusively from the new, signature-verified tokens[cite: 30].

2. SIWE Verification Hardening (F-04)

  • ERC-6492 / ERC-1271 Support: The verify route now utilizes viem's parseSiweMessage and verifySiweMessage rather than a weak regex match[cite: 30]. This fully supports Smart Wallet signature recovery while correctly checking issue/expiry timestamps[cite: 30].
  • Domain Binding: SIWE_DOMAIN enforcement (or Host header fallback) guarantees signatures obtained for other sites can no longer be replayed here[cite: 30].

3. Stateless Nonces & Memory Leak Prevention (F-04)

  • Self-Authenticating Nonces: Replaced the previous module-level Set<string> — which introduced severe memory leaks and erratic cross-instance sign-in failures — with stateless, HMAC-verified nonces that carry their own built-in uint32 expiry[cite: 30].
  • Safe Replay Bounds: Tracked nonces are opportunistically pruned and safely bounded to 10,000 concurrent uses to prevent memory exhaustion vectors.

…nt-spend-permissions`

### Description
This pull request completely overhauls the session and authentication layer of `agent-spend-permissions` to close multiple critical and high-severity access control vulnerabilities (F-02, F-04)[cite: 30]. Previously, the application authorized mainnet USDC spending based on an unsigned, trivial-to-forge base64 session token, and verified SIWE signatures without asserting domain bindings or tracking nonces safely[cite: 30].

### Key Changes & Remediations

#### 1. Forgeable Session Mitigation (F-02)
* **Cryptographic Signatures:** The application no longer relies on an unsigned `Buffer.from("0xADDRESS:TIMESTAMP").toString('base64')` cookie to authorize operations[cite: 30]. `src/lib/session.ts` now wraps payloads with a strict `v1.<payload>.<mac>` standard authenticated by a constant-time HMAC-SHA256 signature using a mandatory `SESSION_SECRET`[cite: 30].
* **Route Protection:** All endpoints (`/api/wallet/create`, `/api/search`, `/api/chat`) that manipulate or spend on behalf of server wallets have been strictly transitioned to read exclusively from the new, signature-verified tokens[cite: 30].

#### 2. SIWE Verification Hardening (F-04)
* **ERC-6492 / ERC-1271 Support:** The `verify` route now utilizes `viem`'s `parseSiweMessage` and `verifySiweMessage` rather than a weak regex match[cite: 30]. This fully supports Smart Wallet signature recovery while correctly checking issue/expiry timestamps[cite: 30].
* **Domain Binding:** `SIWE_DOMAIN` enforcement (or `Host` header fallback) guarantees signatures obtained for other sites can no longer be replayed here[cite: 30].

#### 3. Stateless Nonces & Memory Leak Prevention (F-04)
* **Self-Authenticating Nonces:** Replaced the previous module-level `Set<string>` — which introduced severe memory leaks and erratic cross-instance sign-in failures — with stateless, HMAC-verified nonces that carry their own built-in `uint32` expiry[cite: 30]. 
* **Safe Replay Bounds:** Tracked nonces are opportunistically pruned and safely bounded to `10,000` concurrent uses to prevent memory exhaustion vectors.
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