CashFusion-shaped covert sockets on a second listen
(CovertSubmitter: slots, spares, randTrap stagger) plus SOCKS5
CONNECT with unique per-connection credentials so Tor can isolate
circuits. No live Tor daemon, round driver, Chronik, or signing.
Details
- Reviewers
Fabien - Group Reviewers
Restricted Project - Commits
- rABCbe6500c061d8: [alp-fusion] Add covert-channel submitter and SOCKS5 Tor hook
- cd apps/alp-fusion && pnpm test
- Confirm covert tests submit CovertComponent on a second socket and dial through the mock SOCKS5 proxy with unique logins
Diff Detail
- Repository
- rABC Bitcoin ABC
- Lint
Lint Not Applicable - Unit
Tests Not Applicable
Event Timeline
Tail of the build log:
/work /work/abc-ci-builds/ai-review Connecting to CodeRabbit... 0s elapsed Preparing review... 1s elapsed ✗ Review limit reached Limit details: You’ve used all 5 included reviews currently available. Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. You're only billed for reviews past your plan's rate limits ($0.25/file). You can wait 11 minutes for the limit to reset. https://app.coderabbit.ai/settings/billing?tab=usage&orgId=79839cd4-7849-4bd5-8d6d-5ecaf453356e Build ai-review failed with exit code 1
Build Bitcoin ABC Diffs / Diff Testing (ai-review) passed.
CodeRabbit Review
Diff : committed changes only
Compare : HEAD → master
Directory : work
────────────────────────────────────────
(\(\
(• .•) Tabs or spaces? Yes.
────────────────────────────────────────────────────────────────────────
major [Stability & Availability]
→ ]8;;vscode://file//work/apps/alp-fusion/src/protocol/covert.ts:597apps/alp-fusion/src/protocol/covert.ts:597-598]8;;
Guard decodeMessage and onMessage inside the loop.
recvMessage and sendMessage are wrapped in try/catch, but
decodeMessage and onMessage are not. A remote peer that sends a frame
which is not a valid CovertMessage makes decodeMessage throw, and the
rejection escapes serveCovertPeer. Callers start the loop with `void
serveCovertPeer(...) (see test/protocol/covert.test.ts` lines 44 and
163), so the rejection is unhandled and terminates the Node process on the
default unhandledRejection policy. A throwing onMessage callback has
the same effect.
Close the connection and return instead.
🐛 Proposed fix
- const dec = decodeMessage(types.CovertMessage, raw);
- const result = onMessage(dec.field, dec.payload);
+ let result: { ok: true } | { ok: false; message: string };
+ try {
+ const dec = decodeMessage(types.CovertMessage, raw);
+ result = onMessage(dec.field, dec.payload);
+ } catch {
+ // Undecodable frame or handler fault: the stream cannot resync.
+ conn.close();
+ return;
+ }────────────────────────────────────────
Review complete
1 finding ✔
Major 1
11 files reviewed:
- apps/alp-fusion/DEPLOY.md
- apps/alp-fusion/README.md
- apps/alp-fusion/SPEC.md
- apps/alp-fusion/src/protocol/connection.ts
- apps/alp-fusion/src/protocol/constants.ts
- apps/alp-fusion/src/protocol/covert.ts
- apps/alp-fusion/src/protocol/messages.ts
- apps/alp-fusion/src/protocol/socks5.ts
- apps/alp-fusion/test/protocol/covert.test.ts
- apps/alp-fusion/test/protocol/helpers/mockSocks5.ts
... and 1 more file
────────────────────────────────────────
Print all AI prompts: coderabbit review --show-prompts
Guard serveCovertPeer decode/onMessage so a bad covert frame cannot unhandled-reject.
Build Bitcoin ABC Diffs / Diff Testing (ai-review) passed.
CodeRabbit Review
Diff : committed changes only
Compare : HEAD → master
Directory : work
────────────────────────────────────────
(\(\
(• .•) WMD: Weapons of Mass Debugging.
────────────────────────────────────────────────────────────────────────
major [Security & Privacy]
→ ]8;;vscode://file//work/apps/alp-fusion/src/protocol/covert.ts:216apps/alp-fusion/src/protocol/covert.ts:216]8;;
Use a CSPRNG for the covert timing stagger.
Math.random() is not cryptographically strong and its state is
recoverable from a few outputs. This rng feeds randTrap for both
connection times and per-socket submit delays, which is the timing defense
that stops a coordinator from joining covert sockets to a control session.
A predictable stagger weakens that defense. The module already imports
randomBytes.
🔒 Proposed fix
- this.rng = { random: () => Math.random() };
+ // Timing stagger is privacy-relevant: sample from a CSPRNG.
+ this.rng = { random: () => randomBytes(6).readUIntBE(0, 6) / 2 ** 48 };────────────────────────────────────────────────────────────────────────
minor [Maintainability & Code Quality] → ]8;;vscode://file//work/apps/alp-fusion/DEPLOY.md:85apps/alp-fusion/DEPLOY.md:85-87]8;; Correct the actor for the socks5 option. socks5 is a dial-side option. It exists on ConnectOptions and CovertSubmitterOptions, so only the connecting participant can use it. A coordinator operator cannot gain covert-channel privacy by setting socks5; the coordinator side needs an onion service or equivalent inbound path. State that participants point socks5 at the Tor SOCKS port when they connect to a public coordinator. 📝 Proposed wording - Covert/Tor is required before claiming CashFusion-class network privacy — plain TCP control channels are correctness-only. `CovertSubmitter` + - SOCKS5 are the hook; point `socks5` at a Tor SOCKS port (typically - `127.0.0.1:9050`) when running a public coordinator. + SOCKS5 are the hook; participants point `socks5` at a Tor SOCKS port + (typically `127.0.0.1:9050`) when they dial a public coordinator. The + coordinator side still needs an inbound Tor path (onion service).
────────────────────────────────────────────────────────────────────────
major [Stability & Availability]
→ ]8;;vscode://file//work/apps/alp-fusion/src/protocol/connection.ts:344apps/alp-fusion/src/protocol/connection.ts:344-355]8;;
Destroy the underlying socket when the TLS handshake fails.
wrapTls receives an already connected socket. On timeout it destroys
only tlsSock, and on 'error' it destroys nothing. The TCP socket (and
its SOCKS5/Tor circuit) then stays open after the promise rejects.
socks5Connect attaches a no-op 'error' handler to that socket, so the
leak is silent. CovertSubmitter.runConnection dials once per slot and
per spare, so repeated handshake failures accumulate open descriptors.
Destroy both sockets on every rejection path.
🔧 Proposed fix
const timer = setTimeout(() => {
tlsSock.destroy();
+ socket.destroy();
reject(new Error(`TLS connect timeout to ${host}`));
}, timeoutMs);
tlsSock.once('secureConnect', () => {
clearTimeout(timer);
resolve(new FusionConnection(tlsSock));
});
tlsSock.once('error', err => {
clearTimeout(timer);
+ tlsSock.destroy();
+ socket.destroy();
reject(err);
});────────────────────────────────────────────────────────────────────────
minor [Data Integrity & Integration]
→ ]8;;vscode://file//work/apps/alp-fusion/test/protocol/helpers/mockSocks5.ts:100apps/alp-fusion/test/protocol/helpers/mockSocks5.ts:100-101]8;;
Detach the handshake reader and flush its buffer before relaying.
socketReader keeps its 'data' listener attached for the socket
lifetime. Two effects follow:
1. Bytes that arrive in the same segment as the CONNECT request stay in
buf and are never written to dest, so a pipelined client loses data.
2. Every relayed byte is also appended to buf, which grows for the whole
connection.
The current tests wait for the CONNECT reply before sending, so case 1
does not trigger today. Detach and flush to keep the mock faithful.
🔧 Proposed fix
function socketReader(socket: Socket) {
let buf = Buffer.alloc(0);
const waiters = new Set<() => void>();
- socket.on('data', (chunk: Buffer) => {
+ const onData = (chunk: Buffer) => {
buf = Buffer.concat([buf, chunk]);
for (const w of [...waiters]) {
w();
}
- });
+ };
+ socket.on('data', onData);
return {
+ detach: () => {
+ socket.off('data', onData);
+ const rest = buf;
+ buf = Buffer.alloc(0);
+ return rest;
+ },
read: (n: number): Promise<Buffer> =>
Then hand the leftover bytes to the relay:
const dest = await tcpConnect(destHost, destPort);
socket.write(Buffer.from([0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0, 0]));
+ const leftover = reader.detach();
+ if (leftover.length > 0) {
+ dest.write(leftover);
+ }
dest.pipe(socket);
socket.pipe(dest);────────────────────────────────────────
Review complete
4 findings ✔
Major 2
Minor 2
11 files reviewed:
- apps/alp-fusion/DEPLOY.md
- apps/alp-fusion/README.md
- apps/alp-fusion/SPEC.md
- apps/alp-fusion/src/protocol/connection.ts
- apps/alp-fusion/src/protocol/constants.ts
- apps/alp-fusion/src/protocol/covert.ts
- apps/alp-fusion/src/protocol/messages.ts
- apps/alp-fusion/src/protocol/socks5.ts
- apps/alp-fusion/test/protocol/covert.test.ts
- apps/alp-fusion/test/protocol/helpers/mockSocks5.ts
... and 1 more file
────────────────────────────────────────
Print all AI prompts: coderabbit review --show-prompts
CSPRNG covert stagger, fail-close TLS-over-SOCKS sockets, fix DEPLOY socks5 actor, flush mock SOCKS leftover.
Build Bitcoin ABC Diffs / Diff Testing (ai-review) passed.
CodeRabbit Review
Diff : committed changes only
Compare : HEAD → master
Directory : work
────────────────────────────────────────
(\(\
(• .•) I love a good shortcut. This is a great shortcut to production incidents.
────────────────────────────────────────────────────────────────────────
minor [Stability & Availability]
→ ]8;;vscode://file//work/apps/alp-fusion/src/protocol/covert.ts:596apps/alp-fusion/src/protocol/covert.ts:596-602]8;;
Close the connection when recvMessage fails.
recvMessage() uses the FusionConnection default timeout of 120 s. When
it throws on timeout, the loop returns and leaves the socket open. No
reader stays attached, so the covert peer socket is never released. An
idle or slow client then holds a server socket for the lifetime of the
process. Callers use void serveCovertPeer(...), so no other code closes
it.
Close the connection on the read failure path.
🔒 Proposed fix
let raw: Buffer;
try {
raw = await conn.recvMessage();
} catch {
+ conn.close();
return;
}────────────────────────────────────────────────────────────────────────
major [Data Integrity & Integration] → ]8;;vscode://file//work/apps/alp-fusion/src/protocol/socks5.ts:76apps/alp-fusion/src/protocol/socks5.ts:76-84]8;; Preserve bytes received after a successful SOCKS5 CONNECT. When REP is 0x00, destination bytes may already be buffered when socks5Connect detaches the reader. The current branch rejects the tunnel and loses the buffered application data. Return the leftover bytes from detach() and prepend them to the paused socket before FusionConnection attaches its data listener. Add a test where the destination sends first.
────────────────────────────────────────
Review complete
2 findings ✔
Major 1
Minor 1
11 files reviewed:
- apps/alp-fusion/DEPLOY.md
- apps/alp-fusion/README.md
- apps/alp-fusion/SPEC.md
- apps/alp-fusion/src/protocol/connection.ts
- apps/alp-fusion/src/protocol/constants.ts
- apps/alp-fusion/src/protocol/covert.ts
- apps/alp-fusion/src/protocol/messages.ts
- apps/alp-fusion/src/protocol/socks5.ts
- apps/alp-fusion/test/protocol/covert.test.ts
- apps/alp-fusion/test/protocol/helpers/mockSocks5.ts
... and 1 more file
────────────────────────────────────────
Print all AI prompts: coderabbit review --show-prompts
Re-upload to re-run CI / CodeRabbit on the accepted stagger, TLS fail-close, DEPLOY, and mock-SOCKS fixes.
Build Bitcoin ABC Diffs / Diff Testing (ai-review) passed.
CodeRabbit Review
Diff : committed changes only
Compare : HEAD → master
Directory : work
────────────────────────────────────────
(\(\
(• .•) Abstraction is not about vagueness, it is about being precise at a new semantic level. - Edsger W. Dijkstra
────────────────────────────────────────────────────────────────────────
major [Stability & Availability]
→ ]8;;vscode://file//work/apps/alp-fusion/src/protocol/covert.ts:523apps/alp-fusion/src/protocol/covert.ts:523-525]8;;
Remove a dead spare from spareConnections.
reassignOrStop returns early when cov.slotNum === null. That path runs
for a spare connection, both when its connect fails (line 458) and when
its ping loop throws (line 514). The task then exits, but the spare stays
in this.spareConnections.
A later slot failure can pop() that dead spare. The slot then points to
a CovertConnection with connection === null and no running task, so
spare.wake.trigger() reaches no waiter. The slot never reconnects and
never submits, and waitUntilConnected / waitUntilDone fail on timeout
even when other live spares exist.
Drop the spare from the pool before returning.
🐛 Proposed fix
private reassignOrStop(cov: CovertConnection, err: Error): void {
const slotNum = cov.slotNum;
if (slotNum === null) {
+ // A spare whose task exited must not stay in the pool; a later
+ // pop() would hand a slot a connection with no running task.
+ const idx = this.spareConnections.indexOf(cov);
+ if (idx !== -1) {
+ this.spareConnections.splice(idx, 1);
+ }
return;
}────────────────────────────────────────
Review complete
1 finding ✔
Major 1
11 files reviewed:
- apps/alp-fusion/DEPLOY.md
- apps/alp-fusion/README.md
- apps/alp-fusion/SPEC.md
- apps/alp-fusion/src/protocol/connection.ts
- apps/alp-fusion/src/protocol/constants.ts
- apps/alp-fusion/src/protocol/covert.ts
- apps/alp-fusion/src/protocol/messages.ts
- apps/alp-fusion/src/protocol/socks5.ts
- apps/alp-fusion/test/protocol/covert.test.ts
- apps/alp-fusion/test/protocol/helpers/mockSocks5.ts
... and 1 more file
────────────────────────────────────────
Print all AI prompts: coderabbit review --show-prompts
Drop a dead spare from spareConnections so a later slot failure cannot inherit a connection with no running task.
Build Bitcoin ABC Diffs / Diff Testing (ai-review) passed.
CodeRabbit Review
Diff : committed changes only
Compare : HEAD → master
Directory : work
────────────────────────────────────────
(\(\
(• .•) torvalds@linux:~$ git review
────────────────────────────────────────
Review complete
No findings ✔
11 files reviewed:
- apps/alp-fusion/DEPLOY.md
- apps/alp-fusion/README.md
- apps/alp-fusion/SPEC.md
- apps/alp-fusion/src/protocol/connection.ts
- apps/alp-fusion/src/protocol/constants.ts
- apps/alp-fusion/src/protocol/covert.ts
- apps/alp-fusion/src/protocol/messages.ts
- apps/alp-fusion/src/protocol/socks5.ts
- apps/alp-fusion/test/protocol/covert.test.ts
- apps/alp-fusion/test/protocol/helpers/mockSocks5.ts
... and 1 more file
────────────────────────────────────────
| apps/alp-fusion/src/protocol/socks5.ts | ||
|---|---|---|
| 236 ↗ | (On Diff #61040) | I'm sure Node has built-in libs to parse IP addresses, this will let you check for invalid ipv4 and maybe even support ipv6 ? It's 2026 after all |
Build Bitcoin ABC Diffs / Diff Testing (ai-review) passed.
CodeRabbit Review
Diff : committed changes only
Compare : HEAD → master
Directory : work
────────────────────────────────────────
(\(\
(• .•) Crouching Tiger, Hidden NullPointerException.
────────────────────────────────────────────────────────────────────────
minor [Stability & Availability]
→ ]8;;vscode://file//work/apps/alp-fusion/src/protocol/covert.ts:604apps/alp-fusion/src/protocol/covert.ts:604-608]8;;
Close the socket when recvMessage fails.
recvMessage() uses the default 120 s timeout. If a covert peer connects
and then stays silent, recvMessage rejects with `Timed out waiting for
message`, this loop returns, and the socket stays open with no reader. The
coordinator then holds one idle file descriptor per abandoned covert
socket. Close the connection on the failure path.
🔧 Proposed fix
try {
raw = await conn.recvMessage();
} catch {
+ conn.close();
return;
}────────────────────────────────────────────────────────────────────────
minor [Functional Correctness]
→ ]8;;vscode://file//work/apps/alp-fusion/src/protocol/socks5.ts:234apps/alp-fusion/src/protocol/socks5.ts:234-237]8;;
Reject non-ASCII destination hostnames instead of encoding them lossily.
Buffer.from(host, 'ascii') keeps only the low byte of each code unit. A
hostname with non-ASCII characters is silently mangled, and the proxy
receives a different name than the caller requested. The length check does
not detect this. Validate the characters, or convert the name with
domainToASCII before encoding.
🔧 Proposed fix
- const name = Buffer.from(host, 'ascii');
+ const ascii = domainToASCII(host) || host;
+ if (!/^[\x21-\x7e]+$/.test(ascii)) {
+ throw new Error('SOCKS5: dest host must be printable ASCII');
+ }
+ const name = Buffer.from(ascii, 'ascii');
if (name.length === 0 || name.length > 255) {
throw new Error('SOCKS5: dest host must be 1..255 ASCII bytes');
}
Add the import:
import { domainToASCII } from 'node:url';────────────────────────────────────────
Review complete
2 findings ✔
Minor 2
11 files reviewed:
- apps/alp-fusion/DEPLOY.md
- apps/alp-fusion/README.md
- apps/alp-fusion/SPEC.md
- apps/alp-fusion/src/protocol/connection.ts
- apps/alp-fusion/src/protocol/constants.ts
- apps/alp-fusion/src/protocol/covert.ts
- apps/alp-fusion/src/protocol/messages.ts
- apps/alp-fusion/src/protocol/socks5.ts
- apps/alp-fusion/test/protocol/covert.test.ts
- apps/alp-fusion/test/protocol/helpers/mockSocks5.ts
... and 1 more file
────────────────────────────────────────
Print all AI prompts: coderabbit review --show-prompts
CodeRabbit on Diff 61092: taking the serveCovertPeer recvMessage-timeout close (and the matching sendMessage fail path). Skipping the domainToASCII / reject-non-ASCII dest-host change: Buffer.from(host, "ascii") is lossy, but this hook only dials onion, IPv4, or IPv6 — all already ASCII or handled by isIPv4/isIPv6. Not worth punycode here.
Build Bitcoin ABC Diffs / Diff Testing (ai-review) passed.
CodeRabbit Review
Diff : committed changes only
Compare : HEAD → master
Directory : work
────────────────────────────────────────
(\(\
(• .•) Please step away from the keyboard!
────────────────────────────────────────────────────────────────────────
major [Data Integrity & Integration] → ]8;;vscode://file//work/apps/alp-fusion/src/protocol/socks5.ts:74apps/alp-fusion/src/protocol/socks5.ts:74-82]8;; Preserve buffered destination bytes after SOCKS5 CONNECT. A successful CONNECT reply can share a socket chunk with destination data. reader.detach() leaves those bytes in its private buffer, and lines 74–82 reject the tunnel instead of handing them to FusionConnection. Return the buffer from detach() and call socket.unshift(leftover) before handoff. Add a test where the destination sends first.
────────────────────────────────────────
Review complete
1 finding ✔
Major 1
11 files reviewed:
- apps/alp-fusion/DEPLOY.md
- apps/alp-fusion/README.md
- apps/alp-fusion/SPEC.md
- apps/alp-fusion/src/protocol/connection.ts
- apps/alp-fusion/src/protocol/constants.ts
- apps/alp-fusion/src/protocol/covert.ts
- apps/alp-fusion/src/protocol/messages.ts
- apps/alp-fusion/src/protocol/socks5.ts
- apps/alp-fusion/test/protocol/covert.test.ts
- apps/alp-fusion/test/protocol/helpers/mockSocks5.ts
... and 1 more file
────────────────────────────────────────
Print all AI prompts: coderabbit review --show-prompts