v7.5.0: each app gets its own smaller pipeline, and a fix for sub-apps sharing one SecurityConfig #116
rennf93
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
That pulls guard-core 3.10.0 with it. Your config, your decorators, your middleware setup all keep working unchanged.
The short version
guard-core 3.10.0 stopped running security checks that your configuration can never trigger. A default setup went from 17 checks per request to 4.
This release is the FastAPI side of that, plus one security fix that only became a security fix once the pipeline got smaller.
The security fix, first
If two
SecurityMiddlewareinstances share the sameSecurityConfigobject, they used to share a pipeline. That is the documented sub-app mounted-middleware pattern, so it is not an exotic setup.That was harmless while every app got the same 17 checks. It stopped being harmless the moment the pipeline started depending on which routes you decorated.
Concretely: app A decorates a route with
@rate_limit. App B decorates one with@require_auth. They share a config. App A initializes first, builds a pipeline with noauthenticationcheck because none of its own routes need one, and registers it. App B starts, finds the cached state under the same key, adopts it by reference, and serves/needs-authwithout ever authenticating anything.The registry is now keyed on the config and the decorator handler together, so two apps with different decorators build their own pipelines. There is a regression test that fails against the old key.
You are affected if you mount sub-apps and pass the same
SecurityConfiginstance to more than oneSecurityMiddleware. If you build a fresh config per app, you were never exposed.Register your decorators and you get the smaller pipeline
Six checks depend entirely on your route decorators:
authentication,referrer,time_window,required_headers,custom_validators,request_size_content.guard-core can only skip them if it can see your route configuration. Before this release it could only see it if you called
set_decorator_handler. Now it also picks upapp.state.guard_decorator:All three startup paths handle it:
guard_lifespan,make_lifespan, andguard_startup.If it cannot find your decorator handler at all, it assumes every route uses everything and keeps all six. You lose the speed, never the protection.
Check what you actually got. The middleware logs it at startup:
Two smaller changes
A request whose ASGI
scopeis not a real mapping no longer corrupts pipeline construction. It leaves the decorator handler unset rather than feeding a bogus value into the build. Mostly this bit test doubles, but a non-standard request object would have hit it too.httpx2is now a dev dependency, because that is what starlette'sTestClientexpects. Runtime dependencies are unchanged.If you upgraded and something looks different
The pipeline log line will show fewer checks than you are used to. That is the point. Compare the skipped ones against your config: if a check you actually configured is missing from that list, that is a bug and I want to hear about it.
Full changelog: https://github.com/rennf93/fastapi-guard/blob/master/CHANGELOG.md
guard-core 3.10.0 release notes, which cover the pipeline change itself: rennf93/guard-core#61
All reactions