Async middleware pattern for consistent security headers in aiohttp #12423
cak
started this conversation in
Show and tell
Replies: 1 comment
|
I typically use a middleware to apply headers like Content-Security-Policy locally during development, and then enforce it via nginx in production. |
0 replies
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.
I’ve been trying to clean up how we apply HTTP security headers in async Python services and landed on a simple aiohttp middleware pattern.
The main issue was inconsistency:
Middleware ended up being the cleanest place to enforce it:
What I like about this:
If you don’t want to wire this up each time, I wrapped the pattern here:
https://github.com/TypeError/secure
Curious if others are enforcing headers at middleware level in aiohttp or doing something different?
All reactions