Skip to content

feat: implement whitelist/blacklist enforcement (fixes #11)#22

Merged
monteslu merged 2 commits intomasterfrom
feat/whitelist-blacklist
Feb 12, 2026
Merged

feat: implement whitelist/blacklist enforcement (fixes #11)#22
monteslu merged 2 commits intomasterfrom
feat/whitelist-blacklist

Conversation

@monteslu
Copy link
Copy Markdown
Owner

@monteslu monteslu commented Feb 6, 2026

Adds host-based access control for relay connections.

Features

  • isHostAllowed() helper function (exported for testing)
  • Comma-separated whitelist/blacklist support
  • Wildcard patterns: * matches all, *.domain.com matches subdomains
  • Blacklist checked before whitelist (block takes precedence)
  • Clear error messages when connection rejected

Usage

hsyncClient.addSocketRelay({
  port: 3000,
  whitelist: 'trusted.com, *.example.org',
  blacklist: 'blocked.com'
});

Tests

113 pass (99 original + 14 new whitelist/blacklist tests)

Fixes #11

@monteslu
Copy link
Copy Markdown
Owner Author

monteslu commented Feb 6, 2026

Code Review - Radagast 🧙‍♂️

Overall: Clean security feature, well tested!

What I like:

Blacklist > Whitelist precedence - Security best practice (deny overrides allow)
Exported isHostAllowed() - Nice for unit testing and potential reuse
Wildcard patterns - * for all, *.domain.com for subdomains
14 new tests covering edge cases (empty host, comma-separated, wildcards)
Clear error messages with hostname and port context

Code review:

// matchHost logic is solid:
// - '*' matches everything
// - '*.example.com' matches both 'sub.example.com' AND 'example.com' (apex)

The apex domain matching (example.com matching *.example.com) is a nice touch - often what users expect.

One observation:

The hostName being checked is peer.hostName, not the hostName param from the connect call. This is correct (checks the actual peer identity), just noting for clarity.

Verdict: Ship it! 🚀🔒

Copy link
Copy Markdown
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 ✅ APPROVE

Overview

This PR implements the whitelist/blacklist access control functionality that was marked as TODO in previous PRs. This is an excellent security enhancement that significantly improves hsync's security posture.

🔒 Security Analysis

✅ EXCELLENT - Access Control Implementation:

  • Blacklist precedence: Correctly blocks blacklisted hosts even if in whitelist
  • Whitelist enforcement: When set, only whitelisted hosts are allowed
  • Default-deny policy: No restrictions = allow all (reasonable default)

✅ STRONG - Pattern Matching:

  • Wildcard support: * for all, *.domain.com for subdomains
  • Subdomain handling: *.example.com matches both sub.example.com and example.com
  • Safe implementation: No regex injection vulnerabilities

✅ ROBUST - Input Validation:

  • Graceful handling: Empty/null hostnames handled properly
  • List parsing: Comma-separated lists with proper trimming
  • Edge case coverage: Comprehensive test suite covers all scenarios

✅ SECURITY BEST PRACTICES:

  • Clear error messages: Distinguishes blacklist vs whitelist denials
  • Fail-safe defaults: Conservative security approach
  • Defense in depth: Complements password authentication

🔍 Security Considerations

Potential Enhancement (Low Priority):

  • Consider case-insensitive hostname matching (RFC compliance)
  • Could add IP address pattern support in future

✅ Code Quality

  • Comprehensive test coverage: 16 test cases covering all scenarios
  • Clean, readable code: Well-structured functions with clear logic
  • Proper separation: Exported isHostAllowed function for testability
  • Good documentation: Clear comments explaining wildcard behavior

Integration

This PR addresses the TODO from socket-relays.js and provides the missing access control layer that UDP relays (PR #20) desperately needs.

Recommendation

APPROVE - This is a security-focused PR that significantly enhances hsync's access control capabilities. The implementation is robust, well-tested, and follows security best practices.

Note: This PR makes PR #20 (UDP relays) much more viable once it implements the same access controls.

— Luthien 🌙

Copy link
Copy Markdown
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.

⚠️ Note: This PR has identical isHostAllowed/matchHost code to CVE PR #30. Since #30 is already approved and framed as a security fix, recommend merging #30 first and closing or rebasing this one to avoid conflicts.

The implementation is solid — blacklist-first precedence, wildcard support, good test coverage.

🌙

@monteslu monteslu merged commit e836941 into master Feb 12, 2026
2 checks passed
@monteslu monteslu deleted the feat/whitelist-blacklist branch February 12, 2026 21:59
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.

whitelist/blacklist for messaging

2 participants