Flask 3.1
Last reviewed Sep 12, 2026
Prompt Details
CWE Coverage
- 20
- 23
- 36
- 59
- 73
- 78
- 79
- 89
- 95
- 113
- 117
- 203
- 208
- 209
- 214
- 250
- 295
- 306
- 307
- 319
- 328
- 338
- 346
- 347
- 352
- 367
- 379
- 384
- 409
- 416
- 426
- 427
- 434
- 470
- 488
- 489
- 502
- 524
- 532
- 601
- 611
- 613
- 614
- 674
- 732
- 770
- 772
- 776
- 798
- 807
- 829
- 862
- 916
- 918
- 942
- 1004
- 1104
- 1275
- 1333
- 1336
- 1395
Prompt Preview
Apply the Jinja 3.1 and Python 3 prompts first. These rules cover Flask 3.1 configuration, proxy and request trust, sessions, CSRF, CORS, authentication, rendering, file handling, errors, and production deployment.
Configuration and application setup
- Load production configuration from a trusted source and fail startup when
SECRET_KEYor another required control is missing. - Generate a high-entropy
SECRET_KEY, keep it outside source, and use Flask 3.1SECRET_KEY_FALLBACKSonly for a bounded rotation window before removing expired keys; verify rotation support separately in extensions that use the key. - On Flask 3.1.0, which predates the 3.1.1 fix, a non-empty
SECRET_KEY_FALLBACKSmakes Flask sign new sessions with the last fallback key instead ofSECRET_KEY, so leave the fallback list empty on that release. - Keep debug mode and the interactive debugger disabled in every reachable production environment.
- Register authentication, CSRF, error handling, and security headers centrally through an application factory.
- Keep development defaults, example credentials, test routes, and permissive extension settings out of production configuration.
Requests, hosts, and proxies
- Set
TRUSTED_HOSTSto a nonempty list of exact production hostnames; its default isNone, which allows any domain, and a leading dot trusts that domain plus all subdomains. - Reject untrusted hosts at the front proxy when callbacks require trusted host data;
SERVER_NAMEdoes not filter hosts, andbefore_requestandafter_requeststill run whenTRUSTED_HOSTSrejects a