Illustration of web push encryption, a notification envelope sealed with a padlock on a laptop screen Illustration of web push encryption, a notification envelope sealed with a padlock on a laptop screen

How Are Web Push Notifications Encrypted?

How web push encryption works under RFC 8291: p256dh and auth keys, ECDH and AES-128-GCM, what push services can see, and how VAPID differs.

Web push encryption uses the Message Encryption for Web Push standard, RFC 8291. Your server combines its own temporary key with the browser’s p256dh public key and 16-byte auth secret through ECDH, then encrypts the payload with AES-128-GCM. The push service only relays ciphertext. Only the subscribed browser can decrypt the notification.

When people ask me whether web push is private, the honest answer has two parts. The message content is end-to-end encrypted between your server and the visitor’s browser. However, the push service still sees metadata, such as when you sent a message and to which endpoint. Here’s how web push encryption works, step by step, and what it does and doesn’t protect.

Key facts at a glance:

  • Standard: RFC 8291 defines web push encryption, and RFC 8188 defines the aes128gcm content coding it uses.
  • Keys: each subscription carries a P-256 public key (p256dh) and a 16-byte auth secret, created by the browser.
  • Cipher: AES-128-GCM, with keys derived through ECDH and HKDF.
  • Size: push services only have to accept 4,096 bytes of encrypted body, which leaves at most 3,993 bytes of plaintext.
  • VAPID is separate: VAPID (RFC 8292) proves who sent the message. It doesn’t encrypt anything.

How does web push encryption work?

Web push encryption works like a sealed envelope that only one browser can open. The browser publishes a public key when it subscribes. Your server uses that key to lock each message, so the push service in the middle can carry it but not read it.

The process follows the same steps for every message:

  1. The browser subscribes through the Push API and creates a key pair plus a random auth secret.
  2. Your site sends the subscription (endpoint, p256dh and auth) to your server.
  3. For each message, your server creates a new temporary (ephemeral) P-256 key pair and a random 16-byte salt.
  4. The server runs ECDH between its temporary private key and the browser’s p256dh public key to get a shared secret.
  5. HKDF mixes that shared secret with the auth secret and salt to derive a content encryption key and a nonce.
  6. The payload is encrypted with AES-128-GCM and sent with the server’s temporary public key in the message header.
  7. The browser repeats the key agreement with its private key, derives the same key, and decrypts the payload for your service worker.

Because the server makes a fresh key pair and salt for every message, two identical notifications never produce the same ciphertext.

What are the p256dh and auth keys in a push subscription?

The p256dh and auth values are the two keys the browser hands you so you can encrypt messages for it. You’ll see them in every PushSubscription object, next to the endpoint URL:

FieldWhat it isSizeWho can see it
endpointURL at the push service for this subscriptionVaries by browserYour server and the push service
keys.p256dhBrowser’s P-256 ECDH public key65 bytes (Base64URL encoded)Your server
keys.authRandom authentication secret16 bytes (Base64URL encoded)Your server
Private keyMatching private keyNever leaves the browserOnly the browser

Treat p256dh and auth as sensitive. Anyone who holds them and the endpoint could encrypt a message for that subscriber, although they would still need your VAPID private key to get the push service to accept it. I store them in the same database table as the endpoint and never expose them in front-end code or logs.

Can the push service read your notifications?

No. Firebase Cloud Messaging (FCM), Mozilla’s autopush and Apple’s web push service only receive encrypted bytes, so they can’t read the title, body or link inside your payload. That’s the whole point of RFC 8291.

That said, encryption doesn’t hide everything. The push service still knows the endpoint, the time of each request, the payload size and headers such as TTL and Urgency. My post on what data a web push service stores covers that side in more detail.

On the browser side, the decrypted payload is handed to your service worker as plain data. From there, the notification appears on screen, and anyone who can see the screen can read it. So keep one-time codes and private details out of notifications even though the transport is encrypted.

Is VAPID the same as web push encryption?

No. VAPID and encryption solve two different problems, and people mix them up all the time. Encryption protects the content for the subscriber. VAPID proves to the push service that the message comes from the server the subscriber signed up with.

Web push encryptionVAPID
StandardRFC 8291 and RFC 8188RFC 8292
Keys usedBrowser’s p256dh and auth, plus a fresh server key per messageYour site’s fixed VAPID key pair
ProtectsMessage content from the push serviceSubscriptions from being used by other senders
What a failure looks likeBrowser can’t decrypt; nothing showsPush service rejects with 401 or 403

If you want the full VAPID story, read my explainer on VAPID keys for web push.

What is the difference between aes128gcm and aesgcm?

aes128gcm is the current, standard content coding, and you should use it. aesgcm is an older draft format that some early Chrome and Edge versions used before RFC 8291 was finalised.

In aes128gcm, the salt, record size and server public key travel inside the encrypted body’s header. The old aesgcm format put them in separate Encryption and Crypto-Key HTTP headers instead. You can check what a browser accepts with PushManager.supportedContentEncodings, which MDN documents here. Modern libraries default to aes128gcm, so in practice you rarely touch this setting.

Do you have to write the encryption code yourself?

No, and I wouldn’t recommend it. Maintained libraries already implement RFC 8291 correctly, and hand-rolled crypto is an easy place to make subtle mistakes. You pass the subscription and the payload; the library does the key agreement, key derivation and encryption.

The common choices are:

If you use the Firebase JavaScript SDK for subscribing, FCM handles the web push encryption on its side when it forwards your message to the browser.

Does encryption limit the payload size?

Yes, a little. Push services only need to accept 4,096 bytes of encrypted body. After the 86-byte header, at least 1 byte of padding and a 16-byte authentication tag, RFC 8291 says that leaves at most 3,993 bytes of plaintext.

In practice, that’s plenty for a title, body, icon URL, image URL and click link. Send URLs, not images, and keep extra data small. My post on the web push payload size limit shows what to do when you hit a 413 error.

Where LaraPush fits

If you’d rather not deal with keys and encryption at all, a self-hosted panel handles it for you. LaraPush is a self-hosted web push panel that you install on your own VPS, with a one-time licence from $499 (check LaraPush pricing). It sends through Firebase Cloud Messaging and stores subscriber data in your own MySQL database, so the subscription keys stay on a server you control. The features page lists what’s included. The trade-offs are no free plan and a server you maintain. For other options, see my roundup of the best push notification services and tools.

Frequently asked questions

Are web push notifications end-to-end encrypted?

The payload is. RFC 8291 encrypts each message between your server and the subscribed browser, so the push service can’t read it. However, the push service still sees metadata such as the endpoint, timing and size. Once the browser decrypts the message, the notification appears in plain text on the screen.

What happens if the p256dh or auth key is wrong?

The push service usually still accepts the message, because it can’t check the encryption. The browser then fails to decrypt it, so the push event never gets usable data and nothing useful appears. If one subscriber gets nothing while others work, check that you stored their keys exactly as the browser sent them.

Do I need my own SSL certificate for web push encryption?

You need HTTPS on your site, because the Push API only works in secure contexts. That certificate is separate from web push encryption, which uses per-message keys under RFC 8291. Your server’s connection to the push service also uses HTTPS, but your libraries handle that automatically.

Can I send a web push notification without a payload?

Yes. A push message with no body needs no encryption keys. The service worker then shows a generic notification or fetches the content from your server. Most sites send an encrypted payload instead, because it saves an extra network request and shows the right content even on a slow connection.

Does web push encryption make it safe to send passwords or OTPs?

No. Encryption protects the message in transit, but the decrypted text appears on screen and often on the lock screen. Anyone near the device can read it. Keep passwords, full one-time codes and personal data out of notifications, and link to a signed-in page instead.

Leave a Reply

Your email address will not be published. Required fields are marked *