Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
ed8b8062
Commit
ed8b8062
authored
May 04, 2007
by
Martijn Pieters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Collector #2321: skip trusted proxies when extracting the client ip from X-Forwarded-For
parent
54109450
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
1 deletion
+44
-1
doc/CHANGES.txt
doc/CHANGES.txt
+3
-0
lib/python/ZPublisher/HTTPRequest.py
lib/python/ZPublisher/HTTPRequest.py
+9
-1
lib/python/ZPublisher/tests/testHTTPRequest.py
lib/python/ZPublisher/tests/testHTTPRequest.py
+32
-0
No files found.
doc/CHANGES.txt
View file @
ed8b8062
...
...
@@ -8,6 +8,9 @@ Zope Changes
Bugs fixed
- Collector #2321: Skip trusted proxies when extracting the client IP
address from the request.
- Collector #2318: Allow override of zopectl's control socket in
zope.conf
...
...
lib/python/ZPublisher/HTTPRequest.py
View file @
ed8b8062
...
...
@@ -269,7 +269,15 @@ class HTTPRequest(BaseRequest):
if
environ
.
has_key
(
'HTTP_X_FORWARDED_FOR'
)
and
self
.
_client_addr
in
trusted_proxies
:
# REMOTE_ADDR is one of our trusted local proxies. Not really very remote at all.
# The proxy can tell us the IP of the real remote client in the forwarded-for header
self
.
_client_addr
=
environ
[
'HTTP_X_FORWARDED_FOR'
].
split
(
','
)[
-
1
].
strip
()
# Skip the proxy-address itself though
forwarded_for
=
[
e
.
strip
()
for
e
in
environ
[
'HTTP_X_FORWARDED_FOR'
].
split
(
','
)]
forwarded_for
.
reverse
()
for
entry
in
forwarded_for
:
if
entry
not
in
trusted_proxies
:
self
.
_client_addr
=
entry
break
else
:
self
.
_client_addr
=
''
...
...
lib/python/ZPublisher/tests/testHTTPRequest.py
View file @
ed8b8062
...
...
@@ -702,6 +702,38 @@ class RequestTests( unittest.TestCase ):
self
.
assertEqual
(
f
.
xreadlines
(),
f
)
def
testTrustedProxies
(
self
):
TEST_ENVIRON
=
{
'REQUEST_METHOD'
:
'GET'
,
'SERVER_NAME'
:
'localhost'
,
'SERVER_PORT'
:
'80'
,
'REMOTE_ADDR'
:
'127.0.0.1'
,
'HTTP_X_FORWARDED_FOR'
:
'10.1.20.30, 192.168.1.100'
,
}
from
StringIO
import
StringIO
from
ZPublisher.HTTPRequest
import
HTTPRequest
,
trusted_proxies
s
=
StringIO
(
''
)
env
=
TEST_ENVIRON
.
copy
()
request
=
HTTPRequest
(
s
,
env
,
None
)
self
.
assertEqual
(
request
.
getClientAddr
(),
'127.0.0.1'
)
trusted_proxies
.
append
(
'127.0.0.1'
)
request
=
HTTPRequest
(
s
,
env
,
None
)
self
.
assertEqual
(
request
.
getClientAddr
(),
'192.168.1.100'
)
trusted_proxies
[
0
]
=
'192.168.1.100'
env
=
TEST_ENVIRON
.
copy
()
env
[
'REMOTE_ADDR'
]
=
'192.168.1.100'
request
=
HTTPRequest
(
s
,
env
,
None
)
self
.
assertEqual
(
request
.
getClientAddr
(),
'10.1.20.30'
)
env
=
TEST_ENVIRON
.
copy
()
del
env
[
'REMOTE_ADDR'
]
request
=
HTTPRequest
(
s
,
env
,
None
)
self
.
assertEqual
(
request
.
getClientAddr
(),
''
)
def
test_suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
AuthCredentialsTestsa
,
'test'
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment