Stack Trace In Response

Discover Pynt's documentation on security tests for stack trace in response vulnerabilities! Learn how Pynt secures your APIs against potential exposure of sensitive information.


A stack trace is a list of function calls that shows the flow of execution of a program. It can contain information about the names and locations of functions, variables, and parameters used in the code. If a stack trace is returned in an API response, it can reveal details about the server-side implementation of the API, including the programming language, framework, and libraries used, as well as the file path and line numbers of the code that threw the error.

Returning stack traces in API responses is generally not a good idea because it can expose sensitive information about your server and potentially compromise its security.

What are the common mistakes done by developers ?

There could be a few reasons why you are seeing stack traces returned by your API:

  1. Some programming languages and frameworks have a "debug mode" which is used during development to help diagnose issues. When debug mode is enabled, stack traces may be returned in API responses. However, it's important to disable debug mode in production environments to prevent sensitive information from being exposed.

  2. Error Handling: If your API is not handling errors correctly, it may be returning stack traces to clients. This can happen if your API is not configured to catch and handle exceptions in a way that prevents stack traces from being displayed.

How can I fix returned stack trace issues ?

It's important to ensure that your API is properly configured to handle errors and that stack traces are not returned to clients in production environments. You should also consider implementing custom error messages that provide enough information for clients to understand the problem without revealing sensitive information. This can help improve the security of your API and prevent potential attacks.

For example: to disable stack traces returned by Flask, you can set the debug configuration option to False in your Flask application. Here's an example:

from flask import Flask

app = Flask(__name__)
app.config['DEBUG'] = False

# Your Flask routes and application code here

When debug is set to True, Flask will return detailed error messages including stack traces. By setting it to False, Flask will return a simpler error message that does not include a stack trace.

It's important to note that you should disable debug mode in production environments to prevent sensitive information from being exposed. In development environments, you can still use the stack trace for debugging purposes, but it should not be exposed to clients.

Test cases in this category:

This test case checks for stack traces returned in responses


[ST001] Stack trace in response

Last updated