Stack trace exposure (ARCH2127)
Ce contenu n’est pas encore disponible dans votre langue.
Key python.security.stack-trace-exposure · Severity warning · Category security · CWE CWE-209
Writing exception details or a stack trace into an HTTP response leaks internal implementation to clients and widens the attack surface. Return a generic error message.
Incorrect
Section titled “Incorrect”import tracebackfrom flask import jsonify
def handle(e): return jsonify(error=traceback.format_exc()), 500Correct
Section titled “Correct”import loggingfrom flask import jsonify
def handle(e): logging.exception("unhandled error") return jsonify(error="Internal server error"), 500Write stack traces to the server log, not the client, and return a generic error message to the client.