security.declareObjectProtected('View') appears to be buggy

Bug #142921 reported by ChrisW
2
Affects Status Importance Assigned to Milestone
Zope 2
Invalid
Medium
Unassigned

Bug Description

This simple wrapper class:

class NamesProxy:

    security = ClassSecurityInfo()

    # security.declareObjectProtected('View')

    security.setDefaultAccess('allow')

    def __init__(self,names):
        self.names=names

    security.declareProtected('View','__getitem__')
    def __getitem__(self,item):
        return self.names[item]

    security.declareProtected('View','__len__')
    def __len__(self):
        return len(self.names)

...should allow BTreeFolder2 to be batched over in Python Scripts and Page Templates. However, if the "security.declareObjectProtected('View')" is uncommented, then, with VerboseSecurity installed, you get the following error:

2004-03-21T22:45:34 PROBLEM(100) Zope Security Policy '<PermissionRole object at 0x84692a0>' passed as roles during validation of 'NamesProxy' is not a sequence.
------
2004-03-21T22:45:34 ERROR(200) SiteError http://x/folder/index_html
Traceback (innermost last):
  File /usr/local/zope/2.6.1/lib/python/Products/PageTemplates/Expressions.py, line 346, in restrictedTraverse
    (Object: Products.MyProduct)
    (Info: {'path': ['Products', 'MyProduct', 'NamesProxy'], 'TraversalRequestNameStack': []})
  File /zope/dev_web/Products/VerboseSecurity/VerboseSecurityPolicy.py, line 169, in validate
TypeError: 'in' or 'not in' needs sequence right argument

Tags: bug zope
Revision history for this message
ChrisW (chris-simplistix) wrote :

Changes: submitter email, edited transcript, revised description, new comment

Oops, left a bit fo customer info in there.

Revision history for this message
Tres Seaver (tseaver) wrote :

A couple of things:

  - Your test case doesn't initialize the class (which I
    assume is an omission)

  - The code for permission roles is some of the
    trickiest in Zope, and exists in different forms on
    each of the two release branches and the HEAD.

  - Therefore, I wouldn't expect to see a fix for this
    on the 2.6 branch unless you (or somebody) is
    motivated to provide it.

  - If you find a similar problem for 2.7 or the HEAD,
    with a reproducible test case, then we will likely
    fix it. Note that a testcase which can't be
    reproduced *without* VerboseSecurity doesn't qualify
    (VS tries hard to emulate standard security, but
    it *could* be the source of the problem.)

Revision history for this message
ChrisW (chris-simplistix) wrote :

- the missing itialize class was a result of missing in the copy paste by one line ;-)

- I noticed about that code, hence I ran crying to this collector :'(

- I'll let you know if it still shows up in 2.7, when I finally get the customer there.

- The issue produced an error without VS, just an even less clear error ;-)

Revision history for this message
Florent Guillaume (efge) wrote :

Status: Pending => Deferred

Please followup on this, otherwise it will be considered a pilot error and closed.

Revision history for this message
Florent Guillaume (efge) wrote :

Status: Deferred => Pending

Hm not defered, sorry. Pending closure, rather :)

Revision history for this message
ChrisW (chris-simplistix) wrote :

Status: Pending => Accepted

 Supporters added: chrisw

Deferred was the right state.
I'll accept this as something I need ot look at, but it might be a while. I'm pretty damn sure it wasn't pilot error though ;-)

Revision history for this message
ChrisW (chris-simplistix) wrote :

Changes: edited transcript, revised version_info, new comment

This is still an issue in Zope 2.7.3.

Now the message is:

Error Type: TypeError
Error Value: iterable argument required

...and you get a helpful bit in the event log:

2004-11-27T19:28:35 PROBLEM(100) Zope Security Policy '<PermissionRole object at
 0x014CD578>' passed as roles during validation of 'NamesProxy' is
not a sequence.

Revision history for this message
Florent Guillaume (efge) wrote :

Changes: edited transcript, importance (critical => medium)

Revision history for this message
ChrisW (chris-simplistix) wrote :

I don't use VerboseSecurity anymore...

Changed in zope2:
assignee: ChrisW (chris-simplistix) → nobody
Revision history for this message
Tres Seaver (tseaver) wrote :

Can't be reproduced without VerboseSecurity.

Changed in zope2:
status: Confirmed → Incomplete
Revision history for this message
Tres Seaver (tseaver) wrote :

I looked back at this: basically, the issue here is that using 'security.declareObjectProtected' requires that you *also* set up the default role-permission mapping using 'setPermissionDefault', e.g.::

    'security.setPermissionDefault('View', ['Anonymous'])

"Local" role bindings are not available to the ClassSecurityInfo object at startup: the lazy lookup of those bindings which drives the normal protection of methods and attributes is driven by the ExtensionClass attribute getter, and can't work for the "bare" object itself.

Changed in zope2:
status: Incomplete → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.