security: verify payload integrity before processing notifications#362
Merged
Abd-Standard merged 3 commits intoJun 30, 2026
Merged
Conversation
- add payload-integrity.ts — hashPayload() and verifyPayloadIntegrity() using HMAC-SHA256 with timing-safe comparison - store payload_hash at schedule time (requires PAYLOAD_INTEGRITY_SECRET env) - add payload_hash column via additive ALTER TABLE migration (idempotent) - verify hash in scheduler before execution — tampered payloads are immediately failed (retries exhausted) and logged as errors - 13 tests: unit (hash/verify) + integration (store, match, tamper, valid)
|
Hey @michaelvic123! 👋 It looks like this PR isn't linked to any issue. If this PR is for one of the issues assigned to you as part of a Wave, please link it to ensure your contribution is tracked properly. You can do this by adding a keyword to the PR description (e.g.,
|
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.
What
Adds HMAC-SHA256 payload integrity verification to the notification pipeline. Tampered payloads are detected and rejected before delivery.
How it works
At schedule time (
notification-api.ts→repository.create):PAYLOAD_INTEGRITY_SECRETis set, an HMAC-SHA256 hash of the serialised payload is computed and stored in a newpayload_hashcolumn.At execution time (
notification-scheduler.ts→processNotification):crypto.timingSafeEqual.errorlog is emitted.Files changed
utils/payload-integrity.tshashPayload()andverifyPayloadIntegrity()database/database.tsALTER TABLEmigration forpayload_hashcolumn (idempotent)types/scheduled-notification.tspayloadHashtoScheduledNotificationandScheduledNotificationRowservices/scheduled-notification-repository.tscreate(), map field inrowToModel()services/notification-scheduler.tstests/payload-integrity.test.tsTests
13 tests pass:
hashPayload— determinism, payload sensitivity, secret sensitivityverifyPayloadIntegrity— valid pair, tampered payload, wrong hash, empty inputsConfiguration
Set
PAYLOAD_INTEGRITY_SECRETin your environment. If unset the feature is inactive and existing behaviour is unchanged.