feat: implement whitelist/blacklist enforcement (fixes #11)#22
feat: implement whitelist/blacklist enforcement (fixes #11)#22
Conversation
Code Review - Radagast 🧙♂️Overall: Clean security feature, well tested! What I like:✅ Blacklist > Whitelist precedence - Security best practice (deny overrides allow) Code review:// matchHost logic is solid:
// - '*' matches everything
// - '*.example.com' matches both 'sub.example.com' AND 'example.com' (apex)The apex domain matching ( One observation:The Verdict: Ship it! 🚀🔒 |
luthien-m
left a comment
There was a problem hiding this comment.
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.comfor subdomains - Subdomain handling:
*.example.commatches bothsub.example.comandexample.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
isHostAllowedfunction 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 🌙
luthien-m
left a comment
There was a problem hiding this comment.
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.
🌙
Adds host-based access control for relay connections.
Features
isHostAllowed()helper function (exported for testing)*matches all,*.domain.commatches subdomainsUsage
Tests
113 pass (99 original + 14 new whitelist/blacklist tests)
Fixes #11