EasySecurityPython 3

Secret Redactor

Redact common emails, bearer tokens, and API-key-shaped strings from log text.

25m3 sample tests6 hidden tests

Redact common secret-like values from logs before they are stored.

Requirements

  • Define redact_secrets(text).
  • Replace email addresses with <email>. Surrounding angle brackets in the source (for example Contact <[email protected]>) are left in place, so the result may look like Contact <<email>>.
  • Replace bearer tokens like Bearer abc123 with Bearer <redacted>. The token body runs until whitespace or a terminator in {',', ';'} (so punctuation after the token is preserved).
  • Replace keys beginning with sk- followed by at least eight letters, digits, _, or - with sk-<redacted>.
  • Return the redacted string.
  • Preserve other text unchanged.

Example

python
1assert redact_secrets("Authorization: Bearer abc123") == "Authorization: Bearer <redacted>"

Constraints

  • Use standard-library Python only.
  • Don't over-redact short strings like sk-test.
  • Redaction should be deterministic.

Editor