Skip to content

Gunicorn's handling of PATH_INFO and SCRIPT_NAME can lead to security issues when placed behind a proxy #2650

@itszn

Description

@itszn

This might not be something you can fix, but I wanted to report it since people might have vulnerable configs.

Gunicorn reads some WSGI variables from request headers. This can be an issue when a proxy allows and passes along these special header values.

For example SCRIPT_NAME is used to transform PATH_INFO. If a proxy previously parsed the request path to determine if access is allowed, and attacker could now use a SCRIPT_NAME header to bypass the proxy.

Here is an example nginx config:

server {
    listen 80;
    underscores_in_headers on;
    location / {
        include proxy_params;
        proxy_pass http://unix:/tmp/gunicorn.sock;
        proxy_pass_request_headers on;
        location ^~ /admin/ {
            deny all; # disallow anyone from accessing any routes starting with /admin/
        }
}

This request will call the /admin/something/bad route in the WSGI app despite nginx's deny all.

requests.get(URL+'/REMOVED/admin/something/bad', headers={'script_name':'REMOVED/'})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions