security: sanitize Sentry request environment metadata (#411)
Heimdall Gitea / Detect CI scope (pull_request) Successful in 1m12s
Heimdall Gitea / Build and tests (pull_request) Successful in 22m21s
Heimdall Gitea / Build and scan agent image (pull_request) Skipped
Heimdall Gitea / Build and scan NVIDIA Agent image (pull_request) Skipped
Heimdall Gitea / Build and scan server image (pull_request) Successful in 10m53s
Heimdall Gitea / Publish versioned installer release (pull_request) Skipped
Heimdall Gitea / CI policy (pull_request) Successful in 1s
Heimdall Gitea / Detect CI scope (pull_request) Successful in 1m12s
Heimdall Gitea / Build and tests (pull_request) Successful in 22m21s
Heimdall Gitea / Build and scan agent image (pull_request) Skipped
Heimdall Gitea / Build and scan NVIDIA Agent image (pull_request) Skipped
Heimdall Gitea / Build and scan server image (pull_request) Successful in 10m53s
Heimdall Gitea / Publish versioned installer release (pull_request) Skipped
Heimdall Gitea / CI policy (pull_request) Successful in 1s
This commit is contained in:
1 parent
26c9ae5ebd
commit
bc2bff96fb
3 files changed
+14
-2
No files matched your search
@@ -5,7 +5,7 @@ description: Keep Heimdall Sentry events free of authentication material while p
|
||||
|
||||
# Sentry telemetry privacy
|
||||
|
||||
Sentry event and transaction processing are configured in `src/Heimdall.Web/Program.cs`. `SetBeforeSend` and `SetBeforeSendTransaction` are separate SDK callbacks, so apply `SentryTelemetryPrivacy` to both. Before either payload is sent, remove or redact request/response authentication headers, cookies, query strings, bodies, URL user information, and sensitive values in event extras, transaction contexts, tags, spans, and breadcrumbs. Keep the helper in the Web boundary; do not move request telemetry into Domain or Application.
|
||||
Sentry event and transaction processing are configured in `src/Heimdall.Web/Program.cs`. `SetBeforeSend` and `SetBeforeSendTransaction` are separate SDK callbacks, so apply `SentryTelemetryPrivacy` to both. Before either payload is sent, filter request `Headers`, `Env`, and `Other` maps; remove request/response cookies, query strings, and bodies; strip URL user information; and filter sensitive values in event extras, transaction contexts, tags, spans, and breadcrumbs. Keep the helper in the Web boundary; do not move request telemetry into Domain or Application.
|
||||
|
||||
When changing this behavior:
|
||||
|
||||
@@ -13,6 +13,9 @@ When changing this behavior:
|
||||
- Treat header names case-insensitively and normalize common separators before matching names that indicate authorization, API keys, tokens, secrets, passwords, credentials, or cookies.
|
||||
- Clear entire fields such as cookie strings, query strings, and request bodies when selective redaction could miss nested or encoded credentials. Strip URL user information, query, and fragment while retaining the safe path.
|
||||
- Apply the same sensitive-key filtering to event extras and breadcrumbs. Preserve the existing rate-limit breadcrumb filter.
|
||||
- Recursively inspect string-keyed maps in extras and custom contexts. Replace arrays, other collections, and opaque object graphs with `[Filtered]` instead of allowing uninspected JSON serialization; retain safe primitive values and safe map entries.
|
||||
- Filter sensitive-name tags on both `SentryEvent` and `SentryTransaction`; sanitize trace custom data, response headers, and span data/tags.
|
||||
- Include synthetic request `env`/`other`, sensitive event tags, nested maps, arrays, and opaque values in serializer-level tests.
|
||||
- Never copy actual event headers, API keys, cookies, tokens, or request bodies into issue comments, test fixtures, logs, or acceptance evidence. Record only field names and synthetic test outcomes.
|
||||
|
||||
## Acceptance
|
||||
|
||||
@@ -98,6 +98,8 @@ internal static class SentryTelemetryPrivacy
|
||||
return;
|
||||
|
||||
RedactStringValues(request.Headers);
|
||||
RedactStringValues(request.Env);
|
||||
RedactStringValues(request.Other);
|
||||
request.Cookies = null;
|
||||
request.Url = StripQueryAndUserInfo(request.Url);
|
||||
request.QueryString = null;
|
||||
|
||||
@@ -19,6 +19,8 @@ public sealed class SentryTelemetryPrivacyTests
|
||||
"x-api-key": "{{apiKey}}",
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
"env": { "AUTHORIZATION": "SENTINEL_ENV_AUTH_411", "REMOTE_ADDR": "192.0.2.1" },
|
||||
"other": { "access_token": "SENTINEL_OTHER_TOKEN_411", "safe": "preserved" },
|
||||
"cookies": "session={{cookie}}",
|
||||
"data": { "access_token": "SENTINEL_BODY_TOKEN_411" }
|
||||
},
|
||||
@@ -37,6 +39,10 @@ public sealed class SentryTelemetryPrivacyTests
|
||||
Assert.Same(sentryEvent, sanitized);
|
||||
Assert.Equal("[Filtered]", sanitized.Request!.Headers!["x-api-key"]);
|
||||
Assert.Equal("application/json", sanitized.Request.Headers["Content-Type"]);
|
||||
Assert.Equal("[Filtered]", sanitized.Request.Env!["AUTHORIZATION"]);
|
||||
Assert.Equal("192.0.2.1", sanitized.Request.Env["REMOTE_ADDR"]);
|
||||
Assert.Equal("[Filtered]", sanitized.Request.Other!["access_token"]);
|
||||
Assert.Equal("preserved", sanitized.Request.Other["safe"]);
|
||||
Assert.Null(sanitized.Request.Cookies);
|
||||
Assert.Equal("https://central.example/api/agents", sanitized.Request.Url);
|
||||
Assert.Null(sanitized.Request.QueryString);
|
||||
@@ -94,7 +100,7 @@ public sealed class SentryTelemetryPrivacyTests
|
||||
"contexts": {
|
||||
"trace": { "type": "trace", "data": { "api_key": "SENTINEL_TRANSACTION_TRACE_411", "safe": "preserved" } },
|
||||
"response": { "type": "response", "cookies": "session=SENTINEL_TRANSACTION_RESPONSE_COOKIE_411", "headers": { "Set-Cookie": "SENTINEL_TRANSACTION_SET_COOKIE_411", "Content-Type": "application/json" }, "data": { "token": "SENTINEL_TRANSACTION_RESPONSE_BODY_411" } },
|
||||
"custom": { "clientSecret": "SENTINEL_TRANSACTION_CONTEXT_411", "mode": "safe" }
|
||||
"custom": { "clientSecret": "SENTINEL_TRANSACTION_CONTEXT_411", "mode": "safe", "metadata": [ { "token": "SENTINEL_CONTEXT_ARRAY_411" } ] }
|
||||
},
|
||||
"breadcrumbs": [
|
||||
{ "message": "request", "type": "http", "category": "http.client", "data": { "Authorization": "SENTINEL_TRANSACTION_BREADCRUMB_411", "method": "GET" } }
|
||||
@@ -123,6 +129,7 @@ public sealed class SentryTelemetryPrivacyTests
|
||||
Assert.Null(sanitized.Contexts.Response.Data);
|
||||
Assert.Equal("[Filtered]", ((IDictionary<string, object?>)sanitized.Contexts["custom"])["clientSecret"]);
|
||||
Assert.Equal("safe", ((IDictionary<string, object?>)sanitized.Contexts["custom"])["mode"]);
|
||||
Assert.Equal("[Filtered]", ((IDictionary<string, object?>)sanitized.Contexts["custom"])["metadata"]);
|
||||
Assert.Equal("[Filtered]", sanitized.Breadcrumbs.Single().Data!["Authorization"]);
|
||||
Assert.Equal("GET", sanitized.Breadcrumbs.Single().Data!["method"]);
|
||||
Assert.Equal("[Filtered]", sanitized.Tags["api_key"]);
|
||||
|
||||
Reference in new issue
Block a user