security: sanitize nested Sentry metadata (#411)
Heimdall Gitea / Detect CI scope (pull_request) Canceled after 0s
Heimdall Gitea / CI policy (pull_request) Canceled after 0s
Heimdall Gitea / Build and tests (pull_request) Canceled after 0s
Heimdall Gitea / Build and scan server image (pull_request) Canceled after 0s
Heimdall Gitea / Build and scan agent image (pull_request) Canceled after 0s
Heimdall Gitea / Build and scan NVIDIA Agent image (pull_request) Canceled after 0s
Heimdall Gitea / Publish versioned installer release (pull_request) Canceled after 0s

This commit is contained in:
arnaud.dartois committed 2026-11-13 13:59:27 +01:00
1 parent fc36b38c6c
commit 26c9ae5ebd
2 files changed
+72 -7

No files matched your search

@@ -14,6 +14,12 @@ internal static class SentryTelemetryPrivacy
SanitizeRequest(sentryEvent.Request);
SanitizeContexts(sentryEvent.Contexts);
foreach (var key in sentryEvent.Tags.Keys.ToArray())
{
if (IsSensitiveName(key))
sentryEvent.SetTag(key, Redacted);
}
if (sentryEvent.Extra is IDictionary<string, object?> extra)
RedactObjectValues(extra);
@@ -107,10 +113,13 @@ internal static class SentryTelemetryPrivacy
foreach (var key in contexts.Keys.ToArray())
{
if (key is "trace" or "response")
continue;
if (IsSensitiveName(key))
contexts[key] = Redacted;
else if (contexts[key] is IDictionary<string, object?> nested)
RedactObjectValues(nested);
else
contexts[key] = RedactValue(contexts[key])!;
}
}
@@ -124,8 +133,7 @@ internal static class SentryTelemetryPrivacy
continue;
}
if (values[key] is IDictionary<string, object?> nested)
RedactObjectValues(nested);
values[key] = RedactValue(values[key]);
}
}
@@ -141,11 +149,48 @@ internal static class SentryTelemetryPrivacy
continue;
}
if (values[key] is IDictionary<string, object?> nested)
RedactObjectValues(nested);
setValue(key, RedactValue(values[key])!);
}
}
private static object? RedactValue(object? value)
{
if (value is IDictionary<string, object?> mutableDictionary)
{
RedactObjectValues(mutableDictionary);
return value;
}
if (value is IReadOnlyDictionary<string, object?> readOnlyDictionary)
{
var sanitized = new Dictionary<string, object?>(StringComparer.Ordinal);
foreach (var pair in readOnlyDictionary)
sanitized[pair.Key] = IsSensitiveName(pair.Key) ? Redacted : RedactValue(pair.Value);
return sanitized;
}
if (value is System.Collections.IDictionary dictionary)
{
var sanitized = new Dictionary<string, object?>(StringComparer.Ordinal);
foreach (System.Collections.DictionaryEntry entry in dictionary)
{
if (entry.Key is not string key)
return Redacted;
sanitized[key] = IsSensitiveName(key) ? Redacted : RedactValue(entry.Value);
}
return sanitized;
}
if (value is System.Collections.IEnumerable and not string)
return Redacted;
// Arbitrary objects may serialize properties containing credentials under unknown names.
// Keep primitive values; discard unsupported object graphs rather than emit them unsanitized.
return value is null or string or bool or byte or sbyte or short or ushort or int or uint or long or ulong or float or double or decimal
? value
: Redacted;
}
private static bool IsSensitiveName(string name)
{
var normalized = name.Replace("-", string.Empty, StringComparison.Ordinal)