adding the other RFC1918 addresss space to the allowed x-forwarded-for header 
(#183)



Project: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/commit/e1dd5bcf
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/tree/e1dd5bcf
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/diff/e1dd5bcf

Branch: refs/heads/master
Commit: e1dd5bcf09d9bd75e61515a1569cbbb4f2041a10
Parents: 62eac24
Author: kyletrueex <k...@trueex.com>
Authored: Sun Dec 18 14:00:04 2016 -0500
Committer: Bob Ippolito <b...@redivi.com>
Committed: Sun Dec 18 11:00:04 2016 -0800

----------------------------------------------------------------------
 src/mochiweb_request.erl | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/blob/e1dd5bcf/src/mochiweb_request.erl
----------------------------------------------------------------------
diff --git a/src/mochiweb_request.erl b/src/mochiweb_request.erl
index 302d6bc..ec0ad36 100644
--- a/src/mochiweb_request.erl
+++ b/src/mochiweb_request.erl
@@ -119,6 +119,21 @@ get(peer, {?MODULE, [Socket, _Opts, _Method, _RawPath, 
_Version, _Headers]}=THIS
                 Hosts ->
                     string:strip(lists:last(string:tokens(Hosts, ",")))
             end;
+        %% Copied this syntax from webmachine contributor Steve Vinoski
+        {ok, {Addr={172, Second, _, _}, _Port}} when (Second > 15) andalso 
(Second < 32) ->
+            case get_header_value("x-forwarded-for", THIS) of
+                undefined ->
+                    inet_parse:ntoa(Addr);
+                Hosts ->
+                    string:strip(lists:last(string:tokens(Hosts, ",")))
+            end;
+        {ok, {Addr={192, 168, _, _}, _Port}} ->
+            case get_header_value("x-forwarded-for", THIS) of
+                undefined ->
+                    inet_parse:ntoa(Addr);
+                Hosts ->
+                    string:strip(lists:last(string:tokens(Hosts, ",")))
+            end;
         {ok, {{127, 0, 0, 1}, _Port}} ->
             case get_header_value("x-forwarded-for", THIS) of
                 undefined ->

Reply via email to