Log Sanitizer
Statement
Goal
As a SecOps engineer, you must ensure that sensitive data never leaks into application logs.For the purposes of this task, tokens are defined as being bounded by non-alphanumeric characters or the beginning or end of the line.
Inspect a stream of server log lines and sanitize all occurrences of the following two patterns, subject to the overlapping rule:
1. Credit card numbers
Exactly four consecutive tokens, each consisting of exactly 4 digits and joined by
2. API token
A token
Overlapping rule
Overlapping occurrences of a single pattern should not be considered to fit the pattern and should remain unchanged. For example, this applies to:
• Five or more consecutive tokens, each consisting of exactly 4 digits and joined by
•
If
All other log characters must remain untouched.
Input
Line 1: An integer N for the number of log lines.
Next N lines: A string line representing a raw log entry.
Next N lines: A string line representing a raw log entry.
Output
N lines: The sanitized log entries.
Constraints
1 ≤ N ≤ 10
line contains between 1 and 100 printable ASCII characters.
line contains between 1 and 100 printable ASCII characters.
Example
Input
4 [SYSTEM] Server running on port 8080 with 0 errors. [TRANSFER] Moved funds from 8291-3849-1029-4820 to 5731-4921-5829-1039 confirmed. 192.168.1.1 - GET /auth?token=abC123XyZ HTTP/1.1 2023-10-01 12:00:00 INFO: Session initiated, token=validToken123 login success
Output
[SYSTEM] Server running on port 8080 with 0 errors. [TRANSFER] Moved funds from [CARD_REDACTED] to [CARD_REDACTED] confirmed. 192.168.1.1 - GET /auth?token=[TOKEN_REDACTED] HTTP/1.1 2023-10-01 12:00:00 INFO: Session initiated, token=[TOKEN_REDACTED] login success
Tags
Strings, Parsing, Regular expressions
Difficulty
Easy
Test cases
Test 1: Simple examples Test
Input
4
[SYSTEM] Server running on port 8080 with 0 errors.
[TRANSFER] Moved funds from 8291-3849-1029-4820 to 5731-4921-5829-1039 confirmed.
192.168.1.1 - GET /auth?token=abC123XyZ HTTP/1.1
2023-10-01 12:00:00 INFO: Session initiated, token=validToken123 login success
Output
[SYSTEM] Server running on port 8080 with 0 errors.
[TRANSFER] Moved funds from [CARD_REDACTED] to [CARD_REDACTED] confirmed.
192.168.1.1 - GET /auth?token=[TOKEN_REDACTED] HTTP/1.1
2023-10-01 12:00:00 INFO: Session initiated, token=[TOKEN_REDACTED] login success
Validator 1 Validator
Input
4
[INIT] September 7, 2026: system startup clean.
[SYNC] Pairing devices linked to 1029-3847-5610-2938 and 4756-1029-3847-5610 done.
10.0.0.5 - POST /refresh?token=SecretSession99 HTTP/2.0
[INFO] External API call with token=MySecret777 executed successfully
Output
[INIT] September 7, 2026: system startup clean.
[SYNC] Pairing devices linked to [CARD_REDACTED] and [CARD_REDACTED] done.
10.0.0.5 - POST /refresh?token=[TOKEN_REDACTED] HTTP/2.0
[INFO] External API call with token=[TOKEN_REDACTED] executed successfully
Test 2: Start and end of line Test
Input
2
1111-2222-3333-4444 is expired.
[PAYMENT] Successfully processed transaction with card 4928-1029-3847-5610
Output
[CARD_REDACTED] is expired.
[PAYMENT] Successfully processed transaction with card [CARD_REDACTED]
Validator 2 Validator
Input
2
0000-1111-2222-3333 is blocked.
[BILLING] User 8891 charged 50 USD on 3847-5610-2938-4756
Output
[CARD_REDACTED] is blocked.
[BILLING] User 8891 charged 50 USD on [CARD_REDACTED]
Test 3: Non-alphanumeric boundaries Test
Input
7
php?my_token=abc&token=valid123_extra
ERROR Negative balance on -8291-3849-1029-4820
TRACE Range overflow on 8291-3849-1029-4820-
TRACE: req_id=42;card=7482-1928-3746-5019;token=AdminPass99;
DEBUG /audit?token=token_beta9
2026-09-08T09:03:00Z: [token=SecretApiKey]; card: 0093-5648-7367-2174!
LOG 1234#1111-2222-3333-4444#5678 END
Output
php?my_token=[TOKEN_REDACTED]&token=[TOKEN_REDACTED]_extra
ERROR Negative balance on -[CARD_REDACTED]
TRACE Range overflow on [CARD_REDACTED]-
TRACE: req_id=42;card=[CARD_REDACTED];token=[TOKEN_REDACTED];
DEBUG /audit?token=[TOKEN_REDACTED]_beta9
2026-09-08T09:03:00Z: [token=[TOKEN_REDACTED]]; card: [CARD_REDACTED]!
LOG 1234#[CARD_REDACTED]#5678 END
Validator 3 Validator
Input
7
url/endpoint;token=Key999!done
ERROR Reverting state to -4756-1029-3847-5610
TRACE Trailing dash in 4756-1029-3847-5610-
DEBUG Payload: mode=live;cnum=2938-4756-1029-3847;token=LiveKey987;
INFO /config?token=token_prod44
2049-06-04T07:00:05Z: <token=AdminPass99> and {4146-3499-5862-8507}
INFO 9999/4756-1029-3847-5610/1111 DONE
Output
url/endpoint;token=[TOKEN_REDACTED]!done
ERROR Reverting state to -[CARD_REDACTED]
TRACE Trailing dash in [CARD_REDACTED]-
DEBUG Payload: mode=live;cnum=[CARD_REDACTED];token=[TOKEN_REDACTED];
INFO /config?token=[TOKEN_REDACTED]_prod44
2049-06-04T07:00:05Z: <token=[TOKEN_REDACTED]> and {[CARD_REDACTED]}
INFO 9999/[CARD_REDACTED]/1111 DONE
Test 4: Non-matching - credit card numbers Test
Input
7
ERROR 404: Resource /card/4921-5829-1039 not found
INFO Session UUID A8291-3849-1029-4820 started
FAIL Parsing error at string 8291--3849--1029--4820
TRACE Invalid checksum for entry 8291-3849-1029-48209
DEBUG Account 998291-3849-1029-4820 locked
WARN Receipt 8291-3849-1029-4820XYZ printed
[ERROR] Record 8123-4567-901-2345 does not match database schema.
Output
ERROR 404: Resource /card/4921-5829-1039 not found
INFO Session UUID A8291-3849-1029-4820 started
FAIL Parsing error at string 8291--3849--1029--4820
TRACE Invalid checksum for entry 8291-3849-1029-48209
DEBUG Account 998291-3849-1029-4820 locked
WARN Receipt 8291-3849-1029-4820XYZ printed
[ERROR] Record 8123-4567-901-2345 does not match database schema.
Validator 4 Validator
Input
7
ERROR 400: User ID 5610-2938-4756 invalid
INFO Key mismatch X4756-1029-3847-5610 detected
FAIL Bad delimiter in 3847--5610--2938--4756
TRACE Check length of 1029-3847-5610-29385
DEBUG Transaction 884756-1029-3847-5610 rejected
WARN Ticket number 4756-1029-3847-5610ABC
[WARN] Result: query 1111-222-3333-4444 returned 0 rows.
Output
ERROR 400: User ID 5610-2938-4756 invalid
INFO Key mismatch X4756-1029-3847-5610 detected
FAIL Bad delimiter in 3847--5610--2938--4756
TRACE Check length of 1029-3847-5610-29385
DEBUG Transaction 884756-1029-3847-5610 rejected
WARN Ticket number 4756-1029-3847-5610ABC
[WARN] Result: query 1111-222-3333-4444 returned 0 rows.
Test 5: Non-matching - API tokens Test
Input
5
GET /api/v1/user?Token=xyz987
INFO Generating backup for token_99XqZ
WARN Malformed request missing parameter token=
DEBUG: Incoming parameter notatoken=abc12345 mapped to null.
POST /check?token==invalid/token
Output
GET /api/v1/user?Token=xyz987
INFO Generating backup for token_99XqZ
WARN Malformed request missing parameter token=
DEBUG: Incoming parameter notatoken=abc12345 mapped to null.
POST /check?token==invalid/token
Validator 5 Validator
Input
5
POST /login payload: Token=secure12
INFO Deprecated field token_OldVal found
WARN Dropped connection due to empty token=
INFO: Event logged with identifier mytoken=123456.
GET /status?token==error$token
Output
POST /login payload: Token=secure12
INFO Deprecated field token_OldVal found
WARN Dropped connection due to empty token=
INFO: Event logged with identifier mytoken=123456.
GET /status?token==error$token
Test 6: Overlapping Test
Input
4
[WARN] Invalid format in payload: 1492-3850-9281-4029-5731
FATAL System dump: 1829-3847-5610-2938-4756-1029-3847-5610
DEBUG: Retry auth string ?token=token=892abc
ALERT Stack trace contains param token=token=token=Pass999
Output
[WARN] Invalid format in payload: 1492-3850-9281-4029-5731
FATAL System dump: 1829-3847-5610-2938-4756-1029-3847-5610
DEBUG: Retry auth string ?token=token=892abc
ALERT Stack trace contains param token=token=token=Pass999
Validator 6 Validator
Input
4
[INFO] Chain sync failed at block 3847-5610-2938-4756-1029
FATAL Memory leak 5610-2938-4756-1029-3847-5610-2938-4756
DEBUG: Parsing query params: &token=token=admin
WARN Duplicate query args found: token=token=token=SecretKey42
Output
[INFO] Chain sync failed at block 3847-5610-2938-4756-1029
FATAL Memory leak 5610-2938-4756-1029-3847-5610-2938-4756
DEBUG: Parsing query params: &token=token=admin
WARN Duplicate query args found: token=token=token=SecretKey42
Test 7: Overlapping with priority Test
Input
3
POST /checkout?token=8291-3849-1029-4820
POST /order?token=8291-3849-1029-4820-5731;done
POST /batch?token=8291-8291-3849-1029-4820-5731-6842;completed
Output
POST /checkout?token=[TOKEN_REDACTED]-3849-1029-4820
POST /order?token=[TOKEN_REDACTED]-[CARD_REDACTED];done
POST /batch?token=[TOKEN_REDACTED]-8291-3849-1029-4820-5731-6842;completed
Validator 7 Validator
Input
3
GET /payment?token=4756-1029-3847-5610
GET /verify?token=4756-1029-3847-5610-2938;ready
GET /archive?token=4756-4756-1029-3847-5610-2938-1029;finished
Output
GET /payment?token=[TOKEN_REDACTED]-1029-3847-5610
GET /verify?token=[TOKEN_REDACTED]-[CARD_REDACTED];ready
GET /archive?token=[TOKEN_REDACTED]-4756-1029-3847-5610-2938-1029;finished
Solution language
Solution
Stub generator input