miguelgrinberg / Flask-SocketIO

Socket.IO integration for Flask applications.
MIT License
5.31k stars 888 forks source link

More secure nginx configuration examples #1966

Closed LorenzoLeonardini closed 1 year ago

LorenzoLeonardini commented 1 year ago

The current Nginx example configuration in the docs is potentially vulnerable. This PR fixes that to avoid people introducing potential issues in their apps when copy-pasting that configuration.

Explaination

This is the current configuration:

location /static {
    alias <path-to-your-application>/static;
    expires 30d;
}

in case there are two separate folders, <path-to-your-application>/static and <path-to-your-application>/static_secret this setup would allow an attacker to access all the files contained in /static_secret just by requesting http://[domain]/static_secret/[file]. Adding a final slash ensures only the static folder is served.

location /static/ {
    alias <path-to-your-application>/static/;
    expires 30d;
}

Note that as we add the slash to alias <path-to-your-application>/static/, it's extremely important that we add the final slash to location /static/ as well, as a lack of this would lead to a much more serious path traversal vulnerability[1][2]