A Flask error handler returns a body without a status code, so the error is answered with 200 OK

tx0/python:error-page-sent-as-okrecommendedwarningreliability/error-handlingdepth fastbug

What it finds

The value a function registered with @app.errorhandler(404) returns becomes the response as it is; a bare template or string is sent with status 200, which tells clients and caches that the request succeeded. Returning (body, 404) keeps the status. Returns of tuples, of responses built by a call, and of the caught error itself are left alone.

From the rule's source, error_page_sent_as_ok.rs.

Example from the rule's tests
from flask import Flask, render_template app = Flask(__name__) @app.errorhandler(404)def missing(error):    return render_template("404.html")tx0 reports: this error response goes out with status 200 @app.errorhandler(500)def broken(error):    return render_template("500.html"), 500 @app.errorhandler(HTTPException)def http(error):    return error
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/python:error-page-sent-as-ok" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

# tx0: ignore[tx0/python:error-page-sent-as-ok] reason="..."

tx0 explain tx0/python:error-page-sent-as-ok shows the same in the terminal. Found a false positive? Report it.