##// END OF EJS Templates
auth: only use X- headers instead of wsgi.url_scheme if explicitly told so in url_scheme_header - drop https_fixup setting...
auth: only use X- headers instead of wsgi.url_scheme if explicitly told so in url_scheme_header - drop https_fixup setting Before, several X- headers would be trusted to overrule the actual connection protocol (http or https) seen by the Kallithea WSGI server. That was mainly when https_fixup were set, but it incorrectly also kicked in if https_fixup or use_htsts were configured. The ambiguity of which headers were used also made it less reliable. The proxy server not only had to be configured to set one of the headers correctly, it also had to make sure other headers were not passed on from the client. It would thus in some cases be possible for clients to fake the connection scheme, and thus potentially be possible to bypass restrictions configured in Kallithea. Fixed by making it configurable which WSGI environment variable to use for the protocol. Users can configure url_scheme_header to for example HTTP_X_FORWARDED_PROTO instead of using the default wsgi.url_scheme . This change is a bit similar to what is going on in the https_fixup middleware, but is doing a bit more of what for example is happening in similar code in werkzeug/middleware/proxy_fix.py . The semantics of the old https_fixup were unsafe, so it has been dropped. Admins that are upgrading must change their configuration to use the new url_scheme_header option.

File last commit:

r8680:070b8c39 default
r8680:070b8c39 default
Show More
application.py
68 lines | 2.8 KiB | text/x-python | PythonLexer
# -*- coding: utf-8 -*-
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""WSGI middleware initialization for the Kallithea application."""
from kallithea.config.app_cfg import base_config
from kallithea.config.middleware.https_fixup import HttpsFixup
from kallithea.config.middleware.permanent_repo_url import PermanentRepoUrl
from kallithea.config.middleware.simplegit import SimpleGit
from kallithea.config.middleware.simplehg import SimpleHg
from kallithea.config.middleware.wrapper import RequestWrapper
from kallithea.lib.utils2 import asbool
__all__ = ['make_app']
def wrap_app(app):
"""Wrap the TG WSGI application in Kallithea middleware"""
config = app.config
# we want our low level middleware to get to the request ASAP. We don't
# need any stack middleware in them - especially no StatusCodeRedirect buffering
app = SimpleHg(app, config)
app = SimpleGit(app, config)
# Enable https redirects based on HTTP_X_URL_SCHEME set by proxy
if any(asbool(config.get(x)) for x in ['url_scheme_variable', 'force_https', 'use_htsts']):
app = HttpsFixup(app, config)
app = PermanentRepoUrl(app, config)
# Optional and undocumented wrapper - gives more verbose request/response logging, but has a slight overhead
if asbool(config.get('use_wsgi_wrapper')):
app = RequestWrapper(app, config)
return app
def make_app(global_conf, **app_conf):
"""
Set up Kallithea with the settings found in the PasteDeploy configuration
file used.
:param global_conf: The global settings for Kallithea (those
defined under the ``[DEFAULT]`` section).
:return: The Kallithea application with all the relevant middleware
loaded.
This is the PasteDeploy factory for the Kallithea application.
``app_conf`` contains all the application-specific settings (those defined
under ``[app:main]``.
"""
assert app_conf.get('sqlalchemy.url') # must be called with a Kallithea .ini file, which for example must have this config option
assert global_conf.get('here') and global_conf.get('__file__') # app config should be initialized the paste way ...
return base_config.make_wsgi_app(global_conf, app_conf, wrap_app=wrap_app)