Skip to content

Commit ba47ab9

Browse files
B4nanclaude
andauthored
fix: block open redirect via literal backslash and double slashes in nginx (#2356)
## Summary - The previous `%5C` check is bypassed because CloudFront decodes `%5C` to literal `\` before forwarding to nginx, so `$request_uri` never contains `%5C` - This PR adds nginx rules to also block literal backslashes and multiple leading slashes in request URIs - Tests use `curl --request-target` to simulate exactly what CDNs forward to nginx Fixes apify/apify-core#26551 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ada3c6b commit ba47ab9

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

.github/workflows/test.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,16 @@ jobs:
8585
[ "$actual" = "$expected" ] || (echo "❌ Expected HTTP $expected but got $actual for $url" && exit 1)
8686
}
8787
88-
echo "🧪 Checking encoded backslash blocking..."
88+
echo "🧪 Checking open redirect protection..."
89+
# Encoded backslash (%5C) - as sent by clients directly
8990
assert_status "http://localhost:8080///%5Cevil.com/" "400"
9091
assert_status "http://localhost:8080/%5Cevil.com/" "400"
91-
assert_status "http://localhost:8080/platform/%5Ctest" "400"
9292
assert_status "http://localhost:8080///%5cevil.com/" "400"
93+
# Literal backslash - as forwarded by CDNs that decode %5C before proxying
94+
assert_status "http://localhost:8080" "400" --request-target '/\evil.com/'
95+
assert_status "http://localhost:8080" "400" --request-target '///\evil.com/'
96+
# Multiple leading slashes (no backslash) - also a redirect vector
97+
assert_status "http://localhost:8080" "400" --request-target '//evil.com/'
9398
9499
echo "🧪 Checking Nginx responses... (apify-docs)"
95100
assert_header "http://localhost:8080/" "Content-Type" "text/html"

nginx.conf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ server {
2121
set $backend "https://apify.github.io/apify-docs";
2222
resolver 1.1.1.1 8.8.8.8 valid=30s ipv6=off;
2323

24-
# Prevent open redirect via encoded backslash (%5C) in URL
25-
# Some browsers decode %5C to \ and normalize it to / in URL paths,
26-
# which combined with the trailing-slash rewrite can create redirect vectors
27-
if ($request_uri ~* "%5c") {
24+
# Prevent open redirect via backslash or multiple leading slashes in URL
25+
# CDNs like CloudFront may decode %5C to literal \ before forwarding to nginx.
26+
# The trailing-slash rewrite then puts \ in the Location header, which browsers
27+
# normalize to /, creating protocol-relative URLs (e.g. /\evil.com → //evil.com).
28+
if ($request_uri ~ "\\\\|%5[cC]|^//") {
2829
return 400;
2930
}
3031

0 commit comments

Comments
 (0)