Fix proxied logging X-Forwarded-For IP address.

This commit is contained in:
voussoir 2025-11-14 17:15:44 -08:00
parent c319c6fd58
commit 8656b02403

View file

@ -6,7 +6,6 @@ vlogging.earlybird_config()
import gevent.monkey; gevent.monkey.patch_all() import gevent.monkey; gevent.monkey.patch_all()
import werkzeug.middleware.proxy_fix import werkzeug.middleware.proxy_fix
import argparse import argparse
import gevent.pywsgi import gevent.pywsgi
import os import os
@ -24,10 +23,16 @@ import backend
site = backend.site site = backend.site
site.wsgi_app = werkzeug.middleware.proxy_fix.ProxyFix(site.wsgi_app) site.wsgi_app = werkzeug.middleware.proxy_fix.ProxyFix(site.wsgi_app)
site.debug = True site.debug = False
HTTPS_DIR = pathclass.Path(__file__).parent.with_child('https') HTTPS_DIR = pathclass.Path(__file__).parent.with_child('https')
def fix_proxied_logging(method):
def format_request(self, *a, **k):
self.client_address = self.headers.get('X-Forwarded-For', self.client_address)
return method(self, *a, **k)
return format_request
#################################################################################################### ####################################################################################################
def etiquette_flask_launch( def etiquette_flask_launch(
@ -52,6 +57,8 @@ def etiquette_flask_launch(
application=site, application=site,
) )
http.handler_class.format_request = fix_proxied_logging(http.handler_class.format_request)
if localhost_only: if localhost_only:
log.info('Setting localhost_only=True') log.info('Setting localhost_only=True')
site.localhost_only = True site.localhost_only = True