Class HeaderSanitizer
Provides a helper to remove sensitive or dangerous data from message headers. This is particularly useful before logging or persisting headers.
Inherited Members
Namespace: Chapar.Core.Utilities
Assembly: Chapar.Core.dll
Syntax
public static class HeaderSanitizer
Fields
| Edit this page View SourceDangerousChars
Declaration
public static readonly char[] DangerousChars
Field Value
| Type | Description |
|---|---|
| char[] |
Methods
| Edit this page View SourceSanitize(IDictionary<string, object?>?, IEnumerable<string>?, IEnumerable<string>?)
Sanitizes a dictionary of headers by:
- Replacing the value of any key in the built‑in set of sensitive headers set with "[REDACTED]".
- Removing carriage return, line feed, and null characters from all header values.
- Optionally restricting headers to a pre‑defined set of allowed keys.
The original dictionary is not modified.
Declaration
public static IDictionary<string, object?> Sanitize(IDictionary<string, object?>? headers, IEnumerable<string>? additionalSensitiveKeys = null, IEnumerable<string>? allowedKeys = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IDictionary<string, object> | headers | The headers to sanitize. Can be null. |
| IEnumerable<string> | additionalSensitiveKeys | Additional sensitive keys to redact (on top of the built‑in set). |
| IEnumerable<string> | allowedKeys | If provided, only headers whose keys are in this set will be included in the result. If null or empty, all non‑redacted headers are kept. |
Returns
| Type | Description |
|---|---|
| IDictionary<string, object> | A new, safe dictionary. Never returns null. |