A simple diagram of the Improper Error Handling risk path
Risk path: an input or context crosses a security boundary.
A simple three-step test path for Improper Error Handling
Testing path: establish a baseline, make one controlled change, and verify the effect.

Issue

Applications encounter errors during normal operation: requests may be malformed, a database may be unavailable, or an internal operation may fail. Error handling is the code and configuration that detect those conditions, decide what the application should do, and communicate the result.

Errors are not automatically vulnerabilities. An application can return a useful message without exposing sensitive internals. A problem arises when it mishandles an error—for example, by showing a stack trace, continuing in an unsafe state, or silently treating a failed security check as successful. CWE describes these as related weaknesses, including information leaks in error messages and failures to handle exceptional conditions. CWE-209, CWE-755

Common causes include:

  • Returning raw exception messages, stack traces, SQL errors, file paths, environment values, or framework diagnostics to users.
  • Handling only expected errors and allowing unexpected exceptions to reach a default server error page.
  • Catching an exception but ignoring it, or returning a success response after an operation failed.
  • Allowing a failed authorization or security check to fall back to permissive behavior. CWE calls this “failing open.” CWE-636
  • Returning different messages for sensitive states, such as whether a particular account exists, when that distinction should not be public.
  • Logging too little for diagnosis, or logging sensitive data that should not be retained.

For HTTP APIs, status codes communicate the broad result: 4xx generally indicates a client error, while 5xx indicates a server error. The exact code should match the situation; a status code alone does not establish whether error handling is secure. RFC 9110 APIs may use the standardized Problem Details format to describe an error in a consistent way. It is intended to describe the HTTP interface, not to expose implementation debugging data. RFC 9457

Examples

Request with malformed JSON

POST /api/profile HTTP/1.1
Host: api.example.com
Content-Type: application/json
 
{"displayName":

Problematic response

HTTP/1.1 500 Internal Server Error
Content-Type: text/plain
 
JsonParseException at /srv/app/api/profile.py:84
Database connection: db-internal.example.net

This response exposes implementation and infrastructure details. It does not, by itself, show that the database can be reached or that data has been accessed.

Safer response

HTTP/1.1 400 Bad Request
Content-Type: application/problem+json
 
{
  "type": "https://api.example.com/problems/invalid-request",
  "title": "Invalid request",
  "status": 400,
  "detail": "The request body is not valid JSON.",
  "instance": "/api/profile"
}

The message explains how the client can correct the request without returning internal exception details. RFC 9457 defines the Problem Details format and cautions that it is not a debugging format. RFC 9457

Fail-open check

try:
    allowed = authorization_service.can_edit(user, document)
except AuthorizationServiceError:
    allowed = True  # Unsafe: a failed check grants access.

A safer pattern is to deny the action when authorization cannot be established, while recording a diagnostic event for operators:

try:
    allowed = authorization_service.can_edit(user, document)
except AuthorizationServiceError:
    log_authorization_failure(request_id)
    allowed = False

The log function should avoid recording credentials, tokens, or other sensitive request data.

Impact

The impact depends on what the error reveals or how the application behaves after the failure.

  • Information disclosure: A detailed error may reveal internal paths, software components, database behavior, or request data. This can help someone investigate further, but does not by itself prove that they can access data or exploit another flaw. OWASP Web Security Testing Guide
  • Unsafe access decisions: If an authorization check fails and the application proceeds as though it passed, a protected action may become available. Confirm this by demonstrating the protected action succeeds without the required authorization.
  • Data or service reliability: If errors are ignored or handled inconsistently, operations may be incomplete, state may be inconsistent, or requests may fail unexpectedly. The specific consequence must be demonstrated; an error response alone does not prove data loss or corruption.
  • Account or state enumeration: Different responses can disclose whether an account or resource exists. The evidence is the observable difference; the risk depends on whether that information is sensitive and useful in the application’s context.

A verbose error is an information-disclosure finding when it exposes internal details. Claims such as data theft, authentication bypass, or account takeover require separate evidence that the disclosed information or failure behavior enables those outcomes.

Testing

1. Check errors for sensitive information

Trigger representative application errors and inspect responses for secrets, personal data, stack traces, or internal paths. Compare what an ordinary user can actually read.

Example: An internal file path may help identify the software. Its presence alone does not prove account compromise.

GET /api/orders/invalid-id HTTP/1.1
Host: app.example.test

2. Compare authentication and input errors

Use known and unknown test accounts or invalid input formats and compare status, body, and timing. Check whether differences expose information the application intends to keep private.

Example: Different login messages may reveal whether a test account exists. Test the documented behavior before reporting it.

POST /api/login HTTP/1.1
Host: app.example.test
Content-Type: application/json
 
{"username":"unknown-test-user","password":"incorrect"}

3. Check failure state and logs

After an error, inspect whether the action partially completed and whether sensitive details are restricted to appropriate server logs. Compare handling across routes and dependencies.

Example: A 500 response does not prove an unsafe state. Inspect the record after the operation.

A browser’s displayed error page may come from the browser, a proxy, a CDN, a web server, or the application. Capture the actual HTTP response in the Network panel or with an authorized HTTP client before attributing the message to application behavior. OWASP’s testing guidance recommends examining errors across relevant inputs and paths, not relying on a single response. OWASP WSTG: Improper Error Handling

Mitigation

Primary fixes

  • Handle expected failures deliberately. Validate input and map known conditions to appropriate client responses. Use a centralized handler for unexpected failures so they do not fall through to development pages or server defaults.
  • Keep client messages useful and limited. Explain what the user can do next, such as correcting a field or retrying later. Do not return stack traces, raw exception messages, secrets, internal paths, or infrastructure details. Safe field-level validation messages can still be specific.
  • Fail securely for security decisions. If an authorization, authentication, or policy check cannot complete, do not grant access by default. Test that the protected action is denied when the check fails.
  • Record diagnostics safely. Log enough information for investigation, such as the exception and a request identifier, in a protected logging system. Restrict access and avoid logging credentials, session tokens, or unnecessary personal information. OWASP recommends separating user-facing messages from diagnostic information. OWASP Error Handling Cheat Sheet
  • Use accurate HTTP semantics. Return a suitable 4xx response when the request cannot be fulfilled because of the client’s input or permissions, and a suitable 5xx response when the server cannot fulfill an otherwise valid request. Do not return success for an operation that failed. RFC 9110

Additional defensive measures

  • Disable developer exception pages and detailed diagnostics in public production environments. Microsoft’s ASP.NET Core guidance specifically warns against displaying detailed exception information publicly in production. Microsoft Learn: Error handling in ASP.NET Core
  • Keep responses consistent where differences could reveal sensitive account or resource state.
  • Monitor server-side failures and investigate repeated errors, while avoiding alerts that expose sensitive log content.
  • Review error handling in application code, framework settings, reverse proxies, and API gateways. A generic application page does not prevent an upstream component from returning detailed diagnostics.

After applying fixes, repeat the relevant tests and confirm both sides of the behavior: clients receive a suitable response without sensitive internals, and authorized operators can still investigate the failure from protected logs.