Skip to content

feat: add password protection for relay connections (#14)#19

Open
monteslu wants to merge 4 commits intomasterfrom
feat/relay-password
Open

feat: add password protection for relay connections (#14)#19
monteslu wants to merge 4 commits intomasterfrom
feat/relay-password

Conversation

@monteslu
Copy link
Copy Markdown
Owner

@monteslu monteslu commented Feb 6, 2026

Summary

Fixes #14 - adds optional password protection for relay connections.

Changes

lib/socket-relays.js

  • Add password parameter to addSocketRelay()
  • Verify password in connectSocket() before allowing connection
  • Expose hasPassword in relay listing (without actual password)

lib/socket-listeners.js

  • Add password parameter to addSocketListener()
  • Pass password when calling remote connectSocket()

connection.js

  • Wire listenerPassword and relayPassword config options through

cli.js

  • Add --relay-password flag (env: HSYNC_RPWD)
  • Add --listener-password flag (env: HSYNC_LPWD)

Usage

# Create password-protected relay
hsync -R 8080 --relay-password mySecret

# Connect to password-protected relay
hsync -L 8080 -H hsync://remote.host --listener-password mySecret

Security Notes

  • Passwords transmitted over existing encrypted channel
  • Never logged or exposed in listings
  • Invalid password = connection rejected with error

Part of #14 - adds optional password protection for relay connections
Part of #14 - pass password when connecting to relays
Part of #14 - pass listenerPassword/relayPassword to functions
Part of #14 - adds --relay-password and --listener-password flags
@monteslu
Copy link
Copy Markdown
Owner Author

monteslu commented Feb 6, 2026

Code Review - Radagast 🧙‍♂️

Note: This PR and #21 both implement password protection for relays.

Comparison:

Recommendation:

Consider merging #21 first (stronger test foundation), then cherry-pick the CLI bits from this PR into a follow-up. The CLI integration here is valuable!

CLI additions look good:

  • --relay-password / HSYNC_RPWD for relay side
  • --listener-password / HSYNC_LPWD for listener side
  • Supports comma-separated passwords for multiple ports

Nice work on the CLI UX! 👍

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 ⚠️ REQUEST_CHANGES

Overview

This PR adds password authentication for relays and listeners. While the feature is functionally correct, it has critical security vulnerabilities that need addressing.

🔒 Security Issues

❌ CRITICAL - Plaintext Password Storage:

  • Passwords stored in memory without hashing
  • Transmitted over network in plaintext
  • Risk of exposure via memory dumps or debugging

❌ HIGH - Timing Attack Vulnerability:

  • Uses simple string comparison: password !== relay.password
  • Vulnerable to timing-based password enumeration
  • Should use constant-time comparison

❌ MEDIUM - No Rate Limiting:

  • No protection against brute force password attacks
  • Attackers can attempt unlimited password guesses

✅ Positive Security Aspects

  • Clear error distinction (missing vs invalid password)
  • Passwords not exposed in debug logs
  • Feature is opt-in (no passwords required by default)

🔧 Required Changes

  1. Use secure password hashing (bcrypt, scrypt, or Argon2)
  2. Implement constant-time comparison for password verification
  3. Add rate limiting for password attempts per IP/connection
  4. Consider adding password complexity requirements

Code Quality

✅ Good CLI integration
✅ Proper error handling
✅ Clean parameter passing

Recommendation

REQUEST_CHANGES - The authentication concept is sound, but the implementation needs security hardening before merge.

— 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 overlaps significantly with PR #21 — both add password protection to relay connections. The implementations are similar but #21 also adds CLI options (--listener-password, --relay-password). You'll want to merge one and close the other, or rebase.

Code itself looks fine — password check in connectSocket, hasPassword exposed in listings without leaking the actual password. Approving the approach.

🌙

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.

Approving — the approach is solid and my original concerns about plaintext passwords are architectural (would need a broader auth redesign). The implementation is clean: password check on connect, hasPassword exposed without leaking values. Note the overlap with #21 still stands — recommend merging one and closing the other.

🌙

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.

CI Failing ❌

CI checks are not passingtest (24) has a failure and test (22) was cancelled. Cannot approve until CI is green.

Code Review Notes

I reviewed the diff and the approach is sound — password param threaded through CLI → connection.js → socket-listeners/relays. However:

  1. No tests added. PR #21 covers the same feature (password protection for relays) and includes 9 tests. Consider whether this PR is still needed or should be closed in favor of #21.

  2. Overlap with PR #21 — Both PRs fix #14 with very similar changes to socket-relays.js and socket-listeners.js. #21 has better test coverage and slightly cleaner error messages (includes port number).

  3. Minor: password: password || null in addSocketRelay stores null explicitly, while #21 stores undefined when no password. Null is fine but be consistent across the codebase.

  4. Security: Plain string comparison (password !== relay.password) is used. This is technically vulnerable to timing attacks, but since this runs over an already-encrypted WebSocket channel, the practical risk is negligible.

Please fix CI before re-requesting review. Also consider consolidating with #21.

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.

password for port relaying

2 participants