CVE-2021-21360: Exposure of Sensitive Information to an Unauthorized Actor (CWE-200)
value: Products.GenericSetup is a mini-framework for expressing the configured state of a Zope Site as a set of filesystem artifacts. In Products.GenericSetup before version 2.1.1 there is an information disclosure vulnerability - anonymous visitors may view log and snapshot files generated by the Generic Setup Tool. The problem has been fixed in version 2.1.1. Depending on how you have installed Products.GenericSetup, you should change the buildout version pin to 2.1.1 and re-run the buildout, or if you used pip simply do pip install `"Products.GenericSetup>=2.1.1"`.
CWE description: The product exposes sensitive information to an actor that is not explicitly authorized to have access to that information.
CVSS v3 base score: 5.3
Published: 2021-03-09T01:15Z
Repository: https://github.com/zopefoundation/Products.GenericSetup
Language: Python
Files changed: CHANGES.rst, src/Products/GenericSetup/context.py, src/Products/GenericSetup/tests/test_tool.py
Commit date: 2021-03-02 00:43:04 +0100
Commit message: Enforce access control on snapshot files and folders.

Diff: diff --git a/CHANGES.rst b/CHANGES.rst
index 60d0d82..cc2aad0 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -2,11 +2,11 @@ Changelog
 =========
 
 2.1.1 (unreleased)
 ------------------
 
-- Enforce access control on setup tool log files
+- Enforce access control on setup tool log files and snapshot files and folders.
   (`#101 <https://github.com/zopefoundation/Products.GenericSetup/issues/101>`_)
 
 
 2.1.0 (2021-01-26)
 ------------------
diff --git a/src/Products/GenericSetup/context.py b/src/Products/GenericSetup/context.py
index 1c8ba1d..9977929 100644
--- a/src/Products/GenericSetup/context.py
+++ b/src/Products/GenericSetup/context.py
@@ -24,10 +24,11 @@ from tarfile import TarFile
 from tarfile import TarInfo
 
 import six
 
 from AccessControl.class_init import InitializeClass
+from AccessControl.Permissions import view
 from AccessControl.SecurityInfo import ClassSecurityInfo
 from Acquisition import Implicit
 from Acquisition import aq_base
 from Acquisition import aq_inner
 from Acquisition import aq_parent
@@ -497,10 +498,14 @@ class SnapshotExportContext(BaseContext):
         folder = self._ensureSnapshotsFolder(subdir)
 
         # MISSING: switch on content_type
         ob = self._createObjectByType(filename, text, content_type)
         folder._setObject(str(filename), ob)  # No Unicode IDs!
+        # Tighten the View permission on the new object.
+        # Only the owner and Manager users may view the log.
+        # file_ob = self._getOb(name)
+        ob.manage_permission(view, ('Manager', 'Owner'), 0)
 
     @security.protected(ManagePortal)
     def getSnapshotURL(self):
         """ See IExportContext.
         """
@@ -557,12 +562,14 @@ class SnapshotExportContext(BaseContext):
         for element in path:
 
             if element not in current.objectIds():
                 # No Unicode IDs!
                 current._setObject(str(element), Folder(element))
-
-            current = current._getOb(element)
+                current = current._getOb(element)
+                current.manage_permission(view, ('Manager', 'Owner'), 0)
+            else:
+                current = current._getOb(element)
 
         return current
 
 
 InitializeClass(SnapshotExportContext)
diff --git a/src/Products/GenericSetup/tests/test_tool.py b/src/Products/GenericSetup/tests/test_tool.py
index 2ce313c..d392bbc 100644
--- a/src/Products/GenericSetup/tests/test_tool.py
+++ b/src/Products/GenericSetup/tests/test_tool.py
@@ -471,10 +471,19 @@ class SetupToolTests(FilesystemTestBase, TarballTester, ConformsToISetupTool):
 
         prefix = 'import-all-%s' % PROFILE_ID
         logged = [x for x in tool.objectIds('File') if x.startswith(prefix)]
         self.assertEqual(len(logged), 1)
 
+    def check_restricted_access(self, obj):
+        # For most objects that we create, we do not want ordinary users to
+        # see it, also not when they have View permission on a higher level.
+        rop_info = obj.rolesOfPermission(view)
+        allowed_roles = sorted([x['name'] for x in rop_info
+                                if x['selected']])
+        self.assertEqual(allowed_roles, ['Manager', 'Owner'])
+        self.assertFalse(obj.acquiredRolesAreUsedBy(view))
+
     def test_runAllImportStepsFromProfile_unicode_id_creates_reports(self):
 
         TITLE = 'original title'
         PROFILE_ID = u'snapshot-testing'
         site = self._makeSite(TITLE)
@@ -495,15 +504,11 @@ class SetupToolTests(FilesystemTestBase, TarballTester, ConformsToISetupTool):
 
         # Check acess restriction on log files
         logged = [x for x in tool.objectIds('File')]
         for file_id in logged:
             file_ob = tool._getOb(file_id)
-            rop_info = file_ob.rolesOfPermission(view)
-            allowed_roles = sorted([x['name'] for x in rop_info
-                                    if x['selected']])
-            self.assertEqual(allowed_roles, ['Manager', 'Owner'])
-            self.assertFalse(file_ob.acquiredRolesAreUsedBy(view))
+            self.check_restricted_access(file_ob)
 
     def test_runAllImportStepsFromProfile_sorted_explicit_purge(self):
 
         site = self._makeSite()
         tool = self._makeOne('setup_tool').__of__(site)
@@ -1099,10 +1104,19 @@ class SetupToolTests(FilesystemTestBase, TarballTester, ConformsToISetupTool):
         info = tool.listSnapshotInfo()[0]
 
         self.assertEqual(info['id'], 'default')
         self.assertEqual(info['title'], 'default')
 
+        # Check access restriction on snapshot files and folders
+        self.check_restricted_access(tool.snapshots)
+        self.check_restricted_access(snapshot)
+        for obj in snapshot.objectValues():
+            self.check_restricted_access(obj)
+            if hasattr(aq_base(obj), 'objectValues'):
+                for child in obj.objectValues():
+                    self.check_restricted_access(child)
+
     def test_applyContext(self):
         from ..tool import EXPORT_STEPS_XML
         from ..tool import IMPORT_STEPS_XML
         from ..tool import TOOLSET_XML
 

Vulnerable code: - Enforce access control on setup tool log files

            current = current._getOb(element)
            rop_info = file_ob.rolesOfPermission(view)
            allowed_roles = sorted([x['name'] for x in rop_info
                                    if x['selected']])
            self.assertEqual(allowed_roles, ['Manager', 'Owner'])
            self.assertFalse(file_ob.acquiredRolesAreUsedBy(view))
Fixed code: - Enforce access control on setup tool log files and snapshot files and folders.
from AccessControl.Permissions import view
        # Tighten the View permission on the new object.
        # Only the owner and Manager users may view the log.
        # file_ob = self._getOb(name)
        ob.manage_permission(view, ('Manager', 'Owner'), 0)
                current = current._getOb(element)
                current.manage_permission(view, ('Manager', 'Owner'), 0)
            else:
                current = current._getOb(element)
    def check_restricted_access(self, obj):
        # For most objects that we create, we do not want ordinary users to
        # see it, also not when they have View permission on a higher level.
        rop_info = obj.rolesOfPermission(view)
        allowed_roles = sorted([x['name'] for x in rop_info
                                if x['selected']])
        self.assertEqual(allowed_roles, ['Manager', 'Owner'])
        self.assertFalse(obj.acquiredRolesAreUsedBy(view))

            self.check_restricted_access(file_ob)
        # Check access restriction on snapshot files and folders
        self.check_restricted_access(tool.snapshots)
        self.check_restricted_access(snapshot)
        for obj in snapshot.objectValues():
            self.check_restricted_access(obj)
            if hasattr(aq_base(obj), 'objectValues'):
                for child in obj.objectValues():
                    self.check_restricted_access(child)