A Flask application's secret key is written in the source

tx0/python:hardcoded-flask-secretrecommendedwarningsecurity/secretsdepth fastsecurity, cwe-798

What it finds

Flask signs session cookies with SECRET_KEY; anyone who reads the key from the source or its history can forge sessions. The key is read from the environment or a secrets store instead. Checked are app.secret_key = "...", app.config["SECRET_KEY"] = "..." and app.config.update(SECRET_KEY="...") with a non-empty literal, in files that import Flask.

From the rule's source, hardcoded_flask_secret.rs.

Example from the rule's tests
import osfrom flask import Flask app = Flask(__name__)app.secret_key = "s3cr3t"tx0 reports: the session signing key is written in the sourceapp.config["SECRET_KEY"] = "dev-key"tx0 reports: the session signing keyapp.config.update(SECRET_KEY="abc")tx0 reports: the session signing keyapp.config["SECRET_KEY"] = os.environ["SECRET_KEY"]app.secret_key = ""
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:hardcoded-flask-secret" = "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:hardcoded-flask-secret] reason="..."

tx0 explain tx0/python:hardcoded-flask-secret shows the same in the terminal. Found a false positive? Report it.