cybersecurity · intermediate · ~15 min · safe pentest lab

Redact secrets from a log line

Practise in-place string editing without leaking original data.

Challenge

Scrub secret values out of a log line in place, so cleartext credentials never reach the log file.

Task

Implement void redact_secrets(char *line) that edits line in place, replacing each secret value with ***:

  • the value after password= (everything up to the next space or end of line), and
  • the value after token= (same: up to the next space or end of line).

The key text (password= / token=) stays; only the value is replaced.

Input

  • line: a NUL-terminated, mutable log line the grader provides. Its buffer is large enough to hold the redacted result, so you may shift characters as needed. At most one password= and one token= appear.

Output

No return value. line is modified in place to contain the redacted text.

Example

"user=alice password=hunter2 token=abc123"   ->   "user=alice password=*** token=***"
"no secrets here"                             ->   "no secrets here"   (unchanged)
"password="                                   ->   "password=***"      (empty value)

Edge cases

  • A key absent from the line: leave it untouched.
  • An empty value (password= at end of line): still becomes password=***.

Input format

A NUL-terminated mutable log line; buffer is large enough for the result.

Output format

No return; line is edited in place with each secret value replaced by ***.

Constraints

Edit in place; keep the key, replace only the value up to the next space or end.

Starter code

#include <string.h>

void redact_secrets(char *line) {
    /* TODO */
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.