feat(notifications): protect security-critical notification preferences (#1160) - #1190
Merged
RUKAYAT-CODER merged 1 commit intoAug 2, 2026
Conversation
…m opt-out (rinafcode#1160) Security-critical notifications (new-device login, password change, payment receipts, account deletion) can never be disabled or unsubscribed from, and incoming preference keys are validated against a known allowlist so unknown keys fail fast with a 400. - Adds SECURITY_CRITICAL_EVENT_TYPES / KNOWN_EVENT_TYPES / EVENT_FREQUENCIES / CHANNEL_KEYS constants. - updatePreferences rejects disabling protected event types via eventFrequency or topicSubscriptions, rejects unknown keys/events/ frequencies, and refuses to disable the last enabled delivery channel. - toggleChannel refuses to disable the last remaining enabled channel. - unsubscribe rejects security-critical event types while still allowing non-critical opt-out and the global "all" switch. - Adds 17 unit tests covering every guard.
|
@NoahJoseph-ux 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! 🚀 |
Contributor
|
Thank you for contributing to the project |
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.
Overview
This PR makes it impossible for a user (or a compromised session) to disable security-critical notifications. Security events — new-device login, password change, payment receipts, and account deletion — are the user's early-warning system for account compromise, so opting out of them (via
updatePreferences,toggleChannel, orunsubscribe) is now rejected with a 400. It also hardens preference updates by validating every incoming key against a known allowlist, so typos or unknown fields fail fast instead of silently writing junk rows.Related Issue
Closes #1160
Changes
Security-critical event protection
src/notifications/preferences/notification-preferences.constants.ts—SECURITY_CRITICAL_EVENT_TYPES,KNOWN_EVENT_TYPES,EVENT_FREQUENCIES,CHANNEL_KEYS.preferences.service.ts—updatePreferencesrejectsneverfrequency orfalsesubscription for any security-critical event type;unsubscriberejects security-critical types while still allowing non-critical opt-out and the global"all"switch.Key validation (allowlist)
preferences.service.ts—updatePreferencesnow rejects unknown top-level keys, unknown event types, and invalid frequency values withBadRequestExceptionbefore any write.Delivery-channel safety net
preferences.service.ts—updatePreferences/toggleChannelrefuse to disable the last remaining enabled delivery channel, guaranteeing security-critical notifications always keep a delivery path.Tests
preferences.service.spec.ts— 17 unit tests covering every guard and the allowed paths (non-critical opt-out, protected-type re-enable, global unsubscribe, multi-channel toggles).Verification Results
Test Suites: 1 passed, 1 total/Tests: 17 passed, 17 totaleslintclean on all changed filestscerrors exist elsewhere in the repo, e.g.src/rbac/roles/roles.controller.ts, untouched by this PR)Acceptance Criteria
eventFrequencyortopicSubscriptionsunsubscriberejects security-critical event types