-
-
Notifications
You must be signed in to change notification settings - Fork 382
doc(Log): add filter for Antiforgery #7830
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||
| // Licensed to the .NET Foundation under one or more agreements. | ||||||
| // Licensed to the .NET Foundation under one or more agreements. | ||||||
| // The .NET Foundation licenses this file to you under the Apache 2.0 License | ||||||
| // See the LICENSE file in the project root for more information. | ||||||
| // Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone | ||||||
|
|
@@ -18,8 +18,12 @@ public static IServiceCollection AddBootstrapBlazorServerService(this IServiceCo | |||||
| // 增加中文编码支持网页源码显示汉字 | ||||||
| services.AddSingleton(HtmlEncoder.Create(UnicodeRanges.All)); | ||||||
|
|
||||||
| // 增加错误日志 | ||||||
| services.AddLogging(logging => logging.AddFileLogger()); | ||||||
| // 增加错误日志,并过滤已知的防伪 Token 解密噪音日志 | ||||||
| services.AddLogging(logging => | ||||||
| { | ||||||
| logging.AddFileLogger(); | ||||||
| logging.AddFilter("Microsoft.AspNetCore.Antiforgery", LogLevel.None); | ||||||
|
||||||
| logging.AddFilter("Microsoft.AspNetCore.Antiforgery", LogLevel.None); | |
| logging.AddFilter("Microsoft.AspNetCore.Antiforgery", LogLevel.Error); |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4,7 +4,6 @@ | |||||
| // Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone | ||||||
|
|
||||||
| using Microsoft.AspNetCore.Components.Authorization; | ||||||
| using Microsoft.AspNetCore.DataProtection; | ||||||
|
|
||||||
| namespace Microsoft.Extensions.DependencyInjection; | ||||||
|
|
||||||
|
|
@@ -99,9 +98,7 @@ public static IServiceCollection AddBootstrapBlazorServices(this IServiceCollect | |||||
| services.AddBootstrapBlazorRegionService(); | ||||||
|
|
||||||
| // 增加密钥存储配置 | ||||||
|
||||||
| // 增加密钥存储配置 | |
| // 增加数据保护服务 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Reconsider removing explicit DataProtection app name and key persistence configuration.
Removing .SetApplicationName("BootstrapBlazor") and .PersistKeysToFileSystem(...) means DataProtection will use host defaults for app isolation and key storage. This can result in ephemeral keys (invalidating auth/antiforgery cookies on restart) or unintended key sharing between apps, especially in scaled or long‑running deployments. If this configuration isn’t being set elsewhere, it’s safer to keep an explicit application name and persistent key store.
Copilot
AI
Apr 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
services.AddDataProtection() used to set SetApplicationName("BootstrapBlazor") and persist the key ring to a known path. This PR removes that configuration entirely, which can change where keys are stored and how antiforgery/data-protection payloads are decrypted across restarts/instances. If the intent is only to reduce Antiforgery log noise (per PR title/issue), consider reverting this change or explicitly documenting/configuring the new key storage strategy (e.g., still set an application name and persist keys to a stable, writable location).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Consider narrowing the antiforgery logging filter instead of disabling the category entirely.
Setting
Microsoft.AspNetCore.AntiforgerytoLogLevel.Nonesuppresses all current and future antiforgery warnings/errors, which may hinder diagnosing production issues. Prefer raising the level (e.g., toWarning/Error) or filtering only the specific noisy event IDs/messages so critical antiforgery failures remain visible in logs.