log4j WSO 2 APIM -从API日志中删除授权头

qltillow  于 2023-06-22  发布在  其他
关注(0)|答案(1)|浏览(104)

我想从api.log文件中删除出现在那里的授权头:

[2022-02-08 15:00:57,703]  INFO {API_LOG} pizzashack - {"headers":["accept=application/json",...,"Connection=keep-alive","Host=localhost:8243","authorization=Bearer yJraWQiOiJnYXRld2F5X3g...","Origin=https://localhost:9443"..

我想删除授权头内的令牌,我该怎么做?我尝试使用log4jproperties添加:

logger.API_LOGGER.property.apim.message = %replace{%msg}{authorization:[^,]*}{"Authorization: Bearer ***"}{}

但它给了我一个错误时重新启动APIM。

3zwtqj6y

3zwtqj6y1#

你应该可以使用log-masking[1]来完成这一操作。
示例配置如下所示。
1.在deploye.toml中为JWT添加下面的掩码正则表达式(请注意这只是一个示例,您可能需要改进它以仅捕获JWT)

[masking_pattern.properties]
"JWT" = ' \\b([a-zA-Z0-9_=]+)\\.([a-zA-Z0-9_=]+)\\.([a-zA-Z0-9_\\-\\+\\/=]*)\\"'

1.通过更新日志模式,为API_LOGGER启用日志屏蔽,如下所示。

appender.API_LOGFILE.layout.pattern = [%d] %5p {%c} %X{apiName} - %mm%ex%n

[1]. https://apim.docs.wso2.com/en/4.1.0/administer/logging-and-monitoring/logging/masking-sensitive-information-in-logs/

相关问题