Skip to content

Commit ada3c6b

Browse files
B4nanclaude
andauthored
fix: block open redirect via encoded backslash (%5C) in nginx (#2354)
## Summary - Block requests containing encoded backslash (`%5C`) in the URI to prevent an open redirect vulnerability - The nginx trailing slash removal rule (`rewrite ^(.+)/$ $1 redirect`) can produce redirects that browsers misinterpret when the URI contains `%5C` - some browsers decode it to `\`, normalize to `/`, and create protocol-relative navigation - Fix adds a server-level check on `$request_uri` that returns 400 before any rewrite processing 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 8214e69 commit ada3c6b

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

.github/workflows/test.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,22 @@ jobs:
7575
echo "$actual" | grep -q "$expected" || (echo "❌ Expected '$expected' in '$header' for $url" && exit 1)
7676
}
7777
78+
function assert_status() {
79+
url=$1
80+
expected=$2
81+
shift 2
82+
extra_args=("$@")
83+
actual=$(curl -s -o /dev/null -w "%{http_code}" "${extra_args[@]}" "$url")
84+
echo "→ $url → HTTP $actual"
85+
[ "$actual" = "$expected" ] || (echo "❌ Expected HTTP $expected but got $actual for $url" && exit 1)
86+
}
87+
88+
echo "🧪 Checking encoded backslash blocking..."
89+
assert_status "http://localhost:8080///%5Cevil.com/" "400"
90+
assert_status "http://localhost:8080/%5Cevil.com/" "400"
91+
assert_status "http://localhost:8080/platform/%5Ctest" "400"
92+
assert_status "http://localhost:8080///%5cevil.com/" "400"
93+
7894
echo "🧪 Checking Nginx responses... (apify-docs)"
7995
assert_header "http://localhost:8080/" "Content-Type" "text/html"
8096
assert_header "http://localhost:8080/" "Content-Type" "text/markdown" -H "Accept: text/markdown"

nginx.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ 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") {
28+
return 400;
29+
}
30+
2431
location = / {
2532
if ($serve_markdown) {
2633
rewrite ^ /llms.txt last;

0 commit comments

Comments
 (0)