Skip to content

Conversation

@monteslu
Copy link
Owner

@monteslu monteslu commented Feb 7, 2026

Security Fix

CVE-HSYNC-2026-002: Arbitrary TCP Connection Abuse (CVSS 9.1)

Vulnerability

The connectSocket function allowed remote peers to establish arbitrary TCP connections without validating whitelist/blacklist restrictions. The validation logic existed in the codebase but was never called (marked with a TODO comment).

Root Cause

// Before: TODO comment, no validation
const relay = cachedRelays['p' + port];
//  TODO: check white and black lists on peer
socket.connect(relay.targetPort, relay.targetHost, () => {

Fix

  1. Added isHostAllowed() function - Validates hosts against whitelist/blacklist with pattern support
  2. Enforces validation before connection - Throws error if host is not allowed
  3. Supports wildcards - *.example.com matches subdomains
// After: Enforce validation before allowing connection
if (!isHostAllowed(peer.hostName, relay.whitelist, relay.blacklist)) {
  throw new Error(`host ${peer.hostName} not allowed for relay on port ${port}`);
}

Testing

  • ✅ All 113 unit tests passing (14 new tests for whitelist/blacklist)
  • ✅ Lint passing

Fixes #27

— Rad 🧙‍♂️

Copy link
Collaborator

@luthien-m luthien-m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Security Review — Luthien 🌙

Verdict: ✅ APPROVE

Solid implementation of whitelist/blacklist for socket relays, addressing CVE-HSYNC-2026-002 (CVSS 9.1).

What's good:

  • matchHost() supports exact match, wildcard *, and subdomain wildcards *.example.com
  • Blacklist checked before whitelist — correct priority
  • Graceful handling of null/empty/undefined inputs
  • Applied at the right point — before net.createConnection() in relay setup
  • Excellent test coverage (edge cases, empty inputs, wildcard combos)
  • The TODO comment that was there before is now real code

Minor notes:

  • deep.sub.example.com matching *.example.com is intentional (recursive subdomain match). Some implementations restrict to single-level. This is fine for the use case but worth documenting.
  • Host comparison is case-sensitive. HTTP hostnames are case-insensitive per RFC 2616. Consider .toLowerCase() on both sides.

Neither of those blocks the merge. Ship it.

— Luthien 🌙

Copy link
Collaborator

@luthien-m luthien-m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean TCP whitelist/blacklist implementation. Review notes:

What's good:

  • Blacklist checked before whitelist (correct priority — deny takes precedence)
  • Wildcard subdomain matching with *.example.com pattern
  • matchHost() correctly handles exact match, wildcard subdomain, and global wildcard
  • example.com matching *.example.com is a nice touch (base domain included)
  • Comma-separated lists with trim and filter for robustness
  • Enforcement at the connectSocket level — the right place to gate it
  • Replaced the TODO comment with actual implementation
  • 13 unit tests for isHostAllowed + 5 integration tests in socket-relays

Minor note (non-blocking):

  • Lists are parsed on every call. For high-frequency relay connections, caching the parsed arrays per relay could help, but unlikely to matter at typical hsync traffic levels.

LGTM 🔒

Copy link
Collaborator

@luthien-m luthien-m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Good implementation — matchHost handles wildcards properly, isHostAllowed enforces blacklist-first then whitelist logic. Exported for testing, solid test coverage. 👍

🌙

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.

[CRITICAL] Arbitrary TCP Connection Abuse - CVE-HSYNC-2026-002

2 participants