fix(security): harden default API key, IP whitelist, and QR access#105
Open
Pakzone1 wants to merge 1 commit into
Open
fix(security): harden default API key, IP whitelist, and QR access#105Pakzone1 wants to merge 1 commit into
Pakzone1 wants to merge 1 commit into
Conversation
Seed random admin key unless ALLOW_DEV_API_KEY=true is set explicitly. Reject API keys with IP whitelist when client IP cannot be determined. Require OPERATOR role for GET /sessions/:id/qr. Document ALLOW_DEV_API_KEY in .env.example and docs README. Opt in predictable dev key in docker-compose.dev.yml.
|
|
||
| it('should reject when IP whitelist is set but client IP is unknown', async () => { | ||
| const key = createMockApiKey({ | ||
| allowedIps: ['10.0.0.1'], |
There was a problem hiding this comment.
It would be great if we could configure it via the .env file. Have you already thought about this, or is the configuration done via the web interface ?
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.
Description
This PR tightens a few security gaps around API keys and session pairing.
On first startup, OpenWA used to create a fixed
dev-admin-keywheneverNODE_ENVwas not set to production. Many Docker and staging setups never set that variable, so new installs could end up with a known admin key. Now the default is always a random key. The old predictable key is only used when you setALLOW_DEV_API_KEY=true, which is meant for local development only. The dev Docker compose file turns that on so local workflows stay convenient.API keys with an IP whitelist used to skip the check when the server could not see a client IP. That meant the restriction could be bypassed. If a whitelist is configured and the client IP is unknown, the request is now rejected.
The QR code endpoint for linking WhatsApp (
GET /sessions/:id/qr) did not require operator permissions. A viewer key could fetch the QR and pair another device to someone else's session. That route now requires the OPERATOR role.Docs were updated in
.env.exampleanddocs/README.mdto explainALLOW_DEV_API_KEY.Type of Change
Testing
After
npm install, run:npm test -- src/modules/auth/auth.service.spec.tsnpm run lintManual checks (optional):
ALLOW_DEV_API_KEY: startup log anddata/.api-keyshould show a randomowa_k1_...key.ALLOW_DEV_API_KEY=true: first boot usesdev-admin-key(dev only).GET /sessions/:id/qrshould get 401.Checklist
Screenshots (if applicable)
N/A
Related Issues
No linked issue. This addresses insecure default API key behavior and related auth hardening.