From: Rich Bowen Date: Sat, 2 May 2026 20:13:17 +0000 (+0000) Subject: rewrite guide: add security considerations section - open redirects, SSRF, path trave... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6061294292c6aeeb6031b96e45b86ee714c41270;p=thirdparty%2Fapache%2Fhttpd.git rewrite guide: add security considerations section - open redirects, SSRF, path traversal (BZ 58892, step 14) git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1933724 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/docs/manual/rewrite/intro.xml b/docs/manual/rewrite/intro.xml index 5e1b388aec..ebeb393263 100644 --- a/docs/manual/rewrite/intro.xml +++ b/docs/manual/rewrite/intro.xml @@ -388,4 +388,83 @@ the RewriteRule. In addition, the +
Security Considerations + +

mod_rewrite is a powerful URL manipulation tool, and +with that power comes the potential for security mistakes. This section +highlights the most common security pitfalls to watch for when writing +rewrite rules.

+ +
Open Redirects + +

If a RewriteRule +constructs a redirect URL using unvalidated user input, an attacker +can craft a link that redirects visitors to a malicious site while +appearing to originate from your domain. This is known as an +open redirect vulnerability.

+ +

For example, this rule is dangerous:

+ + +# DANGEROUS - allows open redirect +RewriteRule "^/redirect" "%{QUERY_STRING}" [R,L] + + +

An attacker could use +https://yoursite.com/redirect?https://evil.com to redirect +users to a malicious site. Always validate or constrain redirect +targets. If the destination must be on your own site, ensure the +substitution begins with / (a relative path) rather than +allowing a full URL from user input.

+ +
+ +
Server-Side Request Forgery (SSRF) + +

When using the [P] (proxy) flag, +mod_rewrite causes the server to make an HTTP request +to the substitution URL on behalf of the client. If any part of that +URL is derived from user input - backreferences, query strings, or +headers - an attacker may be able to cause your server to make requests +to arbitrary internal services or external hosts.

+ +

For example:

+ + +# DANGEROUS - user controls the proxy target +RewriteCond "%{QUERY_STRING}" "target=(.+)" +RewriteRule "^/fetch" "http://%1" [P] + + +

An attacker could use this to probe internal network services that +are not otherwise accessible from the internet. Always use a fixed +hostname in proxy targets, and limit backreferences to the path +component only.

+ +
+ +
Path Traversal + +

Rewrite rules that map user-supplied path components directly to +the filesystem can allow path traversal attacks if the input is not +properly constrained. For example:

+ + +# DANGEROUS - allows path traversal +RewriteRule "^/files/(.+)" "/var/data/$1" [L] + + +

A request for /files/../../etc/passwd could potentially +access files outside the intended directory. Use restrictive patterns +in your RewriteRule (for +example, [a-zA-Z0-9_-]+ instead of .+), and +rely on Apache's built-in protections +(Options and +Directory +restrictions) as defense in depth.

+ +
+ +
+