Skip to content

Redaction

Credentials never leave the SDK in readable form: not in error messages, hook data, logger output, toString/debug/JSON forms of configs and secret values. Redaction replaces values with [REDACTED].

Rules

  • Sensitive headers (case-insensitive): authorization, proxy-authorization, cookie, set-cookie, and any name containing token, secret, password, api-key, apikey, key, auth, session, signature or credential.
  • Sensitive fields and query parameters (case-insensitive substring): password, passwd, secret, token, authorization, cookie, api_key, apikey, api-key, access_key, private_key, client_secret, credential, session, signature.
  • Known secrets: every error message passes through redactText with the secret values the client knows (token, passwords from the config, …); any occurrence of length ≥ 4 is replaced.
  • Vendor error text is redacted and truncated to 300 characters.

The Secret type

Credentials in configuration are wrapped in Secret. Its string, debug and JSON forms print [REDACTED]; reveal() returns the value when you really need it.

import { Secret } from "@grow-codes/jaeger";

const token = new Secret("s3cr3t-value");
String(token);         // "[REDACTED]"
JSON.stringify(token); // "\"[REDACTED]\""
token.reveal();        // "s3cr3t-value"
use grow_jaeger::Secret;

let token = Secret::new("s3cr3t-value");
format!("{token:?}");  // "[REDACTED]"
token.expose_secret(); // "s3cr3t-value" (also: reveal())
// The memory is zeroized when the Secret is dropped.
token := jaeger.NewSecret("s3cr3t-value")
fmt.Sprint(token)        // "[REDACTED]"
fmt.Sprintf("%#v", token) // "[REDACTED]"
token.Reveal()           // "s3cr3t-value"
// slog and encoding/json also see [REDACTED].
from grow_jaeger import Secret

token = Secret("s3cr3t-value")
str(token)               # "[REDACTED]"; repr() never shows the value either
token.reveal()           # "s3cr3t-value"
Secret token = Secret.of("s3cr3t-value".toCharArray());
token.toString();   // "[REDACTED]"
token.reveal();     // "s3cr3t-value"
token.clear();      // wipes the char[] backing store

Redaction helpers

The helpers are public so your own code (logs, hooks, error reports) can apply the same rules.

Function What it does
redactHeaders(headers) copy with sensitive header values replaced
redactUrl(url) URL with sensitive query values replaced (and user info removed)
redactFields(map, extraKeys?) recursive copy of nested maps/lists with sensitive keys replaced
redactText(text, knownSecrets) replaces every known secret value (length ≥ 4)
import { redactFields, redactHeaders, redactText, redactUrl } from "@grow-codes/jaeger";

redactHeaders({ Authorization: "Bearer abc", Accept: "application/json" });
// { authorization: "[REDACTED]", accept: "application/json" }
redactUrl("https://api.example.com/v1?token=abc&page=2");
// "https://api.example.com/v1?token=[REDACTED]&page=2"
redactFields({ user: "ana", password: "x", nested: { apiKey: "y" } });
redactText("login failed for s3cr3t-value", ["s3cr3t-value"]);
// "login failed for [REDACTED]"
use grow_jaeger::core::redact::{redact_fields, redact_headers, redact_text, redact_url};

let headers = redact_headers([("Authorization", "Bearer abc"), ("Accept", "application/json")]);
let url = redact_url("https://api.example.com/v1?token=abc&page=2");
let fields = redact_fields(&serde_json::json!({"password": "x", "nested": {"apiKey": "y"}}), &[]);
let text = redact_text("login failed for s3cr3t-value", &["s3cr3t-value"]);
h := jaeger.RedactHeaderMap(map[string]string{"Authorization": "Bearer abc"})
u := jaeger.RedactURL("https://api.example.com/v1?token=abc&page=2")
f := jaeger.RedactFields(map[string]any{"password": "x", "nested": map[string]any{"apiKey": "y"}})
t := jaeger.RedactText("login failed for s3cr3t-value", []string{"s3cr3t-value"})
// RedactHeaders(http.Header) works on net/http headers.
from grow_jaeger import redact_fields, redact_headers, redact_text, redact_url

redact_headers({"Authorization": "Bearer abc", "Accept": "application/json"})
redact_url("https://api.example.com/v1?token=abc&page=2")
redact_fields({"password": "x", "nested": {"apiKey": "y"}})
redact_text("login failed for s3cr3t-value", ["s3cr3t-value"])
import codes.grow.packages.jaeger.core.Redaction;

Redaction.redactHeaders(Map.of("Authorization", "Bearer abc"));
Redaction.redactUrl("https://api.example.com/v1?token=abc&page=2");
Redaction.redactFields(Map.of("password", "x", "nested", Map.of("apiKey", "y")));
Redaction.redactText("login failed for s3cr3t-value", List.of("s3cr3t-value"));

Logs

Do not log revealed secrets yourself: the SDK can only redact values it knows about.