SKY-L017 · Logic and resilience
Error information disclosure
An exception handler sends the exception's text or a formatted stack trace back in the response, for example jsonify({"error": str(exc)}). Exception messages are written for developers, not for the people who call the API.
- Languages
- Python
- Quality gate
- counted toward the gate limits (full and diff scans)
- Finding type
- review
Why it matters
A database error's text can contain the SQL statement, table and column names or the database host; a stack trace shows file paths and library versions. That is a map for an attacker probing the API, handed over by every request that fails.
What Skylos flags
"""Invoice endpoints.""" from flask import Flask, jsonify, request from billing import service app = Flask(__name__) @app.post("/invoices")def create_invoice(): try: invoice = service.create(request.get_json()) except Exception as exc: app.logger.exception("invoice creation failed") return jsonify({"error": str(exc)}), 500 return jsonify(invoice.to_dict()), 201What Skylos leaves alone
"""Invoice endpoints.""" from flask import Flask, jsonify, requestfrom marshmallow import ValidationError from billing import service app = Flask(__name__) @app.post("/invoices")def create_invoice(): try: invoice = service.create(request.get_json()) except ValidationError as exc: return jsonify({"error": exc.messages}), 400 return jsonify(invoice.to_dict()), 201Why Skylos leaves it alone
The handler sends exc.messages, the field errors a validation library writes for the client ("Missing data for required field"). Skylos only reports the exception object itself, str() or repr() of it, or traceback.format_exc(), not an attribute of the exception.
How Skylos decides
- Runs with
--qualityon Python files. Skips test files (test_*.py,*_test.pyandconftest.py). Looks inside everyexceptblock. - Treats as disclosure the caught exception name (
exc),str(exc),repr(exc)andtraceback.format_exc(), given directly, inside an f-string, or as the value of anerror,message,detail,msgorreasonkey in a dictionary. - Reports a call to
jsonify,make_response,Response,JsonResponse,HttpResponse,HttpResponseBadRequest,HttpResponseServerError,JSONResponse,HTMLResponseorPlainTextResponsethat receives such a value, on the line of the call. - When the handler binds the exception (
except ... as exc), also reports areturnof such a value, on the line of thereturn, since a returned value may become the response body.
How to fix it
Keep the detail in your logs and send the client a generic message. A request ID in both places lets support find the log entry.
"""Invoice endpoints.""" from flask import Flask, jsonify, request from billing import service app = Flask(__name__) @app.post("/invoices")def create_invoice(): try: invoice = service.create(request.get_json())Removed: except Exception as exc:Added: except Exception: app.logger.exception("invoice creation failed")Removed: return jsonify({"error": str(exc)}), 500Added: return jsonify({"error": "Could not create the invoice."}), 500 return jsonify(invoice.to_dict()), 201When it can be wrong
- An exception whose text is written for the client, such as your own
PaymentDeclined("Card expired"), is reported when you returnstr(exc). - A
return str(exc)from a helper that is not a request handler is reported, since Skylos cannot tell where the value goes. - It misses
raise HTTPException(status_code=500, detail=str(exc)), because that is araise, not a response call or areturn.
Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.
How to silence it
Put the marker on the reported line.
Python return jsonify({"error": str(exc)}), 402 # skylos: ignore[SKY-L017] client message[tool.skylos] ignore = ["SKY-L017"]turns the rule off for the project.