fix: restrict CORS origins and gate webhook events endpoint#2
Merged
princemuichkine merged 2 commits intoJun 29, 2026
Merged
Conversation
- Replace wildcard cors() with cors({ origin: appBaseUrl }) on all four
reference servers to prevent cross-origin API key abuse from arbitrary
websites.
- Add optional ADMIN_TOKEN Bearer auth on /api/webhooks/events to prevent
unauthenticated access to sensitive payment and customer data.
- Update .env.example files to document the new ADMIN_TOKEN variable.
Fixes: wildcard CORS + unauthenticated payment endpoints (HIGH),
unauthenticated webhook event endpoint data exposure (MEDIUM).
Co-authored-by: Babacar Diop <princemuichkine@users.noreply.github.com>
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
Fixes two security vulnerabilities found during an at-rest security scan.
1. HIGH — Wildcard CORS enables cross-origin API key abuse
All four reference servers used
cors()with no origin restrictions. Any website a developer visits while running these servers could silently create checkout sessions and initiate charges (Wave, MTN, card) via cross-origin requests — abusing the merchant's secret API key.Fix: Replace
cors()withcors({ origin: appBaseUrl })on all four servers, restricting cross-origin requests to the app's own frontend origin.2. MEDIUM — Unauthenticated webhook event endpoint exposes payment data
GET /api/webhooks/eventsreturned the full in-memory webhook log (transaction IDs, amounts, customer PII) with no authentication. Combined with the wildcard CORS, any website could silently exfiltrate this data.Fix: Add optional
ADMIN_TOKENBearer auth on the events endpoint. WhenADMIN_TOKENis set in.env, requests must includeAuthorization: Bearer <token>. When unset, the endpoint remains open (backward-compatible for local development).Files changed
*/server/index.js(×4)cors()→cors({ origin: appBaseUrl }), auth gate on events endpoint*/.env.example(×4)ADMIN_TOKENvariableTesting
Authorization: Bearer <token>header whenADMIN_TOKENis set