Reverse Proxy Misconfigurations: Nginx

OtherExploitation

From PayloadsAllTheThings by Swissky and contributors, under the MIT licence. Shown as written; the title and classification are ours. Licences. Its authors can have this tip removed by writing to abuse@bugbountytips.org.

Off By Slash

Nginx matches incoming request URIs against the location blocks defined in your configuration.

  • location /app/ matches requests to /app/, /app/foo, /app/bar/123, etc.

  • location /app (no trailing slash) matches /app* (i.e., /application, /appfile, etc.),

This means in Nginx, the presence or absence of a slash in a location block changes the matching logic.

ps1
server {
  location /app/ {
    # Handles /app/ and anything below, e.g., /app/foo
  }
  location /app {
    # Handles only /app with nothing after OR routes like /application, /appzzz
  }
}

Example of a vulnerable configuration: An attacker requesting /styles../secret.txt resolves to /path/styles/../secret.txt

ps1
location /styles {
  alias /path/css/;
}

Missing Root Location

The root /etc/nginx; directive sets the server's root directory for static files. The configuration doesn't have a root location /, it will be set globally set. A request to /nginx.conf would resolve to /etc/nginx/nginx.conf.

ps1
server {
  root /etc/nginx;

  location /hello.txt {
    try_files $uri $uri/ =404;
    proxy_pass http://127.0.0.1:8080/;
  }
}

Comments

No comments yet.