Skip to main content

redact_text

Function redact_text 

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

Redact every credential found in text.

Two passes run in order:

  1. URLs. In each scheme:// token the password of the userinfo (or the whole userinfo when it has no user: part) becomes REDACTED. The userinfo ends at the last @ before the end of the line or the next scheme://, so a password holding an unencoded / ? # @, space or quote is still hidden. A comma separated list of URLs is redacted URL by URL.
  2. key=value pairs anywhere in the text: URL query parameters, libpq DSNs (password=x), ADO strings (;Pwd=x;) and the like. When is_secret_key(key) holds, the value becomes REDACTED. A quoted value is redacted up to its closing quote; an unquoted one up to whitespace, ; or &.

Args: text: Free text that may hold connection strings.

Returns: The text with every recognised secret replaced.