[Zope-Checkins] CVS: Zope/lib/python/Products/PythonScripts - PythonScript.py:1.53

Tres Seaver tseaver at zope.com
Thu Jan 15 18:09:38 EST 2004


Update of /cvs-repository/Zope/lib/python/Products/PythonScripts
In directory cvs.zope.org:/tmp/cvs-serv24317/Products/PythonScripts

Modified Files:
	PythonScript.py 
Log Message:


  - Merge a number of entangled issues from 2.6 / 2.7 audit:

    Iteration over sequences could in some cases fail to check access 
    to an object obtained from the sequence. Subsequent checks (such 
    as for attributes access) of such an object would still be 
    performed, but it should not have been possible to obtain the 
    object in the first place.

    List and dictionary instance methods such as the get method of 
    dictionary objects were not security aware and could return an 
    object without checking access to that object. Subsequent checks 
    (such as for attributes access) of such an object would still be 
    performed, but it should not have been possible to obtain the 
    object in the first place.

    Use of "import as" in Python scripts could potentially rebind 
    names in ways that could be used to avoid appropriate security 
    checks.

    A number of newer built-ins were either unavailable in untrusted 
    code or did not perform adequate security checking.

    Unpacking via function calls, variable assignment, exception 
    variables and other contexts did not perform adequate security 
    checks, potentially allowing access to objects that should have 
    been protected.

    Class security was not properly intialized for PythonScripts, 
    potentially allowing access to variables that should be protected. 
    It turned out that most of the security assertions were in fact 
    activated as a side effect of other code, but this fix is still 
    appropriate to ensure that all security declarations are properly 
    applied.

    DTMLMethods with proxy rights could incorrectly transfer those 
    rights via acquisition when traversing to a parent object.


=== Zope/lib/python/Products/PythonScripts/PythonScript.py 1.52 => 1.53 ===
--- Zope/lib/python/Products/PythonScripts/PythonScript.py:1.52	Thu Jan 15 14:41:31 2004
+++ Zope/lib/python/Products/PythonScripts/PythonScript.py	Thu Jan 15 18:09:07 2004
@@ -31,10 +31,10 @@
 from AccessControl import getSecurityManager
 from OFS.History import Historical, html_diff
 from OFS.Cache import Cacheable
-from AccessControl import full_write_guard, safe_builtins
-from AccessControl.ZopeGuards import guarded_getattr, guarded_getitem
+from AccessControl.ZopeGuards import get_safe_globals, guarded_getattr
 from zLOG import LOG, ERROR, INFO, PROBLEM
 from zExceptions import Forbidden
+import Globals
 
 # Track the Python bytecode version
 import imp
@@ -223,6 +223,7 @@
 
     def _compiler(self, *args, **kw):
         return RestrictedPython.compile_restricted_function(*args, **kw)
+
     def _compile(self):
         bind_names = self.getBindingAssignments().getAssignedNamesInOrder()
         r = self._compiler(self._params, self._body or 'pass',
@@ -255,14 +256,11 @@
         self._v_change = 0
 
     def _newfun(self, code):
-        g = {'__debug__': __debug__,
-             '__name__': None,
-             '__builtins__': safe_builtins,
-             '_getattr_': guarded_getattr,
-             '_getitem_': guarded_getitem,
-             '_write_': full_write_guard,
-             '_print_': RestrictedPython.PrintCollector,
-             }
+        g = get_safe_globals()
+        g['_getattr_'] = guarded_getattr
+        g['__debug__'] = __debug__
+        g['__name__'] = None
+
         l = {}
         exec code in g, l
         self._v_f = f = l.values()[0]
@@ -489,6 +487,8 @@
             RESPONSE.setHeader('Content-Type', 'text/plain')
         return self.read()
 
+
+Globals.InitializeClass(PythonScript)
 
 class PythonScriptTracebackSupplement:
     """Implementation of ITracebackSupplement"""




More information about the Zope-Checkins mailing list