Stack Trace (Java)

  • CWE 209
  • OWASP 2017-A6

Stack Trace Disclosure occurs when an application displays runtime stack traces to end users, exposing internal code paths, function names, line numbers, and system architecture information. This vulnerability often arises from unhandled exceptions or misconfigured error reporting in development environments deployed to production. Attackers can leverage stack traces to gain insight into application logic, underlying frameworks, libraries, and potential weak points, facilitating further attacks such as SQL Injection, Path Traversal, or Remote Code Execution.

Common patterns leading to stack trace disclosure:

  • Uncaught exceptions rendered directly to the browser or API responses.
  • Development or debug mode enabled in production.
  • Web frameworks configured to display detailed error pages by default.
  • Inclusion of sensitive system information such as absolute file paths, package names, or runtime environment variables in error output.

Impacts:

  • Information Disclosure: Reveals function calls, code structure, database query information, and server configuration.
  • Facilitates Attacks: Provides attackers with knowledge to craft targeted exploits.
  • Intellectual Property Exposure: Source code structure and sensitive logic can be inferred.
  • Increased Attack Surface: Knowledge from stack traces allows attackers to bypass security controls or identify vulnerable components.

Detection indicators:

  • Responses contain full stack traces, file paths, or code snippets.
  • Error pages showing line numbers, class/method names, or runtime exceptions.
  • Presence of default error pages from frameworks like Java, ASP.NET, or PHP.
Remediation

Mitigation strategies focus on sanitizing outputs, proper exception handling, and secure logging:

  1. Generic Error Messages for Users
    Display user-friendly messages that do not expose stack traces or internal system details.

  2. Centralized Exception Handling
    Implement global error handling to catch exceptions and return sanitized responses to clients.

  3. Disable Debug Mode in Production
    Ensure all development/debug features, detailed logging, or verbose error pages are disabled in production environments.

  4. Secure Logging
    Log full stack traces and system details internally to files or monitoring systems with restricted access, without exposing them to users.

  5. Input Validation and Sanitization
    Reduce the likelihood of unhandled exceptions by validating inputs and handling edge cases properly.

  6. Principle of Least Privilege
    Limit permissions of web server and application processes to minimize the impact of any leaked information.

  7. Regular Security Testing
    Include stack trace disclosure checks during code review, automated scans, and penetration testing.

  8. Error Page Customization
    Customize error pages for standard HTTP errors (e.g., 404, 500) to prevent default framework pages from revealing internal details.

References