fix(webhooks): persist secrets to DB with AES-256-GCM encryption, use… - #636
Merged
nonsobethel0-dev merged 1 commit intoSep 25, 2026
Conversation
… top-level crypto import Closes Parashield-Protocol#606, Parashield-Protocol#607. Issue Parashield-Protocol#606 (high): WebhooksService stored webhook registration secrets in an in-memory Map — lost on every restart, unencrypted, not shared across instances. Persistence to the database was added under Parashield-Protocol#482; this commit completes Parashield-Protocol#606 by encrypting secrets at rest with AES-256-GCM. - Added WEBHOOK_SECRET_KEY env var (opt-in). When set, secrets are encrypted via AES-256-GCM (randomised IV per secret, auth tag stored alongside ciphertext as 'enc:<iv>:<tag>:<ct>'). When unset a startup warning is emitted and secrets are stored as plain text for backward compatibility. - decryptSecret() handles both encrypted and legacy plain-text rows transparently so existing registrations remain readable after the key is added. - Documented WEBHOOK_SECRET_KEY in .env.example with a generation command. Issue Parashield-Protocol#607 (low): signPayload() was using require('crypto') at runtime, inconsistent with the rest of the codebase and inhibiting tree-shaking. The fix uses the existing top-level import * as crypto already in the file. Tests: updated build() helper to accept a mock ConfigService; added four new tests covering encrypted storage, round-trip decryption, plain-text backward compatibility, and signPayload HMAC correctness. Issues Parashield-Protocol#608 and Parashield-Protocol#609 will be addressed in a follow-up commit.
|
@GreyDayo Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
… top-level crypto import
Closes #606
Closes #607
Issue #606 (high): WebhooksService stored webhook registration secrets in an in-memory Map — lost on every restart, unencrypted, not shared across instances. Persistence to the database was added under #482; this commit completes #606 by encrypting secrets at rest with AES-256-GCM.
Issue #607 (low): signPayload() was using require('crypto') at runtime, inconsistent with the rest of the codebase and inhibiting tree-shaking. The fix uses the existing top-level import * as crypto already in the file.
Tests: updated build() helper to accept a mock ConfigService; added four new tests covering encrypted storage, round-trip decryption, plain-text backward compatibility, and signPayload HMAC correctness.
About this PR
This PR resolves 4 enhancement issues:
Changes
#375 - API versioning strategy
X-API-Versionresponse headerDeprecationheader for v1 withLinkheader pointing to v2 successorx-api-versionheader for API version negotiation#373 - Pagination on policy and claims list endpoints
pageandlimitquery parameters toGET /api/v1/productsendpointgetActiveProductsservice method to support Prisma-based pagination withtake/skipgetClaimsByWalletQuery,getClaimHistory) already had pagination#372 - Rate limiting on claim submission endpoint
limit: 5/60s) toPOST /api/v1/claimsendpoint@Throttledecorator with stricter limits than global throttler (60/60s)#374 - Webhook support for policy/claim status changes
WebhooksServicewith register/unregister/list and status notification methodsWebhooksControllerwithPOST /api/v1/webhooks/registerandGET /api/v1/webhooksendpointspolicy.status.changeeventclaim.status.changeeventIssue Closure
This PR closes the following issues using GitHub keyword syntax:
Verification
{ success, data, total, page, limit })policy.status.change,claim.status.change)