fix: stop logging Consul configuration values
This commit is contained in:
parent
8988c880bc
commit
d7697a412a
@ -60,11 +60,6 @@ internal sealed class ConsulConfigurationProvider : ConfigurationProvider, IDisp
|
||||
_lastIndex = index;
|
||||
Data = dict;
|
||||
_logger.LogInformation("[Consul] 加载成功:{Count} 个 KV,LastIndex={Index}", dict.Count, index);
|
||||
if (dict.Count > 0)
|
||||
{
|
||||
foreach (var k in dict.Keys.Take(3))
|
||||
_logger.LogDebug("[Consul] 示例 key: {Key} = {Val}", k, dict[k]?.ToString()?.Substring(0, Math.Min(20, dict[k]?.ToString()?.Length ?? 0)));
|
||||
}
|
||||
|
||||
if (_options.ReloadOnChange && _watchTimer == null)
|
||||
{
|
||||
|
||||
@ -0,0 +1,33 @@
|
||||
namespace BuildFlow.Architecture.Tests;
|
||||
|
||||
using Xunit;
|
||||
|
||||
/// <summary>
|
||||
/// 配置加载与日志输出的安全边界测试。
|
||||
/// </summary>
|
||||
public class ConfigurationSecurityTests
|
||||
{
|
||||
[Fact]
|
||||
public void ConsulProviderShouldNeverLogConfigurationValues()
|
||||
{
|
||||
var source = File.ReadAllText(Path.Combine(
|
||||
FindRepoRoot().FullName,
|
||||
"src", "BuildFlow.Host", "Configuration", "ConsulConfigurationProvider.cs"));
|
||||
|
||||
Assert.DoesNotContain("{Val}", source);
|
||||
Assert.DoesNotContain("dict[k]", source);
|
||||
Assert.DoesNotContain("示例 key:", source);
|
||||
}
|
||||
|
||||
private static DirectoryInfo FindRepoRoot()
|
||||
{
|
||||
var current = new DirectoryInfo(AppContext.BaseDirectory);
|
||||
while (current is not null)
|
||||
{
|
||||
if (File.Exists(Path.Combine(current.FullName, "BuildFlow.slnx"))) return current;
|
||||
current = current.Parent;
|
||||
}
|
||||
|
||||
throw new InvalidOperationException("无法定位 BuildFlow.slnx,无法验证配置日志安全边界。");
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user