One view accepts both a read method such as GET and a write method such as POST
What it finds
A view that changes state on POST but also answers GET can often be triggered by a link or an image tag, and protections against cross-site requests usually skip GET. Separate handlers, or one method per route, keep reads safe. Checked are Flask's methods= and Django's require_http_methods.
From the rule's source, route_mixes_safe_and_unsafe_methods.rs.
from flask import Flaskfrom django.views.decorators.http import require_http_methods app = Flask(__name__) @app.route("/x", methods=["GET", "POST"])tx0 reports: this view answers both reading and writing methodsdef x(): return "" @app.route("/y", methods=["POST"])def y(): return "" @require_http_methods(["GET", "DELETE"])tx0 reports: this view answers bothdef z(request): return "" Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/python:route-mixes-safe-and-unsafe-methods" = "note"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:route-mixes-safe-and-unsafe-methods] reason="..."tx0 explain tx0/python:route-mixes-safe-and-unsafe-methods shows the same in the terminal. Found a false positive? Report it.