Scrivio Interview library
LeadershipPrincipal6 min read · updated 12 November 2026

How would you balance exposing detailed error information to help clients against the security risk of leaking internals, as a company-wide policy?

The policy is that an error response contains what the client can act on, such as field errors, stable codes and retry advice, and never contains stack traces, SQL, internal class names or hostnames. A correlation id in every response lets support find the full details in our logs, so we do not need to put them in the response. Internal APIs may expose more detail, but under the same rules for secrets, and security reviews the policy and tests it.

Why this question is asked

Developers want detailed errors because they save debugging time, and security teams want minimal errors because every detail can help an attacker. Both are right, which is why this becomes a company policy question rather than a per-service choice. Interviewers ask it to see whether we can turn a real tension into rules that teams can follow and verify. In this answer, we will look at what leaks and why it matters, then build the policy: what clients get, what they never get, how the correlation id resolves the tension, how internal APIs differ, and how the policy is reviewed and tested.

1Two Readers of Every Error

An error response has two kinds of readers. The legitimate client wants to fix its request or decide whether to retry. An attacker probes the API with odd input to learn how it is built. The same response reaches both, so the question is always which details help the first without helping the second.

Details that help attackers are surprisingly ordinary. A stack trace reveals the framework and library versions, which can be matched against known vulnerabilities. An SQL fragment reveals table and column names and confirms that input reaches the database, the first step of an injection attack. An internal hostname or IP maps the network. A message such as user not found, as opposed to wrong password, confirms which accounts exist. None of these help a legitimate client do anything differently.

2What Clients Get: Details They Can Act On

The test for every field is simple: can the client act on it? Field-level validation errors pass that test, because the client can correct the field. A stable error code passes, because the client can branch on it, for example showing a top-up screen for insufficient_funds. Retry advice passes: a 503 with a Retry-After header, or a retryable flag, tells the client whether to try again and when.

YAML
HTTP/1.1 503 Service Unavailable
Retry-After: 30
Content-Type: application/problem+json
{
"type": "https://errors.example.com/temporarily-unavailable",
"title": "Service temporarily unavailable",
"status": 503,
"code": "temporarily_unavailable",
"retryable": true,
"traceId": "4bf92f3577b34da6"
}

Notice what is missing: the name of the downstream system that timed out, the timeout value, the exception class. The client cannot act on any of those, but our logs have all of them under the same trace id.

3What Clients Never Get

The never list is short and absolute, for public and internal APIs alike: stack traces, SQL statements and database error text, internal class and package names, hostnames, IP addresses and file paths, configuration values, and anything secret such as tokens, keys or passwords, including in echoed rejected values. Messages from third-party exceptions are never copied into a response, because we do not control what they contain.

Java
// Broken: leaks the database error text to the client
@ExceptionHandler(DataAccessException.class)
ProblemDetail onDb(DataAccessException ex) {
return ProblemDetail.forStatusAndDetail(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
// detail: "... ERROR: relation "customer_cards" does not exist ..."
}
// Fixed: generic text for the client, full detail in the log
@ExceptionHandler(DataAccessException.class)
ProblemDetail onDb(DataAccessException ex) {
log.error("Database failure", ex); // stack trace with traceId in MDC
return ProblemDetail.forStatusAndDetail(HttpStatus.INTERNAL_SERVER_ERROR,
"An unexpected error occurred."); // plus code and traceId from the shared advice
}

The Spring Boot defaults already follow this: server.error.include-stacktrace and include-message default to never. The policy makes it a rule that nobody changes those defaults in production profiles.

4The Correlation Id Resolves the Tension

The reason we can be strict with clients is that the details are not lost; they are moved. Every error response carries the trace id, and every log line and trace span for that request carries the same id. When a partner reports a failure, they send the id, and our support or engineering team sees the stack trace, the SQL error and the downstream hostname in the logs, where access is controlled and audited.

So the policy is not less information, it is information in the right place. Developers lose nothing during debugging, because their local and test profiles can show more, and production keeps the details behind access control.

5Internal APIs: More Detail, Same Rules for Secrets

APIs called only by our own services can reasonably expose more, because the caller is our own code and debugging across teams is common. An internal response may include the name of the failing dependency or a more specific reason. But the never list still applies in full. Internal is not the same as safe: internal endpoints get exposed by mistake, internal traffic is a target once an attacker is inside, and logs of internal callers are read by many people.

What each kind of API may include
FieldPublic APIInternal API
status, code, title, field errorsyesyes
retry adviceyesyes
trace idyesyes
failing dependency namenoyes
exception class, stack trace, SQLnono
hostnames, secrets, tokensnono
The never rows are the same for both; only the useful middle ground differs.

6Review the Policy and Test It

A policy only protects us if it is checked. The security team reviews and co-signs the policy itself, and API design reviews check new error types against it. The shared error starter enforces it by default: generic messages for unexpected exceptions, the Boot error properties pinned to never, and the trace id added automatically.

Then we test it. Each service's test suite includes a few deliberate failures, an unexpected exception, a database error, malformed JSON, and asserts that the body contains no stack trace markers, no SQL keywords, no package names like com.example and no exception class names. Security scanning of deployed APIs sends malformed requests and flags verbose responses. When a leak is found anyway, it is treated as a security bug with the normal severity process, not as a cosmetic issue.

7Follow-up questions

What should the error say when a user is not found during login?

It should use the same response as a wrong password, for example invalid_credentials with a 401, so an attacker cannot learn which accounts exist. The logs record the real reason. The same idea applies to password reset: the response is identical whether or not the email address is registered.

Is it safe to echo the rejected value in a validation error?

Usually not by default. The value may be personal data, a card number or a password, and echoing it puts it into client logs and browser history. The field name, code and message are enough for the client to fix the request, so the policy leaves rejected values out.

How do developers debug in test environments if responses are so strict?

Profiles for local and test environments can include messages and more detail, as long as they hold no real customer data. The trace id works everywhere, and good log search makes looking up a trace faster than reading a stack trace in a response.

8Conclusion

In this answer, we built a policy that balances helpful errors against leaking internals. Responses carry what the client can act on: field errors, stable codes and retry advice. They never carry stack traces, SQL, internal names, hostnames or secrets. A trace id in every response moves the details into access-controlled logs instead of losing them, internal APIs may show more but follow the same never list, and security reviews the policy while tests and scans verify it.

What to say in the interviewAbout 80 seconds aloud

Open with

I'd base the policy on one question: can the client act on this detail? Field-level validation errors, a stable error code and retry advice like a Retry-After header all pass, so we include them.

Then, if they want more

Stack traces, SQL or database error text, internal class names, hostnames, file paths and anything secret never go in a response, public or internal, because they help an attacker and don't help the client. We also don't copy messages from third-party exceptions, since we don't control what's in them.

The tension disappears with a correlation id: every error response carries the trace id, and every log line and span has it too, so support can see the full stack trace and the database error in access-controlled logs. Nothing is lost, it's just in the right place.

Internal APIs can show a bit more, like which dependency failed, but the never list is identical. Then I'd make it enforceable.

Security co-signs the policy, the shared error starter applies it by default, generic messages for unexpected errors and Boot's include-stacktrace and include-message left at never, and each service has tests that trigger failures and assert the body has no stack trace, SQL or package names. A leak is handled as a security bug.

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 documentation below. 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 "How would you balance exposing detailed error information to help clients against the...": https://scrivio-interview-library.netlify.app/spring-boot/error-handling/4a995e6312/