Litestar 2
Last reviewed Sep 24, 2026
Prompt Details
Prompt Composition
2prompts
- Python 3155 lines · 3.8K tokens
- Litestar 271 lines · 3.8K tokens
Total226 lines · 7.6K tokens
CWE Coverage
- 20
- 23
- 36
- 59
- 78
- 79
- 89
- 95
- 117
- 201
- 208
- 209
- 214
- 250
- 295
- 306
- 319
- 328
- 338
- 347
- 352
- 367
- 379
- 384
- 409
- 416
- 426
- 427
- 470
- 502
- 524
- 532
- 611
- 613
- 614
- 639
- 674
- 732
- 770
- 772
- 776
- 807
- 829
- 862
- 863
- 915
- 916
- 918
- 942
- 1004
- 1104
- 1250
- 1333
- 1336
- 1385
- 1395
Prompt Preview
Apply the Python 3 prompt first. These rules cover Litestar 2 and were checked against 2.24.0, whose package metadata permits Python >=3.8,<4.0 and whose release CI covers 3.8–3.14; deploy on a maintained Python version covered by the Python baseline.
Authentication and route authorization
- Install the chosen
SessionAuth,JWTAuth, orJWTCookieAuthconfiguration throughon_app_init=[auth.on_app_init]. If installingauth.middlewaremanually on a router or controller, also attach the guards and dependencies the policy requires; the middleware property alone does not install the complete security configuration. - Restrict authentication
excludepatterns to intentional public routes with explicit anchors and path boundaries. Reviewexclude_from_auth, customexclude_opt_keyvalues, inherited routeoptsettings, and middlewarescopesas policy exceptions, including mounted applications and static-file routes. - Set
exclude_http_methodsexplicitly on security configurations.SessionAuth,JWTAuth, andJWTCookieAuthdefault to excluding bothOPTIONSandHEAD; use only the methods intended to be public, such as["OPTIONS"]when only preflight is exempt. The lower-levelAbstractAuthenticationMiddlewaredefaults to excluding onlyOPTIONS. - Make guards raise
PermissionDeniedExceptionorNotAuthorizedExceptionon denial; returningFalsedoes not reject a request. Guards from application, router, controller, and handler layers accumulate. Handle intentionally public preflight requests explicitly without weakening protected methods.