-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Update the security guidance #35865
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Update the security guidance #35865
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,12 @@ | ||
| --- | ||
| title: Push notifications for ASP.NET Core Blazor Progressive Web Applications (PWAs) | ||
| ai-usage: ai-assisted | ||
| author: guardrex | ||
| description: Learn how to issue push notifications in Blazor Progressive Web Applications (PWAs). | ||
| monikerRange: '>= aspnetcore-3.1' | ||
| ms.author: wpickett | ||
| ms.custom: mvc | ||
| ms.date: 07/07/2025 | ||
| ms.date: 07/30/2025 | ||
| uid: blazor/progressive-web-app/push-notifications | ||
| --- | ||
| # 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 | |
|
|
||
| Generate the cryptographic public and private keys for securing push notifications either locally, for example with PowerShell or IIS, or using an online tool. | ||
|
|
||
| > [!CAUTION] | ||
| > 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. | ||
|
|
||
| <!-- We'll expand this article to include explicit guidance on key management with AKV. A | ||
| Google search with 'get certificate private key from azure key vault for use in c# code' | ||
| generates a decent code sample. I didn't see such a good starting point in AKV Learn | ||
| articles, so we'll use the AI-generated code as a starting point. | ||
|
|
||
| The preceding CAUTION statement also appears in the 'Send a notification' section. | ||
| --> | ||
|
|
||
| Placeholders used in this article's example code: | ||
|
|
||
| * `{PUBLIC KEY}`: The public key. | ||
| * `{PRIVATE KEY}`: The private key. | ||
|
|
||
| For this article's C# examples, update the `[email protected]` email address to match the address used when creating the custom key pair. | ||
|
|
||
| When implementing push notifications, ensure that cryptographic keys are managed securely: | ||
|
|
||
| * **Key generation**: Use a trusted library or tool to generate the public and private keys. Avoid using weak or outdated algorithms. | ||
| * **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. | ||
| * **Key usage**: Use the private key only for signing push notification payloads. Ensure that the public key is distributed securely to clients. | ||
|
|
||
| For more information on cryptographic best practices, see [Cryptographic Services](/dotnet/standard/security/cryptographic-services). | ||
|
|
||
| ## Create a subscription | ||
|
|
||
| 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 | |
| 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. | ||
|
|
||
| > [!CAUTION] | ||
| > 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. | ||
| > 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. | ||
|
|
||
| ```csharp | ||
| private static async Task SendNotificationAsync(Order order, | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.