[loop-cycle-2] fix: resolve endpoint before execution in CSRF middleware (#626) #656
Reference in New Issue
Block a user
Delete Branch "fix/csrf-exempt-check-before-dispatch"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Fixes #626 — CSRF middleware was executing endpoints before checking
@csrf_exempt.Problem
When CSRF validation failed and the path was not in the exempt list, the middleware called
call_next(request)which executed the endpoint (including all side effects like DB writes), then checked@csrf_exemptafterward. Non-exempt endpoints ran regardless of CSRF protection.Fix
_resolve_endpoint()method that walks the FastAPI/Starlette middleware chain to find the matching route endpoint WITHOUT executing it@csrf_exempton the resolved endpoint BEFORE callingcall_next()Tests
@csrf_exemptendpoints still execute normallyNet lines
~+25 code, -5 removed = modest net add, but eliminates a security vulnerability