Skip to content

Commit b9751e4

Browse files
authored
Backstop for logging secrets in ConfigToString (#600)
We really do want to avoid ever logging these. There is a workaround to force it, but you have to explicitly opt-in which seems reasonable.
1 parent 9aab5af commit b9751e4

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Cognite.Config/Yaml/DefaultFilterTypeInspector.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ public DefaultFilterTypeInspector(
4747
_customConverters = customConverters;
4848
}
4949

50+
private bool ShouldIgnoreForSecurity(string name)
51+
{
52+
var lowerName = name.ToLowerInvariant();
53+
return lowerName.Contains("password")
54+
|| lowerName.Contains("secret")
55+
|| lowerName.Contains("connectionstring");
56+
}
57+
5058
public override string GetEnumName(Type enumType, string name)
5159
{
5260
return _innerTypeDescriptor.GetEnumName(enumType, name);
@@ -82,6 +90,13 @@ public override IEnumerable<IPropertyDescriptor> GetProperties(Type type, object
8290
if (_toIgnore.Contains(name)) return false;
8391
// Some should be kept to encourage users to set them
8492
if (_toAlwaysKeep.Contains(name)) return true;
93+
// Security-sensitive properties should be ignored
94+
// We put this after toAlwaysKeep, so that users can force keeping something
95+
// that looks like a secret but isn't sensitive. In that case it would clearly
96+
// be deliberate.
97+
// These should ideally be listed in toIgnore instead,
98+
// but this serves as a safety net.
99+
if (ShouldIgnoreForSecurity(name)) return false;
85100

86101
var prop = type.GetProperty(name);
87102
object? df = null;

version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.37.0
1+
1.37.1

0 commit comments

Comments
 (0)