fix: whitelist safe characters in trailing-slash rewrite to prevent open redirect#2362
Closed
fix: whitelist safe characters in trailing-slash rewrite to prevent open redirect#2362
Conversation
The [^\\\\] character class in the location regex didn't work in production due to nginx config backslash escaping differences across environments. Use a map directive with \x5c (PCRE hex escape for backslash byte 0x5C) which is completely unambiguous. The map sets $uri_has_backslash, and an if+return inside the trailing-slash location block returns 404 when a backslash is detected - preventing the redirect that would put \ in the Location header. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Previous approaches tried to detect/match the backslash character using \x5c hex escapes, [^\\\\] character classes, map directives, and if blocks - all worked in CI but failed in production. This takes the opposite approach: instead of blacklisting backslashes, whitelist the safe characters that should appear in documentation URLs. The trailing-slash location regex changes from ^(.+)/$ to ^(/[a-zA-Z0-9][a-zA-Z0-9_./-]*)/$ so it only matches URIs composed of letters, digits, dots, hyphens, underscores, and forward slashes. Uses only basic regex features (character ranges and literals) that work identically across all PCRE/POSIX ERE versions with zero escaping ambiguity. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Member
Author
|
Not needed - the \x5c location approach works, previous test failures were due to CloudFront cache. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
^(.+)/$to^(/[a-zA-Z0-9][a-zA-Z0-9_./-]*)/$Fixes apify/apify-core#26551
🤖 Generated with Claude Code