Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Authorization related issue in Pyramids
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
artee  
View profile  
 More options Oct 8 2012, 4:50 pm
From: artee <artur....@gmail.com>
Date: Mon, 8 Oct 2012 13:50:56 -0700 (PDT)
Local: Mon, Oct 8 2012 4:50 pm
Subject: Authorization related issue in Pyramids

Hi

I've spent a few hours trying to resolve security (authorization) related
problem in a big Pyramid app.
The problem was on my side - an exception was thrown inside __acl__
property on RootFactory level, something like this:
class RootFactory(object):
    @property
    def __acl__(self):
        def load_ACL():
            acl = []
            for group in GroupFacade*.all()*: # 'all' function was not
defined
                ...
            return acl
        return load_ACL()
In result access to all views with permission defined was denied.
After small investigation I've found that this exception was silently
handled on Pyramids side:

for location in lineage(context):
try:
    acl = location.__acl__
except AttributeError:
    *continue*

I think that it should be a good idea to change this behavior or add proper
trace here.
Any exception related to missing attribute here will cause hard to find
error and misleading trace:

<No ACL found on any object in resource lineage>

Any ideas to handle it in a proper way?

--
Thanks
Artur Lew


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris McDonough  
View profile  
 More options Oct 8 2012, 7:20 pm
From: Chris McDonough <chr...@plope.com>
Date: Mon, 08 Oct 2012 19:20:51 -0400
Local: Mon, Oct 8 2012 7:20 pm
Subject: Re: Authorization related issue in Pyramids

I agree it is a problem.  I'm not sure what the best way to handle it
is.  Python is pretty bad at AttributeError introspection, so it might
be necessary to do something horrible like this inside Pyramid:

diff --git a/pyramid/authorization.py b/pyramid/authorization.py
index 943f8bd..33f03ac 100644
--- a/pyramid/authorization.py
+++ b/pyramid/authorization.py
@@ -75,11 +75,21 @@ class ACLAuthorizationPolicy(object):
         acl = '<No ACL found on any object in resource lineage>'

         for location in lineage(context):
+
             try:
                 acl = location.__acl__
-            except AttributeError:
+            except AttributeError as e:
+                # We are trying to catch only the AttributeError
+                # raised as the result of the location w/o __acl__
+                # attribute.  But often __acl__ is defined as a prop
+                # which has logic that itself may raise an unrelated
+                # AttributeError.  Below we make sure that we don't
+                # catch those.  Only way to do that I know of.
+                args = e.args
+                if args and '__acl__' in str(args[0]):
+                    raise
                 continue
-
+                
             for ace in acl:
                 ace_action, ace_principal, ace_permissions = ace
                 if ace_principal in principals:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris McDonough  
View profile  
 More options Oct 8 2012, 7:21 pm
From: Chris McDonough <chr...@plope.com>
Date: Mon, 08 Oct 2012 19:21:50 -0400
Local: Mon, Oct 8 2012 7:21 pm
Subject: Re: Authorization related issue in Pyramids

Er, that diff logic is bogus.  But you get the idea.

- C


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Anderson  
View profile  
 More options Oct 8 2012, 7:31 pm
From: John Anderson <son...@gmail.com>
Date: Mon, 8 Oct 2012 20:25:17 -0300
Local: Mon, Oct 8 2012 7:25 pm
Subject: Re: Authorization related issue in Pyramids
On 10/08, Chris McDonough wrote:

Couldn't we just replace the logic with a hasattr and then if it does
run through the __acl__ like normal without exception handling?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris McDonough  
View profile  
 More options Oct 8 2012, 8:28 pm
From: Chris McDonough <chr...@plope.com>
Date: Mon, 08 Oct 2012 20:27:55 -0400
Local: Mon, Oct 8 2012 8:27 pm
Subject: Re: Authorization related issue in Pyramids

No.  Both hasattr and getattr hide AttributeError.

- C


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "getattr hides AttributeError" by Chris Withers
Chris Withers  
View profile  
 More options Oct 8 2012, 8:34 pm
From: Chris Withers <ch...@simplistix.co.uk>
Date: Tue, 09 Oct 2012 10:04:26 +0930
Local: Mon, Oct 8 2012 8:34 pm
Subject: Re: getattr hides AttributeError
On 09/10/2012 09:57, Chris McDonough wrote:

> No.  Both hasattr and getattr hide AttributeError.

I knew about hasattr, but how does getattr hide AttributeError?

cheers,

Chris

--
Simplistix - Content Management, Batch Processing & Python Consulting
             - http://www.simplistix.co.uk


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris McDonough  
View profile  
 More options Oct 8 2012, 8:42 pm
From: Chris McDonough <chr...@plope.com>
Date: Mon, 08 Oct 2012 20:42:04 -0400
Local: Mon, Oct 8 2012 8:42 pm
Subject: Re: getattr hides AttributeError

On Tue, 2012-10-09 at 10:04 +0930, Chris Withers wrote:
> On 09/10/2012 09:57, Chris McDonough wrote:
> > No.  Both hasattr and getattr hide AttributeError.

> I knew about hasattr, but how does getattr hide AttributeError?

What you want is for "real" AttributeErrors to bubble up through the
getattr but they don't.  For example, if you do this:

class Foo(object):
    @property
    def __acl__(self):
        raise AttributeError('abc')

ob = Foo()

result = getattr(ob, '__acl__', None)

An AttributeError will not be raised, and result will be None.

- C


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Withers  
View profile  
 More options Oct 9 2012, 1:18 am
From: Chris Withers <ch...@simplistix.co.uk>
Date: Tue, 09 Oct 2012 14:48:00 +0930
Subject: Re: getattr hides AttributeError

On 09/10/2012 10:12, Chris McDonough wrote:

> On Tue, 2012-10-09 at 10:04 +0930, Chris Withers wrote:
>> On 09/10/2012 09:57, Chris McDonough wrote:
>>> No.  Both hasattr and getattr hide AttributeError.

>> I knew about hasattr, but how does getattr hide AttributeError?

> What you want is for "real" AttributeErrors to bubble up through the
> getattr but they don't.  For example, if you do this:

Yeah, that is annoying..

If it were me, I'd do this:

# nb: does not subclass AttributeError
class InnerAttributeError(Exception):
     pass

class Foo(object):
      @property
      def __acl__(self):
          try:
              ...
              raise AttributeError('abc')
          except AttributeError as e:
              raise InnerAttributeError(e)

If I used it more than once, I'd probably turn it into a decorator:

class Foo(object):
      @property
      @raise_inner_attribute_error
      def __acl__(self):
          ...
          raise AttributeError('abc')

cheers,

Chris

--
Simplistix - Content Management, Batch Processing & Python Consulting
             - http://www.simplistix.co.uk


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »