Repository navigation
fix(notify): accept wallet ECDSA_HASH160 keys on signed requests - #659
Conversation
Dash wallets grant the browser an AUTHENTICATION/HIGH ECDSA_HASH160 key through App Connect, whose on-chain data is only the hash160 of the public key. forge-notify accepted ECDSA_SECP256K1 keys only, so a user signed in with a wallet could not change email or push settings. The envelope takes an optional public_key (base64, 33-byte compressed). An ECDSA_HASH160 key verifies only when it is sent and hashes to the key's data; an ECDSA_SECP256K1 key keeps working without it and refuses one that is not its data. The web client records the session key's type and sends public_key only for an ECDSA_HASH160 key, so services from before this change, which refuse unknown fields, keep accepting every key they did. serviceKey() also names a pasted key by its on-chain id instead of -1. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 9 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
PastaPastaPasta
left a comment
There was a problem hiding this comment.
Verdict: approve
Security review of head 9b2eacf (services/forge-notify/src/auth.rs, forge-web/lib/notify/client.ts, forge-web/lib/auth/controller.ts, docs).
Key binding: sound. public_key sits outside the signed bytes, and that is fine here. To be accepted it must hash160 to the key data read from Platform with proofs, and the signature must verify under it. If an attacker could choose a public_key for someone else's HASH160 key, they would need a RIPEMD160(SHA256) second preimage plus a valid signature under that key. ECDSA public-key recovery only yields keys tied to some signature, not keys that hash to a chosen value. Only 33-byte input is accepted, and a secp256k1 point has exactly one compressed encoding, so there is no alternate encoding of the same point that hashes differently. Stripping or swapping the field in transit makes the request fail and nothing worse. Putting it inside the signed bytes would add nothing.
Key validity and type: sound.
usable_signing_keystill requires the key to be enabled,AUTHENTICATION,HIGH/CRITICALand Forge-bounded, now for both types. MASTER HASH160 is refused (tested).- Other types are refused before
signing_public_keyruns: BLS,EDDSA_25519_HASH160,BIP13_SCRIPT_HASH. - A SECP256K1 key with a
public_keymust byte-equal the key data, so a SECP key plus a bogus key is refused (tested). - A HASH160 key with no
public_keyis refused (tested). - The
"ECDSA_HASH160"string matches forge-core'sKeyTypemapping (platform/mod.rs:412).
Compatibility and replay: unchanged.
#[serde(default)]keeps old two-field envelopes parsing, anddeny_unknown_fieldsis kept (tested).- The web client sends
public_keyonly for type 2, so SECP sessions send the exact same body to pre-change services. - The nonce is still consumed in
api.rsafterverify, keyed byidentity:nonce. A replay with a differentpublic_keyhits the same nonce.
Parsing: sound.
- Base64 is strict STANDARD.
PublicKey::from_sliceplus the explicitlen == 33check refuse uncompressed and hybrid encodings (uncompressed is tested).- The input is parsed before any Platform read, so garbage costs no network work.
Findings (non-blocking):
- Pre-existing, now more exposed: key expiry. The service still does not check a key's
expiresAt, even though consensus refuses expired keys and the web'sfindSigningKeyskips them (forge-web/lib/sdk/write.ts:130). Wallet App Connect grants are exactly the keys that tend to carry an expiry. So this PR widens the existing gap: an expired wallet grant that is still enabled could keep signing notify requests until someone disables it. This doesn't block the PR, but the expiry follow-up should land soon.IdentityKeyInfowould need to carryexpires_atfrom the proof read. - Nit: a HASH160 key is only accepted when its hash is of the compressed public key. That matches DashPay wallets and fails closed otherwise, so it's fine. It could get one line in
service-auth.md, which already says "33-byte compressed". - Nit, web:
serviceKey()now names a pasted key (keyId: -1) by the id found on chain. That is a real fix bundled in, andservice-key.test.tscovers it.
Tests run locally
cargo test -p forge-notify: 31/31 pass (28 lib, including the 4 new auth tests, plus 3 integration).vitest run lib/notify/client.test.ts lib/auth/service-key.test.ts: 9/9 pass.
Negative cases covered: wrong public key, right public key with someone else's signature, missing public key, uncompressed, non-base64, MASTER level, SECP plus a foreign key, and an unknown publicKey field.
🤖 Posted autonomously by Claude (claude-opus-5-5) on behalf of pasta.
Problem
Released Dash wallets (for example DashPay Android 11.9.2 over App Connect v2) give the browser an AUTHENTICATION/HIGH key of type ECDSA_HASH160. On chain, that key stores only hash160(compressed pubkey). forge-notify accepted only
ECDSA_SECP256K1keys and checked signatures against the on-chain data as if it were a full public key. So anyone signed in with a wallet got "key N cannot sign service requests" in the notify panel and couldn't set up email or push. This blocks making wallet sign-in the primary sign-in (docs/design/wallet-primary.md).Fix
src/auth.rs):SignedEnvelopetakes an optionalpublic_keyfield (base64, 33-byte compressed key), anddeny_unknown_fieldsstays.ECDSA_HASH160AUTHENTICATION key verifies only ifpublic_keyis present, parses as a compressed secp256k1 key, and hashes to the key's data. The signature is then checked against that key.ECDSA_SECP256K1key works as before. If it sendspublic_key, the value must equal the key's data or the request is refused.public_keyis refused before the Platform key read.examples/request.rs): sendspublic_keywhen the identity-file entry'skeyTypeisECDSA_HASH160.AuthSessionnow records the signing key'skeyType, read from the on-chain key when the session opens.serviceKey()returns that key type only while the session is still on the stored key.signEnvelopeaddspublic_keyonly for anECDSA_HASH160key.serviceKey()also used to send a pasted raw key's id as-1. It now uses the key id found on chain.docs/design/service-auth.mddocuments the new field.docs/design/wallet-primary.mdno longer says notify already accepts wallet keys.Deploy notes
public_keyonly for HASH160 keys, and old servers never accepted those. Every key that works on an old server today keeps working, with the same envelope as before.Follow-up (not in this PR)
forge-notify doesn't check key expiry.
IdentityKeyInfohas noexpires_at, so a key that expired on Platform but was never disabled can still sign service requests. This was already true for limited SECP keys. It matters more now that wallet grants, which always expire, go through this path. The fix would be to exposeexpires_at(key_limitsalready reads it) and refuse expired keys.Tests
cargo test -p forge-notify: new auth tests cover a HASH160 key with the right pubkey, and refusal with a missing pubkey, a pubkey whose hash doesn't match, a pubkey the signature doesn't verify against, an uncompressed or non-base64 pubkey, and a MASTER-level key. Also covered: a SECP256K1 key with a mismatchingpublic_key, serde (public_keyaccepted,publicKeyrefused), and a hash160 vector.cargo clippy -p forge-notify --all-targets -D warningsis clean.lib/notify/client.test.tschecks that a SECP256K1 envelope stays exactly{request, signature}, and that a HASH160 envelope carries a pubkey that verifies.lib/auth/service-key.test.tschecks that the key type is carried, that a pasted key gets its on-chain id, and that the type is dropped after a renewal stores a new key.vitest lib/auth lib/notify components/notify: 537 passed.tsc --noEmit, eslint andlint:copyare clean.🤖 Generated with Claude Code