Changeset - 088155584e2e
[Not reviewed]
default
0 3 0
Mads Kiilerich - 7 years ago 2018-12-26 03:03:31
mads@kiilerich.com
auth: make sure request.authuser *always* has been checked for check_ip_allowed - there is thus no need to check it later
3 files changed with 7 insertions and 7 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/login.py
Show inline comments
 
@@ -73,16 +73,14 @@ class LoginController(BaseController):
 
            if not self._validate_came_from(c.came_from):
 
                log.error('Invalid came_from (not server-relative): %r', c.came_from)
 
                raise HTTPBadRequest()
 
        else:
 
            c.came_from = url('home')
 

	
 
        ip_allowed = AuthUser.check_ip_allowed(request.authuser, request.ip_addr)
 

	
 
        # redirect if already logged in
 
        if request.authuser.is_authenticated and ip_allowed:
 
        if request.authuser.is_authenticated:
 
            raise HTTPFound(location=c.came_from)
 

	
 
        if request.POST:
 
            # import Login Form validator class
 
            login_form = LoginForm()()
 
            try:
kallithea/lib/auth.py
Show inline comments
 
@@ -774,15 +774,12 @@ class LoginRequired(object):
 
    def __wrapper(self, func, *fargs, **fkwargs):
 
        controller = fargs[0]
 
        user = request.authuser
 
        loc = "%s:%s" % (controller.__class__.__name__, func.__name__)
 
        log.debug('Checking access for user %s @ %s', user, loc)
 

	
 
        if not AuthUser.check_ip_allowed(user, request.ip_addr):
 
            raise _redirect_to_login(_('IP %s not allowed') % request.ip_addr)
 

	
 
        # Check if we used an API key to authenticate.
 
        api_key = user.authenticating_api_key
 
        if api_key is not None:
 
            # Check that controller is enabled for API key usage.
 
            if not self.api_access and not allowed_api_access(loc, api_key=api_key):
 
                # controller does not allow API access
kallithea/lib/base.py
Show inline comments
 
@@ -526,18 +526,23 @@ class BaseController(TGController):
 
            except (ValueError, TypeError):
 
                pass
 
            else:
 
                if type.lower() == 'bearer':
 
                    bearer_token = params
 

	
 
            request.authuser = self._determine_auth_user(
 
            authuser = self._determine_auth_user(
 
                request.GET.get('api_key'),
 
                bearer_token,
 
                session.get('authuser'),
 
            )
 

	
 
            if not AuthUser.check_ip_allowed(authuser, request.ip_addr):
 
                raise webob.exc.HTTPForbidden()
 

	
 
            request.authuser = authuser
 

	
 
            log.info('IP: %s User: %s accessed %s',
 
                request.ip_addr, request.authuser,
 
                safe_unicode(_get_access_path(environ)),
 
            )
 
            return super(BaseController, self).__call__(environ, context)
 
        except webob.exc.HTTPException as e:
0 comments (0 inline, 0 general)