Skip to content

Commit f366bb6

Browse files
committed
Pass X-Forwarded-For and X-Forwarded-Proto headers as
HTTP_X-FORWARDED-FOR and HTTP_X-FORWARDED-PROTO variables in the tracker environment array. Neither of these variables should be used by the code code unless config.ini params are added to control their use. I use the FORWARDED-FOR variable to disable the reCAPTCHA extenxaion check if it is a local address using: if 'HTTP_X-FORWARDED-FOR' in self.client.env: # if proxied from client at local site, don't validate captcha # used for running automated tests. clientip=self.client.env['HTTP_X-FORWARDED-FOR'].split(',')[0] if clientip.startswith("192.168.10."): secret="none" I run a front end web server that proxies over loopback to the running roundup-server. So I feel I can trust the X-Forwarded-For header. In other setup's that may not be true. Hence the requirement that it not be used in core roundup code without allowing the roundup admin the ability to disable it.
1 parent 27998be commit f366bb6

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

CHANGES.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,13 @@ Features:
209209
from the templating class to the hyperdb. (John Rouillard)
210210
- Improves diagnostics for mail processing: When using logging level = DEBUG,
211211
bounces and bounce problems are logged. (Bernhard Reiter)
212+
- In roundup-server, pass X-Forwarded-For and X-Forwarded-Proto
213+
headers as the environment variables: HTTP_X-FORWARDED-FOR and
214+
HTTP_X_FORWARDED_PROTO. If the user is running roundup server behind
215+
a proxy, these headers allow the user to write extensions that can
216+
figure out the original client ip and protocol. None of the core
217+
roundup code uses these headers/env vars. These headers can be
218+
spoofed by bad proxies etc. so you have been warned.
212219

213220
Fixed:
214221

roundup/scripts/roundup_server.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,38 @@ def inner_run_cgi(self):
375375
env['HTTP_HOST'] = self.headers ['host']
376376
except KeyError:
377377
env['HTTP_HOST'] = ''
378+
# https://tools.ietf.org/html/draft-ietf-appsawg-http-forwarded-10
379+
# headers.
378380
xfh = self.headers.getheader('X-Forwarded-Host', None)
379381
if xfh:
382+
# If behind a proxy, this is the hostname supplied
383+
# via the Host header to the proxy. Used by core code.
384+
# Controlled by the CSRF settings.
380385
env['HTTP_X-FORWARDED-HOST'] = xfh
386+
xff = self.headers.getheader('X-Forwarded-For', None)
387+
if xff:
388+
# xff is a list of ip addresses for original client/proxies:
389+
# X-Forwarded-For: clientIP, proxy1IP, proxy2IP
390+
# May not be trustworthy. Do not use in core without
391+
# config option to control its use.
392+
# Made available for extensions if the user trusts it.
393+
# E.g. you may wish to disable recaptcha validation extension
394+
# if the ip of the client matches 172.16.0.0.
395+
env['HTTP_X-FORWARDED-FOR'] = xff
396+
xfp = self.headers.getheader('X-Forwarded-Proto', None)
397+
if xfp:
398+
# xfp is the protocol (http/https) seen by proxies in the
399+
# path of the request. I am not sure if there is only
400+
# one value or multiple, but I suspect multiple
401+
# is possible so:
402+
# X-Forwarded-Proto: https, http
403+
# is expected if the path is:
404+
# client -> proxy1 -> proxy2 -> back end server
405+
# an proxy1 is an SSL terminator.
406+
# May not be trustworthy. Do not use in core without
407+
# config option to control its use.
408+
# Made available for extensions if the user trusts it.
409+
env['HTTP_X-FORWARDED-PROTO'] = xfp
381410
if os.environ.has_key('CGI_SHOW_TIMING'):
382411
env['CGI_SHOW_TIMING'] = os.environ['CGI_SHOW_TIMING']
383412
env['HTTP_ACCEPT_LANGUAGE'] = self.headers.get('accept-language')

0 commit comments

Comments
 (0)