Scrivio Interview library
ScenarioIntermediate7 min read · updated 12 November 2026

A security review finds bearer tokens and passwords in logs from HTTP client debug logging and from exception messages that include request bodies. Logs are already shipped to a central store kept for 90 days. Describe your immediate actions and the lasting fix.

Immediately, I would treat it as a security incident: rotate every exposed token and credential, restrict access to the affected log indexes, and purge or redact the stored events through the incident process. The lasting fix is to switch off HTTP client wire and header debug logging in production, stop putting request bodies and headers into exception messages, add masking for known secret patterns in the encoder and again in the pipeline, and add tests and scanners that catch secrets in log output before and after release.

Why this question is asked

Secrets in logs are worse than most data leaks because a bearer token or password is not just information, it is access. Anyone who can search the log store for 90 days of history can potentially act as those users or services. Interviewers ask this scenario to see whether we put containment first, before the satisfying engineering work, and whether the lasting fix addresses every way the secrets got in. In this answer, we will order the immediate actions, find the two sources in the code and configuration, add masking in two layers, and build the tests and scanning that keep it from happening again.

1Containment Comes First

The logs have been shipped and kept for up to 90 days, so we must assume the secrets have been seen by everyone with access to those indexes, and possibly copied into tickets or exports. Fixing the code first would leave valid credentials exposed for days. So the order is: contain, then clean, then fix.

Rotation is the most important step. Every bearer token, API key and password that appears in the logs must be revoked and replaced, starting with the most powerful ones, such as service credentials with write access. Short-lived user tokens may already have expired, but refresh tokens and long-lived service tokens almost certainly have not. Next, access to the affected indexes is restricted to the incident team so the exposure stops growing. Then the stored events are purged or redacted according to the incident process; many log platforms support delete-by-query or reindexing with a redaction step, and backups and exports must be included. This is also the moment to involve security, and privacy or legal if passwords of real users are involved.

Step throughOrder of the immediate actions
  1. Open a security incidentsecurity owns it; engineering supports
  2. Rotate exposed tokens and credentialsmost powerful first
  3. Restrict access to affected indexes
  4. Stop new leaksturn off wire logging now
  5. Purge or redact stored eventsinclude exports and backups
  6. Lasting fixes and verification

6 steps in order. Play them, or step through them one at a time.

2Source 1: HTTP Client Debug Logging

HTTP clients have very detailed debug loggers that print headers and sometimes full bodies, which include Authorization headers and login forms. Someone enabled them in production, perhaps through a logging.level property that was meant to be temporary. Typical loggers are org.apache.hc.client5.http.wire and org.apache.hc.client5.http.headers for Apache HttpClient 5, reactor.netty.http.client with wiretap enabled for WebClient on Reactor Netty, and OkHttp's HttpLoggingInterceptor at BODY or HEADERS level.

The fix is to pin those loggers off in the shared production configuration, so a property in one service cannot switch them on, and to remove wiretap and logging interceptors from production builds.

Properties
# shared base configuration, production profile
logging.level.org.apache.hc.client5.http.wire=OFF
logging.level.org.apache.hc.client5.http.headers=OFF
logging.level.reactor.netty.http.client=WARN
logging.level.org.springframework.web.reactive.function.client.ExchangeFunctions=INFO
// before: DEBUG org.apache.hc.client5.http.headers - http-outgoing-3 >> Authorization: Bearer eyJhbGciOi...
// after: nothing is written for headers or wire data

If engineers need to see traffic during development, an interceptor that logs method, URL path, status and duration, but never headers or bodies, gives most of the value safely.

3Source 2: Exception Messages That Carry Request Data

The second source is quieter. Code builds an exception message from the request it was processing, and the message ends up in an ERROR log with its stack trace, no debug setting required.

Java
// Before: the whole request, including the password field, goes into the message
throw new LoginException("Login failed for request " + requestBody);
// ERROR ... LoginException: Login failed for request {"user":"asha","password":"Winter2026!"}
// After: a safe message with identifiers only
throw new LoginException("Login failed for user id " + userId + ", reason " + reason);
// ERROR ... LoginException: Login failed for user id 4417, reason BAD_CREDENTIALS

The rule is that exception messages are log output, so they follow the same data rules as log lines: identifiers and error codes, never bodies, headers or credentials. The same applies to error responses mapped from exceptions, which should return a safe message to the client. Some HTTP client exceptions include the response body in their message by default, so check how your client formats errors and wrap them if needed.

4Masking in Two Layers

Even with the sources fixed, a new library or a new piece of code can bring secrets back, so we add masking as a safety net. The first layer is in the application's encoder, for example the logstash-logback-encoder masking decorator or a Log4j2 replace pattern, configured for known patterns: Authorization header values, Bearer followed by a token, JSON fields named password, secret or token, and card-like digit runs. The second layer is in the log pipeline, the collector or shipper, applying the same patterns to everything, including applications and third-party products that do not use our starter.

Two layers matter because each catches what the other misses: the encoder sees structured fields before serialisation, and the pipeline sees all sources.

XML
<jsonGeneratorDecorator class="net.logstash.logback.mask.MaskingJsonGeneratorDecorator">
<defaultMask>[redacted]</defaultMask>
<path>password</path>
<path>authorization</path>
<value>(?i)bearer\s+[A-Za-z0-9._~+/=-]+</value>
</jsonGeneratorDecorator>
// "Calling partner with Bearer eyJhbGciOi..." -> "Calling partner with [redacted]"

5Tests, Scanning and Alerts

Finally, we make the fix verifiable. In CI, an integration test runs a login and a partner call through the real logging configuration, captures the output and fails if it contains the test password or token. A secret scanner, the same kind used on source code, runs over the log output of the integration test suite. In production, the log store has saved searches that alert the security team on patterns such as 'Bearer ' followed by a long token or 'password' inside a JSON message, so a regression is found in minutes rather than at the next review.

Step throughDefences against secrets in logs
  1. Code rulessafe exception messages, identifiers only
  2. Configurationwire and header loggers pinned off in production
  3. Encoder maskingknown patterns and field names
  4. Pipeline maskingsame patterns for every source
  5. DetectionCI tests, scanners, alerts in the log store

5 layers, from the top down. Step through them one at a time.

6Follow-up questions

Who must be told when personal data has been in logs for months?

Inside the company: the security incident team, the data protection officer or privacy team, and legal, who decide whether it counts as a personal data breach under laws such as GDPR. Under GDPR, if the exposure is a breach likely to result in a risk to people, the supervisory authority must be notified within 72 hours of becoming aware of it, and the affected people directly if the risk is high; check the exact obligations with legal. If the company processes data for customers, contracts usually require telling those customers. For card data, the PCI incident process involves the acquiring bank and card brands. Engineers' job is to provide accurate facts quickly: what data, how many people, which systems, who had access, and for how long.

Is it enough to delete the log events?

No. Deletion limits further exposure, but anyone who already read or exported the logs still has the secrets, which is why rotation comes first. Deletion must also cover copies: backups, exports, tickets and any secondary system such as a SIEM that received the same events.

Why not just tell developers to be careful?

Because the leaks came from configuration and from code written for other purposes, not from someone deciding to log a password. Pinned configuration, safe exception patterns, masking and detection protect us when someone is not careful, which will eventually happen.

7Conclusion

In this answer, we handled secrets found in 90 days of shipped logs. We contained first: rotating every exposed token and credential, restricting access to the affected indexes and purging or redacting stored events, including copies. Then we fixed the sources by pinning HTTP client wire and header loggers off in production and keeping request bodies and headers out of exception messages, added masking in both the encoder and the pipeline, and made it verifiable with CI tests, secret scanning and alerts in the log store.

What to say in the interviewAbout 90 seconds aloud

Open with

I'd treat this as a security incident and contain it before touching code. First, rotate every token and credential that appears in the logs, starting with long-lived service credentials, because anyone with access to 90 days of logs may have seen them.

Then, if they want more

At the same time, restrict access to the affected indexes to the incident team, and then purge or redact the stored events through the incident process, including exports, tickets and backups. I'd involve security straight away, and privacy and legal if user passwords or personal data are involved. Then the sources.

The first is HTTP client debug logging, like Apache HttpClient's wire and headers loggers or Reactor Netty wiretap, which print Authorization headers and bodies, so I'd pin them off in the shared production configuration so one service's property can't turn them on.

The second is exception messages built from request bodies; the rule becomes that exception messages contain identifiers and error codes, never bodies, headers or credentials. Then masking as a safety net in two layers: in the encoder, masking Bearer tokens, Authorization values and password fields, and the same patterns in the log pipeline for every source.

Finally detection: an integration test that logs a login and fails if the test password shows up, secret scanning on test log output, and alerts in the log store for Bearer tokens, so a regression is found in minutes.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "A security review finds bearer tokens and passwords in logs from HTTP client debug...": https://scrivio-interview-library.netlify.app/java/java-logging/36ec598342/