Skip to main content

redact_secrets

Function redact_secrets 

Source
pub fn redact_secrets(text: &str) -> String
Expand description

Mask credential-shaped substrings in text.

Recognizes:

  • Authorization: <scheme> <token> and bare Bearer <token>
  • x-api-key: <value>
  • OpenAI-style sk-… keys (20+ word characters after the prefix)
  • JSON fields named apiKey / api_key / apikey with a string value

Returns the text with each matched secret replaced by [REDACTED], leaving the surrounding key or scheme intact so the structure stays readable.