PAGI::FastAPI's to_app Builder Can Bypass Registered Middleware

PAGI::FastAPI versions from 1.0.0 before 1.4.0 can serve requests without authentication or CSRF middleware when an application is built with to_app. The issue is tracked as CVE-2026-130488. The module's add_middleware path keeps middleware objects in a separate stack, while the to_app builder does not reliably connect that stack to the application that serves requests. The fixed release is 1.4.0.

The failure is easy to miss in development because the application may still start. A test that calls a route directly can return a successful response without proving that the production request path has the intended middleware. The risk is highest for APIs that rely on middleware for authentication, CSRF checks, audit logging, or tenant selection. A route handler may be perfectly correct and still receive a request that never passed the gate its author expected.

Inventory every application built with to_app. Search for add_middleware calls and determine whether the same middleware is registered in the serving path. Compare the declarations in code with the request headers and session behavior observed in a staging deployment. Do not rely on a framework method name or a passing route test as proof that middleware ran.

Upgrade to PAGI::FastAPI 1.4.0 or later and restart workers. Re-run tests that exercise the real server, not just an in-process route object. Include a request with no session, a request with a stale CSRF token, and a request with a valid session. Check both the route response and the audit log. If the application uses a reverse proxy that injects identity headers, verify that the proxy cannot become the only authentication control.

The patch also needs a deployment check for old workers. A rolling restart can leave a long-lived process running the vulnerable module while new workers have the fix. Confirm the module version in each process, and drain old workers before removing them. If the service cannot be upgraded immediately, disable routes that depend on middleware-only authorization and add a server-level check in front of the application. That temporary control needs a named owner and a removal date.

Finally, review the application's test contract. Middleware should have a test that proves it is in the serving chain, not merely constructed in code. A negative test that expects a 401 or 403 for an unauthenticated request is stronger evidence than a unit test that checks the middleware object exists.

References