Skip to content
Bitzsoft.Integrationsbitzsoft.integrations

Concept

请求日志脱敏

SensitiveDataRedactor 的结构化脱敏策略和敏感字段识别规则。

Last updated

Bitzsoft.Integrations.RequestLogging 内置结构化脱敏器,在审计日志写入前自动识别并脱敏敏感字段。这是防止密钥进入日志的核心防线。

脱敏架构

HTTP 请求

RequestLogHandler
拦截请求/响应

HttpBodyCapture
捕获完整正文

RequestLogSanitizer
按字段名匹配

SensitiveDataRedactor
按位置脱敏

IRequestLogStore
脱敏后写入

RequestLogProcessor
非阻塞入队

脱敏覆盖范围

HTTP Header

按 Header 名称匹配:

Authorization → ***
X-API-Key → ***
X-Auth-Token → ***
Cookie → ***
Set-Cookie → ***

Query String

按参数名匹配:

?access_token=xxx → access_token=***
?secret=xxx → secret=***
?api_key=xxx → api_key=***
?signature=xxx → signature=***

JSON Body

按 JSON 路径递归匹配:

// 脱敏前
{
"app_id": "2021000...",
"app_secret": "MIIEvQ...",
"data": {
"card_no": "622202...",
"cvv": "123"
}
}
// 脱敏后
{
"app_id": "2021000...",
"app_secret": "***",
"data": {
"card_no": "***",
"cvv": "***"
}
}

XML Body

按元素名匹配:

<!-- 脱敏前 -->
<request>
<appId>2021000...</appId>
<appSecret>MIIEvQ...</appSecret>
</request>
<!-- 脱敏后 -->
<request>
<appId>2021000...</appId>
<appSecret>***</appSecret>
</request>

Form Body

按字段名匹配:

// 脱敏前
grant_type=client_credentials&client_secret=MIIEvQ...&client_id=2021000...
// 脱敏后
grant_type=client_credentials&client_secret=***&client_id=2021000...

正文大小管理

配置默认值说明
MaxLoggedBodyLengthnull不限制最终日志正文大小
MaxInMemoryBodyBytes有界超过后切换到加密临时文件

自定义脱敏策略

宿主可以实现自定义的脱敏策略:

// 注册时覆盖默认脱敏策略
builder.Services.AddRequestLogging<MyRequestLogStore>(options =>
{
options.AdditionalSensitiveFields.Add("x_custom_token");
options.AdditionalSensitiveFields.Add("private_key");
});

相关

100%

滚轮或按钮缩放 · 放大后拖动画面 · 双击切换 100% / 200%