A request header is read with [...], which fails the request when the client did not send it

tx0/python:request-header-subscriptstrictnotereliability/api-misusedepth fastbug

What it finds

request.headers["X-Token"] raises when the header is missing, and Flask answers with a bare 400 while Django's request.META[...] gives a 500. Headers are under the client's control; .get() with a default handles the missing case on purpose.

From the rule's source, request_header_subscript.rs.

Example from the rule's tests
from flask import request def token():    a = request.headers["X-Token"]tx0 reports: a missing header makes this lookup fail    b = request.headers.get("X-Token")    c = request.META["HTTP_HOST"]tx0 reports: a missing header    return a, b, c
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 strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/python:request-header-subscript" = "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:request-header-subscript] reason="..."

tx0 explain tx0/python:request-header-subscript shows the same in the terminal. Found a false positive? Report it.