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
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:
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)
|
||||
|
||||
@@ -24,7 +24,9 @@ public sealed class SentryTelemetryPrivacyTests
|
||||
},
|
||||
"extra": {
|
||||
"safeValue": "preserved",
|
||||
"nested": { "clientSecret": "SENTINEL_EXTRA_SECRET_411" }
|
||||
"nested": { "clientSecret": "SENTINEL_EXTRA_SECRET_411" },
|
||||
"array": [ { "accessToken": "SENTINEL_ARRAY_TOKEN_411", "safe": "preserved" } ],
|
||||
"opaque": { "credential": "SENTINEL_OPAQUE_CREDENTIAL_411" }
|
||||
}
|
||||
}
|
||||
""");
|
||||
@@ -41,6 +43,8 @@ public sealed class SentryTelemetryPrivacyTests
|
||||
Assert.Null(sanitized.Request.Data);
|
||||
Assert.Equal("preserved", sanitized.Extra!["safeValue"]);
|
||||
Assert.Equal("[Filtered]", ((IDictionary<string, object?>)sanitized.Extra["nested"]!)["clientSecret"]);
|
||||
Assert.Equal("[Filtered]", sanitized.Extra["array"]);
|
||||
Assert.Equal("[Filtered]", ((IDictionary<string, object?>)sanitized.Extra["opaque"]!)["credential"]);
|
||||
|
||||
var serialized = SerializeEvent(sanitized);
|
||||
Assert.DoesNotContain(apiKey, serialized, StringComparison.Ordinal);
|
||||
@@ -132,6 +136,22 @@ public sealed class SentryTelemetryPrivacyTests
|
||||
Assert.DoesNotContain("SENTINEL_", serialized, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Sanitize_RedactsSensitiveEventTagsInSdkPayload()
|
||||
{
|
||||
using var document = System.Text.Json.JsonDocument.Parse("""
|
||||
{ "message": "synthetic", "tags": { "api_key": "SENTINEL_EVENT_TAG_411", "method": "GET" } }
|
||||
""");
|
||||
var sentryEvent = SentryEvent.FromJson(document.RootElement);
|
||||
|
||||
var sanitized = SentryTelemetryPrivacy.Sanitize(sentryEvent);
|
||||
|
||||
Assert.Equal("[Filtered]", sanitized.Tags["api_key"]);
|
||||
Assert.Equal("GET", sanitized.Tags["method"]);
|
||||
var serialized = SerializeEvent(sanitized);
|
||||
Assert.DoesNotContain("SENTINEL_EVENT_TAG_411", serialized, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
private static string SerializeTransaction(SentryTransaction transaction)
|
||||
{
|
||||
using var stream = new MemoryStream();
|
||||
|
||||
Reference in new issue
Block a user