security: harden WhatsApp gateway — bearer auth, CORS, error redaction, PII logs#1246
Open
BunnyMoth wants to merge 2 commits into
Open
security: harden WhatsApp gateway — bearer auth, CORS, error redaction, PII logs#1246BunnyMoth wants to merge 2 commits into
BunnyMoth wants to merge 2 commits into
Conversation
…, PII logs, QR cleanup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Security hardening for the WhatsApp gateway (
packages/whatsapp-gateway/).The gateway is a separate Node.js process that does not inherit any of the
Rust-side security layers.
Changes
Bearer token authentication on all endpoints
All endpoints (
/login/start,/login/status,/message/send,/health)now require
Authorization: Bearer <token>. Token is generated at startupvia
crypto.randomBytes(32), logged once to stdout for the Rust kernel tocapture, and validated with
timingSafeEqualto prevent timing attacks.Removed Access-Control-Allow-Origin: *
This is a localhost service-to-service API, not a browser-facing one.
The wildcard CORS header allowed any webpage to send WhatsApp messages
as the linked account (localhost-CSRF vector). Removed entirely.
auth_store directory permissions
fs.chmodSync(authDir, 0o700)applied afteruseMultiFileAuthStatecreates the directory (Linux/Mac only, guarded by
process.platform !== 'win32').Generic error responses
Raw
err.messagewas being returned to API clients. Replaced with{ error: 'internal error' }— full error logged server-side only.PII redaction in logs
Phone numbers now show last 4 digits only. Control characters stripped
from
pushNamebefore logging (prevents log injection).Removed deprecated printQRInTerminal: true
Removed — QR is already served via the data-URL endpoint.
Renamed session_id → connection_id
session_idwas never validated anywhere, misleadingly suggesting itwas a credential. Renamed to
connection_idto clarify it is informational only.Committed package-lock.json
Pins the dependency tree to a reproducible snapshot.
npm auditreports 0 vulnerabilities against this lockfile.Testing
node --check index.js— syntax cleannpm audit— 0 vulnerabilitiescargo test --workspace— 2,074 tests, 0 failures