Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ server {

# remove trailing slashes from all URLs (except root /)
# exact match locations (e.g., location = /sdk/js/) take priority over this regex
# [^\\\\] excludes backslashes to prevent open redirect: nginx decodes %5C to \ in $uri,
# and \ in the Location header gets normalized to / by browsers, turning /\evil.com
# into the protocol-relative URL //evil.com which redirects to evil.com.
location ~ ^([^\\\\]+)/$ {
# Only match URIs composed of safe characters (letters, digits, dots, hyphens,
# underscores, forward slashes). This prevents open redirect via %5C (backslash):
# nginx decodes %5C to \ in $uri, and \ in the Location header gets normalized
# to / by browsers, turning /\evil.com into //evil.com (protocol-relative URL).
location ~ ^(/[a-zA-Z0-9][a-zA-Z0-9_./-]*)/$ {
rewrite ^(.+)/$ $1$is_args$args? redirect;
}

Expand Down