AlgoMaster Logo
AlgoMasterRedact Sensitive Structured Log Fieldsmedium

Redact Sensitive Structured Log Fields

medium

Structured logs make fields easy to query, but they also make secrets easy to leak. A redactor should use the field schema, preserve safe context, and avoid broad substring rules that destroy useful data.

Design a StructuredLogRedactor class:

  • StructuredLogRedactor() creates a stateless redactor.
  • String[] redactValues(String[] keys, String[] values) returns values aligned with keys, replacing sensitive values with exactly [REDACTED].
  • String[] redactedKeys(String[] keys) returns the sensitive keys, preserving their original spelling and sorting them in ascending ASCII order.

A key is sensitive when its final dot-separated segment, compared case-insensitively, is exactly one of:

password, token, secret, authorization, or api_key.

Names such as token_count, password_hash, and secret_value are not sensitive.

Example 1:

Input:

Output:

Explanation: Only the final segment authorization is sensitive.

Example 2:

Input:

Output:

Explanation: Classification is case-insensitive, while token_count does not exactly match a sensitive name.

Constraints

  • 1 <= keys.length == values.length <= 10^4
  • Keys are unique, non-empty ASCII strings.
  • 1 <= keys[i].length <= 100
  • 0 <= values[i].length <= 10^4
  • Inputs are not modified.
  • At most 100 total method calls are made.
Hints

Loading...
CallReturns
new StructuredLogRedactor()null
redactValues(["timestamp","user.email","request.authorization","message"], ["1700","a@example.com","Bearer abc","ok"])["1700","a@example.com","[REDACTED]","ok"]
redactedKeys(["timestamp","user.email","request.authorization","message"])["request.authorization"]

Only the final segment authorization is sensitive; the aligned value is replaced while the key itself is preserved.

Run checks these cases. Submit also runs a larger hidden set.