Skip to main content

SKY-L017 · Logic and resilience

Error information disclosure

Medium

The catalog gives no severity for this rule; the detector always reports MEDIUM.

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
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

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

billing/api.py · PythonReported on line 16
"""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()), 201

What Skylos leaves alone

billing/api.py · Python
"""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()), 201

Why 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

  1. Runs with --quality on Python files. Skips test files (test_*.py, *_test.py and conftest.py). Looks inside every except block.
  2. Treats as disclosure the caught exception name (exc), str(exc), repr(exc) and traceback.format_exc(), given directly, inside an f-string, or as the value of an error, message, detail, msg or reason key in a dictionary.
  3. Reports a call to jsonify, make_response, Response, JsonResponse, HttpResponse, HttpResponseBadRequest, HttpResponseServerError, JSONResponse, HTMLResponse or PlainTextResponse that receives such a value, on the line of the call.
  4. When the handler binds the exception (except ... as exc), also reports a return of such a value, on the line of the return, 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.

billing/api.py · Python · the fix, against the flagged file
"""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()), 201

When it can be wrong

  • An exception whose text is written for the client, such as your own PaymentDeclined("Card expired"), is reported when you return str(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 a raise, not a response call or a return.

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.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.