Starlette 1.7.0
Last reviewed Oct 13, 2026
Prompt Details
Prompt Composition
2prompts
- Python 3155 lines · 3.8K tokens
- Starlette 1.7.088 lines · 4K tokens
Total243 lines · 7.8K tokens
CWE Coverage
- 20
- 22
- 23
- 36
- 59
- 78
- 79
- 89
- 95
- 113
- 117
- 201
- 203
- 208
- 209
- 214
- 250
- 287
- 288
- 295
- 306
- 307
- 319
- 328
- 338
- 347
- 352
- 367
- 379
- 409
- 416
- 426
- 427
- 434
- 470
- 488
- 502
- 524
- 532
- 552
- 601
- 611
- 613
- 614
- 639
- 674
- 732
- 770
- 772
- 776
- 807
- 829
- 862
- 916
- 918
- 942
- 1004
- 1104
- 1275
- 1333
- 1395
Prompt Preview
Apply the Python baseline first, then these rules for Starlette 1.7.0 on maintained stable CPython 3.11–3.15 with anyio>=4.0.0,<5.
Deployment and middleware
- Keep
Starlette(debug=False)in production and install a safe 500 handler; enabling debug replaces that handler's response with a traceback. - Install
TrustedHostMiddlewarewith explicitallowed_hostsbefore middleware that constructs redirects or absolute URLs. Its defaultallowed_hosts=Nonepermits every host; use bracketed IPv6 entries and enablewww_redirectonly when that redirect is intended. - Establish the external scheme and client address only through trusted proxy configuration before using
request.url,request.client, orHTTPSRedirectMiddleware. With Uvicorn, restrict--forwarded-allow-ipsto actual proxies and prevent direct access that would defeat that trust boundary. - Require TLS for both HTTP and WebSocket traffic;
HTTPSRedirectMiddlewareredirectshttpandwsbut does not terminate TLS. Validate hosts before redirects and configure proxy forwarding so the app sees the original secure scheme. - Apply authentication and other mandatory controls around every relevant
Mountand standalone ASGI application. A bareRouterhas no Starlette application middleware;BaseHTTPMiddlewarecovers HTTP only, so protect WebSocket routes explicitly. - Keep request-specific identity and policy state local to the ASGI call or its
scope, never on a shared middleware instance. Use pure ASGI middleware when correctness depends onContextVarpropagation;BaseHTTPMiddleware