I have a nginx server running on Debian. The same server is also running uWSGI with a Flask Python application. One thing I'm trying to do is pass an HTTP header to the Flask application from nginx that's determined by a nginx condition, namely which virtual-host is running the request.
I'm trying to pass an HTTP header from nginx (not from the client) to the uWSGI backend but it isn't showing up in Flask's DebugToolbar under HTTP request.
Relevant section from nginx config
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri =404 @flaskapplication;
}
location @flaskapplication {
include uwsgi_params;
uwsgi_pass unix:/tmp/flaskapplication.sock;
uwsgi_param HTTP_X_TESTING 'bar';
uwsgi_modifier1 30;
}
While running said nginx config said header doesn't show up under Flask-DebugToolbar HTTP request section, although I'm not sure how reliable this is because I injected a HTTP header I know influences application behavior using Burp Suite X-Foo-Bar: 1
and it didn't show up under the HTTP request section but it did influence the application behavior (A certain if statement in @app.before_request
) Obviously I would delete the header if the client added it for security reasons.
The above screenshot is HTTP Headers with Flask-DebugToolbar trying to do uwsgi_param
for HTTP headers.
Thanks
Solved it.
I enabled Flask's debug mode and raised an exception to gain access to the REPL.
With uwsgi_param HTTP_X_FOO 'Foo bar lorem ipsum';
in the nginx configuration in the relevant location block, request.headers
looks like this (private and unrelated information has been redacted)
So request.headers
!= Flask-DebugToolbar request panel.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With