Skip to content

Commit 1e364fc

Browse files
committedFeb 10, 2015
Added support for X-Fowarded-For as trusted proxy header.
1 parent 634b6a4 commit 1e364fc

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed
 

‎src/server/mod_wsgi.c

+32-1
Original file line numberDiff line numberDiff line change
@@ -12356,6 +12356,7 @@ static void wsgi_drop_invalid_headers(request_rec *r)
1235612356
}
1235712357

1235812358
static const char *wsgi_proxy_headers[] = {
12359+
"HTTP_X_FORWARDED_FOR",
1235912360
"HTTP_X_FORWARDED_HTTPS",
1236012361
"HTTP_X_FORWARDED_PROTO",
1236112362
"HTTP_X_FORWARDED_SCHEME",
@@ -12395,7 +12396,37 @@ static void wsgi_process_proxy_headers(request_rec *r)
1239512396
value = apr_table_get(r->subprocess_env, name);
1239612397

1239712398
if (value) {
12398-
if (!strcmp(name, "HTTP_X_FORWARDED_PROTO") ||
12399+
if (!strcmp(name, "HTTP_X_FORWARDED_FOR")) {
12400+
const char *end = NULL;
12401+
12402+
/*
12403+
* A potentially comma separated list where client
12404+
* we are interested in will be listed first.
12405+
*/
12406+
12407+
while (*value != '\0' && apr_isspace(*value))
12408+
value++;
12409+
12410+
if (*value != '\0') {
12411+
end = value;
12412+
12413+
while (*end != '\0' && *end != ',')
12414+
end++;
12415+
12416+
/* Need to deal with trailing whitespace. */
12417+
12418+
while (end != value) {
12419+
if (!apr_isspace(*(end-1)))
12420+
break;
12421+
12422+
end--;
12423+
}
12424+
12425+
apr_table_setn(r->subprocess_env, "REMOTE_ADDR",
12426+
apr_pstrndup(r->pool, value, (end-value)));
12427+
}
12428+
}
12429+
else if (!strcmp(name, "HTTP_X_FORWARDED_PROTO") ||
1239912430
!strcmp(name, "HTTP_X_FORWARDED_SCHEME") ||
1240012431
!strcmp(name, "HTTP_X_SCHEME")) {
1240112432

0 commit comments

Comments
 (0)
Please sign in to comment.