feat(notifications): Web Push delivers notifications to every device, even with TREK closed

A fourth built-in channel next to email, webhook and ntfy. Browsers
register per device, the server encrypts per RFC 8291 and signs per RFC
8292 with node:crypto and sends only to known push services through the
SSRF guard. The event matrix decides per category what arrives by push;
admins switch the channel on under Notifications.

VAPID keys come from the environment or are generated once, only while
neither stored row exists, and kept encrypted. A pair that does not
decrypt or match is never overwritten and never swapped for another one:
push stays off with an error in the log and every device stays
registered until the key is fixed. The subject is VAPID_SUBJECT, then an
https APP_URL, then the project URL.

Only chat messages collapse into one notification per trip, and a
replacement still alerts. A 403 removes a device only after three
failures in a row; 404 and 410 remove it at once. Password change, reset
and an admin setting a password drop the user's devices with the other
credentials. The request log redacts subscriptions and endpoints, boot
errors print *** for every secret variable, and logout forgets the
device with a plain fetch so an expired session cannot redirect midway.

Addresses discussion #894.
This commit is contained in:
Maurice
2026-09-24 23:17:03 +00:00
parent 7ce31756a3
commit 650451bdf7
177 changed files with 7809 additions and 271 deletions
+9
View File
@@ -15,6 +15,7 @@ import { clearAllPluginSessions } from './pluginStore'
import { forgetStartDestination } from '../utils/startDestination'
import { forgetServerLanguage } from './settingsStore'
import { markSignedOut, clearSignedOut } from '../utils/signedOut'
import { forgetPushDeviceOnLogout, resyncPushSubscription } from '../push/webPush'
interface AuthResponse {
user: User
@@ -119,6 +120,9 @@ async function onAuthSuccess(userId: number): Promise<void> {
// an SPA session, so a second login in the same tab would leave the mutation
// queue without a flush trigger. Re-registering is a no-op while they are up.
registerSyncTriggers()
// Tell the server again which push subscription this device holds, in the
// background: sign-in must not wait on it, and it never rejects.
void resyncPushSubscription()
}
export const useAuthStore = create<AuthState>()(
@@ -264,6 +268,11 @@ export const useAuthStore = create<AuthState>()(
// and the next account would come up believing it is offline over a working
// connection, with nothing cached to answer from.
setForcedOffline(false)
// Forget this device's push subscription, on the server and in the browser,
// or the next account on a shared device keeps receiving this one's
// notifications. It has to happen here: the DELETE needs the session cookie
// that step 4 clears. Best effort and bounded, so logout never hangs on it.
await forgetPushDeviceOnLogout()
// 4. Tell server to clear the httpOnly cookie (best-effort).
await fetch('/api/auth/logout', { method: 'POST', credentials: 'include' }).catch(() => {})
// 5. Clear service worker caches containing sensitive data.