Flask 3.1

Last reviewed Sep 12, 2026

Export as PDF

Prompt Details

Prompt Composition

3prompts
  1. Python 3155 lines · 3.8K tokens
  2. Jinja 3.158 lines · 1.5K tokens
  3. Flask 3.175 lines · 2.9K tokens
Total288 lines · 8.2K tokens

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_KEY or another required control is missing.
  • Generate a high-entropy SECRET_KEY, keep it outside source, and use Flask 3.1 SECRET_KEY_FALLBACKS only 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_FALLBACKS makes Flask sign new sessions with the last fallback key instead of SECRET_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_HOSTS to a nonempty list of exact production hostnames; its default is None, 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_NAME does not filter hosts, and before_request and after_request still run when TRUSTED_HOSTS rejects a