# Enrolling to a CA that returns an empty response crashes the node process

Malicious CA returning empty enrollment response triggers uncaught EventEmitter error in fabric-ca-node SDK, crashing the host Node.js process.

- Payout: $500
- Severity: medium
- Program: Linux Foundation Decentralized Trust
- Found by: mttrbrts
- Disclosed: 2022-08-06
- Write-up quality: 6/10
- Original: https://hackerone.com/reports/506412
- Library page: https://bugbountylibrary.com/r/h1%3A506412
- Tags: area:oss domain:oss impact:dos kind:bounty platform:hackerone sev:medium tech:nodejs technique:source-review vuln:dos

**Target:** hyperledger/fabric-sdk-node fabric-ca-client enrollment HTTP handler
**Root cause:** Error path calls JSON.parse(data) on an empty response body inside an EventEmitter 'end' handler; the thrown exception is uncaught because no 'error' listener exists, terminating the process.
**Steps:**
1. Run malicious CA server (`node badCa.js`) that returns empty body on enrollment endpoint.
2. Run client (`node index.js`) using fabric-ca-client to enroll against that CA.
3. SDK receives empty response, `end` handler runs `JSON.parse(data)` on empty string, throws.
4. Uncaught exception in EventEmitter crashes the Node process; client cannot catch it.
**How found:** Noticed the error path used `JSON.parse(data)` on the response body rather than `response.statusCode`; reasoned that an empty body would throw inside an EventEmitter 'end' callback where the exception is uncaught, then built a malicious CA to confirm.
**Exploitation:** Attacker controls or MITMs the CA endpoint; returns empty HTTP body during enrollment. SDK's response 'end' handler parses empty body, throws inside EventEmitter with no error listener, killing the process. Repeated requests deny service to server-side apps using the SDK.
**Insight:** In Node SDKs, exceptions thrown inside EventEmitter 'end'/'data' callbacks are uncaught and kill the process — audit response handlers that JSON.parse attacker-controlled bodies without try/catch or an 'error' listener.

## Proof of concept (copied exactly from the original report)

**Commands to run malicious CA and client**

```
npm install
node badCa.js &
node index.js
```

