|
|
8c01aa |
diff --git a/docs/manual/rewrite/flags.html.en b/docs/manual/rewrite/flags.html.en
|
|
|
8c01aa |
index 80d0759..9673094 100644
|
|
|
8c01aa |
--- a/docs/manual/rewrite/flags.html.en
|
|
|
8c01aa |
+++ b/docs/manual/rewrite/flags.html.en
|
|
|
8c01aa |
@@ -85,10 +85,6 @@ of how you might use them.
|
|
|
8c01aa |
|
|
|
8c01aa |
The [B] flag instructs RewriteRule to escape non-alphanumeric
|
|
|
8c01aa |
characters before applying the transformation.
|
|
|
8c01aa |
-In 2.4.26 and later, you can limit the escaping to specific characters
|
|
|
8c01aa |
-in backreferences by listing them: [B=#?;] . Note: The space
|
|
|
8c01aa |
-character can be used in the list of characters to escape, but it cannot be
|
|
|
8c01aa |
-the last character in the list.
|
|
|
8c01aa |
|
|
|
8c01aa |
mod_rewrite has to unescape URLs before mapping them,
|
|
|
8c01aa |
so backreferences are unescaped at the time they are applied.
|
|
|
8c01aa |
@@ -120,6 +116,16 @@ when the backend may break if presented with an unescaped URL.
|
|
|
8c01aa |
|
|
|
8c01aa |
An alternative to this flag is using a RewriteCond to capture against %{THE_REQUEST} which will capture
|
|
|
8c01aa |
strings in the encoded form.
|
|
|
8c01aa |
+
|
|
|
8c01aa |
+In 2.4.26 and later, you can limit the escaping to specific characters
|
|
|
8c01aa |
+in backreferences by listing them: [B=#?;] . Note: The space
|
|
|
8c01aa |
+character can be used in the list of characters to escape, but you must quote
|
|
|
8c01aa |
+the entire third argument of RewriteRule
|
|
|
8c01aa |
+and the space must not be the last character in the list.
|
|
|
8c01aa |
+
|
|
|
8c01aa |
+# Escape spaces and question marks.
|
|
|
8c01aa |
+RewriteRule "^search/(.*)$" "/search.php?term=$1" "[B= ?]"
|
|
|
8c01aa |
+
|
|
|
8c01aa |
|
|
|
8c01aa |
|
|
|
8c01aa |
|
|
|
8c01aa |
diff --git a/modules/http2/mod_proxy_http2.c b/modules/http2/mod_proxy_http2.c
|
|
|
8c01aa |
index a7e0dcd..9aa1f89 100644
|
|
|
8c01aa |
--- a/modules/http2/mod_proxy_http2.c
|
|
|
8c01aa |
+++ b/modules/http2/mod_proxy_http2.c
|
|
|
8c01aa |
@@ -178,6 +178,16 @@ static int proxy_http2_canon(request_rec *r, char *url)
|
|
|
8c01aa |
path = ap_proxy_canonenc(r->pool, url, (int)strlen(url),
|
|
|
8c01aa |
enc_path, 0, r->proxyreq);
|
|
|
8c01aa |
search = r->args;
|
|
|
8c01aa |
+ if (search && *(ap_scan_vchar_obstext(search))) {
|
|
|
8c01aa |
+ /*
|
|
|
8c01aa |
+ * We have a raw control character or a ' ' in r->args.
|
|
|
8c01aa |
+ * Correct encoding was missed.
|
|
|
8c01aa |
+ */
|
|
|
8c01aa |
+ ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(10412)
|
|
|
8c01aa |
+ "To be forwarded query string contains control "
|
|
|
8c01aa |
+ "characters or spaces");
|
|
|
8c01aa |
+ return HTTP_FORBIDDEN;
|
|
|
8c01aa |
+ }
|
|
|
8c01aa |
}
|
|
|
8c01aa |
break;
|
|
|
8c01aa |
case PROXYREQ_PROXY:
|
|
|
8c01aa |
diff --git a/modules/mappers/mod_rewrite.c b/modules/mappers/mod_rewrite.c
|
|
|
8c01aa |
index 38dbb24..7e2b452 100644
|
|
|
8c01aa |
--- a/modules/mappers/mod_rewrite.c
|
|
|
8c01aa |
+++ b/modules/mappers/mod_rewrite.c
|
|
|
8c01aa |
@@ -168,6 +168,7 @@ static const char* really_last_key = "rewrite_really_last";
|
|
|
8c01aa |
#define RULEFLAG_END (1<<17)
|
|
|
8c01aa |
#define RULEFLAG_ESCAPENOPLUS (1<<18)
|
|
|
8c01aa |
#define RULEFLAG_QSLAST (1<<19)
|
|
|
8c01aa |
+#define RULEFLAG_QSNONE (1<<20) /* programattic only */
|
|
|
8c01aa |
|
|
|
8c01aa |
/* return code of the rewrite rule
|
|
|
8c01aa |
* the result may be escaped - or not
|
|
|
8c01aa |
@@ -761,15 +762,24 @@ static char *escape_absolute_uri(apr_pool_t *p, char *uri, unsigned scheme)
|
|
|
8c01aa |
ap_escape_uri(p, cp), NULL);
|
|
|
8c01aa |
}
|
|
|
8c01aa |
|
|
|
8c01aa |
+
|
|
|
8c01aa |
/*
|
|
|
8c01aa |
* split out a QUERY_STRING part from
|
|
|
8c01aa |
* the current URI string
|
|
|
8c01aa |
*/
|
|
|
8c01aa |
-static void splitout_queryargs(request_rec *r, int qsappend, int qsdiscard,
|
|
|
8c01aa |
- int qslast)
|
|
|
8c01aa |
+static void splitout_queryargs(request_rec *r, int flags)
|
|
|
8c01aa |
{
|
|
|
8c01aa |
char *q;
|
|
|
8c01aa |
int split;
|
|
|
8c01aa |
+ int qsappend = flags & RULEFLAG_QSAPPEND;
|
|
|
8c01aa |
+ int qsdiscard = flags & RULEFLAG_QSDISCARD;
|
|
|
8c01aa |
+ int qslast = flags & RULEFLAG_QSLAST;
|
|
|
8c01aa |
+
|
|
|
8c01aa |
+ if (flags & RULEFLAG_QSNONE) {
|
|
|
8c01aa |
+ rewritelog((r, 2, NULL, "discarding query string, no parse from substitution"));
|
|
|
8c01aa |
+ r->args = NULL;
|
|
|
8c01aa |
+ return;
|
|
|
8c01aa |
+ }
|
|
|
8c01aa |
|
|
|
8c01aa |
/* don't touch, unless it's a scheme for which a query string makes sense.
|
|
|
8c01aa |
* See RFC 1738 and RFC 2368.
|
|
|
8c01aa |
@@ -794,7 +804,7 @@ static void splitout_queryargs(request_rec *r, int qsappend, int qsdiscard,
|
|
|
8c01aa |
olduri = apr_pstrdup(r->pool, r->filename);
|
|
|
8c01aa |
*q++ = '\0';
|
|
|
8c01aa |
if (qsappend) {
|
|
|
8c01aa |
- if (*q) {
|
|
|
8c01aa |
+ if (*q) {
|
|
|
8c01aa |
r->args = apr_pstrcat(r->pool, q, "&" , r->args, NULL);
|
|
|
8c01aa |
}
|
|
|
8c01aa |
}
|
|
|
8c01aa |
@@ -802,9 +812,9 @@ static void splitout_queryargs(request_rec *r, int qsappend, int qsdiscard,
|
|
|
8c01aa |
r->args = apr_pstrdup(r->pool, q);
|
|
|
8c01aa |
}
|
|
|
8c01aa |
|
|
|
8c01aa |
- if (r->args) {
|
|
|
8c01aa |
+ if (r->args) {
|
|
|
8c01aa |
len = strlen(r->args);
|
|
|
8c01aa |
-
|
|
|
8c01aa |
+
|
|
|
8c01aa |
if (!len) {
|
|
|
8c01aa |
r->args = NULL;
|
|
|
8c01aa |
}
|
|
|
8c01aa |
@@ -2733,7 +2743,7 @@ static apr_status_t rewritelock_remove(void *data)
|
|
|
8c01aa |
* XXX: what an inclined parser. Seems we have to leave it so
|
|
|
8c01aa |
* for backwards compat. *sigh*
|
|
|
8c01aa |
*/
|
|
|
8c01aa |
-static int parseargline(char *str, char **a1, char **a2, char **a3)
|
|
|
8c01aa |
+static int parseargline(char *str, char **a1, char **a2, char **a2_end, char **a3)
|
|
|
8c01aa |
{
|
|
|
8c01aa |
char quote;
|
|
|
8c01aa |
|
|
|
8c01aa |
@@ -2784,8 +2794,10 @@ static int parseargline(char *str, char **a1, char **a2, char **a3)
|
|
|
8c01aa |
|
|
|
8c01aa |
if (!*str) {
|
|
|
8c01aa |
*a3 = NULL; /* 3rd argument is optional */
|
|
|
8c01aa |
+ *a2_end = str;
|
|
|
8c01aa |
return 0;
|
|
|
8c01aa |
}
|
|
|
8c01aa |
+ *a2_end = str;
|
|
|
8c01aa |
*str++ = '\0';
|
|
|
8c01aa |
|
|
|
8c01aa |
while (apr_isspace(*str)) {
|
|
|
8c01aa |
@@ -3323,7 +3335,7 @@ static const char *cmd_rewritecond(cmd_parms *cmd, void *in_dconf,
|
|
|
8c01aa |
rewrite_server_conf *sconf;
|
|
|
8c01aa |
rewritecond_entry *newcond;
|
|
|
8c01aa |
ap_regex_t *regexp;
|
|
|
8c01aa |
- char *a1 = NULL, *a2 = NULL, *a3 = NULL;
|
|
|
8c01aa |
+ char *a1 = NULL, *a2 = NULL, *a2_end, *a3 = NULL;
|
|
|
8c01aa |
const char *err;
|
|
|
8c01aa |
|
|
|
8c01aa |
sconf = ap_get_module_config(cmd->server->module_config, &rewrite_module);
|
|
|
8c01aa |
@@ -3341,7 +3353,7 @@ static const char *cmd_rewritecond(cmd_parms *cmd, void *in_dconf,
|
|
|
8c01aa |
* of the argument line. So we can use a1 .. a3 without
|
|
|
8c01aa |
* copying them again.
|
|
|
8c01aa |
*/
|
|
|
8c01aa |
- if (parseargline(str, &a1, &a2, &a3)) {
|
|
|
8c01aa |
+ if (parseargline(str, &a1, &a2, &a2_end, &a3)) {
|
|
|
8c01aa |
return apr_pstrcat(cmd->pool, "RewriteCond: bad argument line '", str,
|
|
|
8c01aa |
"'", NULL);
|
|
|
8c01aa |
}
|
|
|
8c01aa |
@@ -3749,7 +3761,7 @@ static const char *cmd_rewriterule(cmd_parms *cmd, void *in_dconf,
|
|
|
8c01aa |
rewrite_server_conf *sconf;
|
|
|
8c01aa |
rewriterule_entry *newrule;
|
|
|
8c01aa |
ap_regex_t *regexp;
|
|
|
8c01aa |
- char *a1 = NULL, *a2 = NULL, *a3 = NULL;
|
|
|
8c01aa |
+ char *a1 = NULL, *a2 = NULL, *a2_end, *a3 = NULL;
|
|
|
8c01aa |
const char *err;
|
|
|
8c01aa |
|
|
|
8c01aa |
sconf = ap_get_module_config(cmd->server->module_config, &rewrite_module);
|
|
|
8c01aa |
@@ -3763,7 +3775,7 @@ static const char *cmd_rewriterule(cmd_parms *cmd, void *in_dconf,
|
|
|
8c01aa |
}
|
|
|
8c01aa |
|
|
|
8c01aa |
/* parse the argument line ourself */
|
|
|
8c01aa |
- if (parseargline(str, &a1, &a2, &a3)) {
|
|
|
8c01aa |
+ if (parseargline(str, &a1, &a2, &a2_end, &a3)) {
|
|
|
8c01aa |
return apr_pstrcat(cmd->pool, "RewriteRule: bad argument line '", str,
|
|
|
8c01aa |
"'", NULL);
|
|
|
8c01aa |
}
|
|
|
8c01aa |
@@ -3810,6 +3822,17 @@ static const char *cmd_rewriterule(cmd_parms *cmd, void *in_dconf,
|
|
|
8c01aa |
newrule->flags |= RULEFLAG_NOSUB;
|
|
|
8c01aa |
}
|
|
|
8c01aa |
|
|
|
8c01aa |
+ if (*(a2_end-1) == '?') {
|
|
|
8c01aa |
+ /* a literal ? at the end of the unsubstituted rewrite rule */
|
|
|
8c01aa |
+ newrule->flags |= RULEFLAG_QSNONE;
|
|
|
8c01aa |
+ *(a2_end-1) = '\0'; /* trailing ? has done its job */
|
|
|
8c01aa |
+ }
|
|
|
8c01aa |
+ else if (newrule->flags & RULEFLAG_QSDISCARD) {
|
|
|
8c01aa |
+ if (NULL == ap_strchr(newrule->output, '?')) {
|
|
|
8c01aa |
+ newrule->flags |= RULEFLAG_QSNONE;
|
|
|
8c01aa |
+ }
|
|
|
8c01aa |
+ }
|
|
|
8c01aa |
+
|
|
|
8c01aa |
/* now, if the server or per-dir config holds an
|
|
|
8c01aa |
* array of RewriteCond entries, we take it for us
|
|
|
8c01aa |
* and clear the array
|
|
|
8c01aa |
@@ -4215,9 +4238,7 @@ static int apply_rewrite_rule(rewriterule_entry *p, rewrite_ctx *ctx)
|
|
|
8c01aa |
r->path_info = NULL;
|
|
|
8c01aa |
}
|
|
|
8c01aa |
|
|
|
8c01aa |
- splitout_queryargs(r, p->flags & RULEFLAG_QSAPPEND,
|
|
|
8c01aa |
- p->flags & RULEFLAG_QSDISCARD,
|
|
|
8c01aa |
- p->flags & RULEFLAG_QSLAST);
|
|
|
8c01aa |
+ splitout_queryargs(r, p->flags);
|
|
|
8c01aa |
|
|
|
8c01aa |
/* Add the previously stripped per-directory location prefix, unless
|
|
|
8c01aa |
* (1) it's an absolute URL path and
|
|
|
8c01aa |
@@ -4699,6 +4720,17 @@ static int hook_uri2file(request_rec *r)
|
|
|
8c01aa |
unsigned skip;
|
|
|
8c01aa |
apr_size_t flen;
|
|
|
8c01aa |
|
|
|
8c01aa |
+ if (r->args && *(ap_scan_vchar_obstext(r->args))) {
|
|
|
8c01aa |
+ /*
|
|
|
8c01aa |
+ * We have a raw control character or a ' ' in r->args.
|
|
|
8c01aa |
+ * Correct encoding was missed.
|
|
|
8c01aa |
+ */
|
|
|
8c01aa |
+ ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(10410)
|
|
|
8c01aa |
+ "Rewritten query string contains control "
|
|
|
8c01aa |
+ "characters or spaces");
|
|
|
8c01aa |
+ return HTTP_FORBIDDEN;
|
|
|
8c01aa |
+ }
|
|
|
8c01aa |
+
|
|
|
8c01aa |
if (ACTION_STATUS == rulestatus) {
|
|
|
8c01aa |
int n = r->status;
|
|
|
8c01aa |
|
|
|
8c01aa |
@@ -4983,6 +5015,17 @@ static int hook_fixup(request_rec *r)
|
|
|
8c01aa |
if (rulestatus) {
|
|
|
8c01aa |
unsigned skip;
|
|
|
8c01aa |
|
|
|
8c01aa |
+ if (r->args && *(ap_scan_vchar_obstext(r->args))) {
|
|
|
8c01aa |
+ /*
|
|
|
8c01aa |
+ * We have a raw control character or a ' ' in r->args.
|
|
|
8c01aa |
+ * Correct encoding was missed.
|
|
|
8c01aa |
+ */
|
|
|
8c01aa |
+ ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(10411)
|
|
|
8c01aa |
+ "Rewritten query string contains control "
|
|
|
8c01aa |
+ "characters or spaces");
|
|
|
8c01aa |
+ return HTTP_FORBIDDEN;
|
|
|
8c01aa |
+ }
|
|
|
8c01aa |
+
|
|
|
8c01aa |
if (ACTION_STATUS == rulestatus) {
|
|
|
8c01aa |
int n = r->status;
|
|
|
8c01aa |
|
|
|
8c01aa |
diff --git a/modules/proxy/mod_proxy_ajp.c b/modules/proxy/mod_proxy_ajp.c
|
|
|
8c01aa |
index eb550e5..8b8d09e 100644
|
|
|
8c01aa |
--- a/modules/proxy/mod_proxy_ajp.c
|
|
|
8c01aa |
+++ b/modules/proxy/mod_proxy_ajp.c
|
|
|
8c01aa |
@@ -69,6 +69,16 @@ static int proxy_ajp_canon(request_rec *r, char *url)
|
|
|
8c01aa |
path = ap_proxy_canonenc(r->pool, url, strlen(url), enc_path, 0,
|
|
|
8c01aa |
r->proxyreq);
|
|
|
8c01aa |
search = r->args;
|
|
|
8c01aa |
+ if (search && *(ap_scan_vchar_obstext(search))) {
|
|
|
8c01aa |
+ /*
|
|
|
8c01aa |
+ * We have a raw control character or a ' ' in r->args.
|
|
|
8c01aa |
+ * Correct encoding was missed.
|
|
|
8c01aa |
+ */
|
|
|
8c01aa |
+ ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(10406)
|
|
|
8c01aa |
+ "To be forwarded query string contains control "
|
|
|
8c01aa |
+ "characters or spaces");
|
|
|
8c01aa |
+ return HTTP_FORBIDDEN;
|
|
|
8c01aa |
+ }
|
|
|
8c01aa |
}
|
|
|
8c01aa |
if (path == NULL)
|
|
|
8c01aa |
return HTTP_BAD_REQUEST;
|
|
|
8c01aa |
diff --git a/modules/proxy/mod_proxy_balancer.c b/modules/proxy/mod_proxy_balancer.c
|
|
|
8c01aa |
index c6c7e89..9a5cb08 100644
|
|
|
8c01aa |
--- a/modules/proxy/mod_proxy_balancer.c
|
|
|
8c01aa |
+++ b/modules/proxy/mod_proxy_balancer.c
|
|
|
8c01aa |
@@ -106,6 +106,16 @@ static int proxy_balancer_canon(request_rec *r, char *url)
|
|
|
8c01aa |
path = ap_proxy_canonenc(r->pool, url, strlen(url), enc_path, 0,
|
|
|
8c01aa |
r->proxyreq);
|
|
|
8c01aa |
search = r->args;
|
|
|
8c01aa |
+ if (search && *(ap_scan_vchar_obstext(search))) {
|
|
|
8c01aa |
+ /*
|
|
|
8c01aa |
+ * We have a raw control character or a ' ' in r->args.
|
|
|
8c01aa |
+ * Correct encoding was missed.
|
|
|
8c01aa |
+ */
|
|
|
8c01aa |
+ ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(10407)
|
|
|
8c01aa |
+ "To be forwarded query string contains control "
|
|
|
8c01aa |
+ "characters or spaces");
|
|
|
8c01aa |
+ return HTTP_FORBIDDEN;
|
|
|
8c01aa |
+ }
|
|
|
8c01aa |
}
|
|
|
8c01aa |
if (path == NULL)
|
|
|
8c01aa |
return HTTP_BAD_REQUEST;
|
|
|
8c01aa |
diff --git a/modules/proxy/mod_proxy_http.c b/modules/proxy/mod_proxy_http.c
|
|
|
8c01aa |
index a33b57b..f528d94 100644
|
|
|
8c01aa |
--- a/modules/proxy/mod_proxy_http.c
|
|
|
8c01aa |
+++ b/modules/proxy/mod_proxy_http.c
|
|
|
8c01aa |
@@ -90,6 +90,16 @@ static int proxy_http_canon(request_rec *r, char *url)
|
|
|
8c01aa |
path = ap_proxy_canonenc(r->pool, url, strlen(url),
|
|
|
8c01aa |
enc_path, 0, r->proxyreq);
|
|
|
8c01aa |
search = r->args;
|
|
|
8c01aa |
+ if (search && *(ap_scan_vchar_obstext(search))) {
|
|
|
8c01aa |
+ /*
|
|
|
8c01aa |
+ * We have a raw control character or a ' ' in r->args.
|
|
|
8c01aa |
+ * Correct encoding was missed.
|
|
|
8c01aa |
+ */
|
|
|
8c01aa |
+ ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(10408)
|
|
|
8c01aa |
+ "To be forwarded query string contains control "
|
|
|
8c01aa |
+ "characters or spaces");
|
|
|
8c01aa |
+ return HTTP_FORBIDDEN;
|
|
|
8c01aa |
+ }
|
|
|
8c01aa |
}
|
|
|
8c01aa |
break;
|
|
|
8c01aa |
case PROXYREQ_PROXY:
|
|
|
8c01aa |
diff --git a/modules/proxy/mod_proxy_wstunnel.c b/modules/proxy/mod_proxy_wstunnel.c
|
|
|
8c01aa |
index 9dda010..05f5d1e 100644
|
|
|
8c01aa |
--- a/modules/proxy/mod_proxy_wstunnel.c
|
|
|
8c01aa |
+++ b/modules/proxy/mod_proxy_wstunnel.c
|
|
|
8c01aa |
@@ -73,6 +73,16 @@ static int proxy_wstunnel_canon(request_rec *r, char *url)
|
|
|
8c01aa |
path = ap_proxy_canonenc(r->pool, url, strlen(url), enc_path, 0,
|
|
|
8c01aa |
r->proxyreq);
|
|
|
8c01aa |
search = r->args;
|
|
|
8c01aa |
+ if (search && *(ap_scan_vchar_obstext(search))) {
|
|
|
8c01aa |
+ /*
|
|
|
8c01aa |
+ * We have a raw control character or a ' ' in r->args.
|
|
|
8c01aa |
+ * Correct encoding was missed.
|
|
|
8c01aa |
+ */
|
|
|
8c01aa |
+ ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(10409)
|
|
|
8c01aa |
+ "To be forwarded query string contains control "
|
|
|
8c01aa |
+ "characters or spaces");
|
|
|
8c01aa |
+ return HTTP_FORBIDDEN;
|
|
|
8c01aa |
+ }
|
|
|
8c01aa |
}
|
|
|
8c01aa |
if (path == NULL)
|
|
|
8c01aa |
return HTTP_BAD_REQUEST;
|