Modify ↓
#11718 closed defect (wontfix)
Logged IP 127.0.0.1 behind proxy
| Reported by: | ak | Owned by: | Jun Omae |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | general | Version: | 1.0.1 |
| Severity: | minor | Keywords: | patch proxy |
| Cc: | Branch: | ||
| Release Notes: | |||
| API Changes: | |||
| Internal Changes: | |||
Description
If Nginx is used behind a proxy like Nginx, the IP of the author is always logged as 127.0.0.1. This is not desirable. The following patch can be used:
-
trac/web/api.py
348 348 @property 349 349 def remote_addr(self): 350 350 """IP address of the remote user""" 351 return self.environ.get(' REMOTE_ADDR')351 return self.environ.get('HTTP_X_REAL_IP') or self.environ.get('REMOTE_ADDR') 352 352 353 353 @property 354 354 def remote_user(self):
Attachments (0)
Change History (8)
comment:1 by , 11 years ago
| Milestone: | → next-stable-1.0.x |
|---|
comment:2 by , 11 years ago
| Keywords: | patch added |
|---|
Patch is included. I believe it is customary to add a keyword.
comment:3 by , 11 years ago
| Keywords: | proxy added |
|---|---|
| Milestone: | next-stable-1.0.x → 1.0.3 |
| Owner: | set to |
| Status: | new → assigned |
comment:4 by , 11 years ago
| Milestone: | 1.0.3 → 1.0.4 |
|---|
comment:5 by , 11 years ago
| Milestone: | 1.0.4 → 1.0.5 |
|---|
comment:6 by , 11 years ago
After reconsideration, I'd suggest wontfix. We cannot always trust X-Real-IP header since anyone can send it with any value.
Instead, add the following to your *.wsgi script.
_known_remotes = ['192.168.0.2'] # replace with your proxy's addresses def application(environ, start_request): if 'HTTP_X_REAL_IP' in environ and \ environ.get('REMOTE_ADDR') in _known_remotes: environ['REMOTE_ADDR'] = environ['HTTP_X_REAL_IP'] .... from trac.web.main import dispatch_request return dispatch_request(environ, start_request)
comment:7 by , 11 years ago
| Milestone: | 1.0.5 |
|---|---|
| Resolution: | → wontfix |
| Status: | assigned → closed |
Closing….
Note:
See TracTickets
for help on using tickets.



Using
X-Real-IPwould be to avoid troubles. But, I thinkX-Forwarded-Foris in more common use.trac/web/api.py