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 <= 1000 <= values[i].length <= 10^4- Inputs are not modified.
- At most
100 total method calls are made.