Skip to content

Commit 5468978

Browse files
authored
Update the security guidance (#35865)
1 parent f275bd5 commit 5468978

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

aspnetcore/blazor/progressive-web-app/push-notifications.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
---
22
title: Push notifications for ASP.NET Core Blazor Progressive Web Applications (PWAs)
3+
ai-usage: ai-assisted
34
author: guardrex
45
description: Learn how to issue push notifications in Blazor Progressive Web Applications (PWAs).
56
monikerRange: '>= aspnetcore-3.1'
67
ms.author: wpickett
78
ms.custom: mvc
8-
ms.date: 07/07/2025
9+
ms.date: 07/30/2025
910
uid: blazor/progressive-web-app/push-notifications
1011
---
1112
# Push notifications for ASP.NET Core Blazor Progressive Web Applications (PWAs)
@@ -30,24 +31,21 @@ The example in this article uses push notifications to provide order status upda
3031

3132
Generate the cryptographic public and private keys for securing push notifications either locally, for example with PowerShell or IIS, or using an online tool.
3233

33-
> [!CAUTION]
34-
> This article's use of a unencrypted, insecure private key in the app's code ***is for demonstration purposes and local testing only.*** We recommend using a secure approach for supplying a private key to an ASP.NET Core app at all stages of development. When working locally in the Development environment, a private key can be provided to the app using the [Secret Manager](xref:security/app-secrets#secret-manager) tool. In Development, Staging, and Production environments, [Azure Key Vault](/azure/key-vault/) with [Azure Managed Identities](/entra/identity/managed-identities-azure-resources/overview) can be used, noting in passing that to obtain a certificate's private key from a key vault that the certificate must have an exportable private key.
35-
36-
<!-- We'll expand this article to include explicit guidance on key management with AKV. A
37-
Google search with 'get certificate private key from azure key vault for use in c# code'
38-
generates a decent code sample. I didn't see such a good starting point in AKV Learn
39-
articles, so we'll use the AI-generated code as a starting point.
40-
41-
The preceding CAUTION statement also appears in the 'Send a notification' section.
42-
-->
43-
4434
Placeholders used in this article's example code:
4535

4636
* `{PUBLIC KEY}`: The public key.
4737
* `{PRIVATE KEY}`: The private key.
4838

4939
For this article's C# examples, update the `[email protected]` email address to match the address used when creating the custom key pair.
5040

41+
When implementing push notifications, ensure that cryptographic keys are managed securely:
42+
43+
* **Key generation**: Use a trusted library or tool to generate the public and private keys. Avoid using weak or outdated algorithms.
44+
* **Key storage**: Store private keys securely on the server, using a secure storage mechanism such as a hardware security module (HSM) or encrypted storage. Never expose private keys to the client.
45+
* **Key usage**: Use the private key only for signing push notification payloads. Ensure that the public key is distributed securely to clients.
46+
47+
For more information on cryptographic best practices, see [Cryptographic Services](/dotnet/standard/security/cryptographic-services).
48+
5149
## Create a subscription
5250

5351
Before sending push notifications to a user, the app must ask the user for permission. If they grant permission to receive notifications, their browser generates a *subscription*, which includes a set of tokens the app can use to route notifications to the user.
@@ -258,7 +256,7 @@ Sending a notification involves performing some complex cryptographic operations
258256
The `SendNotificationAsync` method dispatches order notifications using the captured subscription. The following code makes uses of `WebPush` APIs for dispatching the notification. The payload of the notification is JSON serialized and includes a message and a URL. The message is displayed to the user, and the URL allows the user to reach the pizza order associated with the notification. Additional parameters can be serialized as required for other notification scenarios.
259257

260258
> [!CAUTION]
261-
> This article's use of a unencrypted, insecure private key in the app's code ***is for demonstration purposes and local testing only.*** We recommend using a secure approach for supplying a private key to an ASP.NET Core app at all stages of development. When working locally in the Development environment, a private key can be provided to the app using the [Secret Manager](xref:security/app-secrets#secret-manager) tool. In Development, Staging, and Production environments, [Azure Key Vault](/azure/key-vault/) with [Azure Managed Identities](/entra/identity/managed-identities-azure-resources/overview) can be used, noting in passing that to obtain a certificate's private key from a key vault that the certificate must have an exportable private key.
259+
> In the following example, we recommend using a secure approach for supplying the private key. When working locally in the Development environment, a private key can be provided to the app using the [Secret Manager](xref:security/app-secrets#secret-manager) tool. In Development, Staging, and Production environments, [Azure Key Vault](/azure/key-vault/) with [Azure Managed Identities](/entra/identity/managed-identities-azure-resources/overview) can be used, noting in passing that to obtain a certificate's private key from a key vault that the certificate must have an exportable private key.
262260
263261
```csharp
264262
private static async Task SendNotificationAsync(Order order,

0 commit comments

Comments
 (0)