fix: encrypt webhook secrets before storage in MongoDB (#3956)#3961
Open
atul-upadhyay-7 wants to merge 10 commits into
Open
fix: encrypt webhook secrets before storage in MongoDB (#3956)#3961atul-upadhyay-7 wants to merge 10 commits into
atul-upadhyay-7 wants to merge 10 commits into
Conversation
- Add webhook crypto utility with AES-256-GCM encryption and HMAC-SHA256 hashing - Encrypt webhook secrets before storing in database - Strip secrets from all API responses (GET, list) - Return raw secret only once at creation time with save warning - Add getWebhookSecretForSigning function for dispatcher to retrieve decrypted secrets - Update dispatcher to use decrypted secrets for signing Fixes Premshaw23#3956
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
This PR fixes the vulnerability where webhook signing secrets were stored in plaintext in MongoDB. Secrets are now encrypted before storage and never exposed in API responses after creation.
Changes
New:
lib/webhook/crypto.jsWEBHOOK_ENCRYPTION_KEYorCRON_SECRETenv varUpdated:
lib/models/webhookModel.jsencryptedSecret) and hashed (secretHash) before storageserializeWebhook()stripssecret,secretHash, andencryptedSecretfrom all responsesgetWebhookSecretForSigning()function retrieves decrypted secrets for the dispatcherupdateWebhook()re-encrypts secrets when updatedUpdated:
lib/webhook/dispatcher.jsgetWebhookSecretForSigning()to retrieve decrypted secrets for signingUpdated:
app/api/webhooks/route.jsSecurity Model
secretfieldencryptedSecret+ hashedsecretHashEnvironment Setup
Set
WEBHOOK_ENCRYPTION_KEYin production (falls back toCRON_SECRET):Testing
POST /api/webhooks— raw secret returned once in responseGET /api/webhooks— no secret in responseRelated Issue
Fixes #3956