Download tasks/codeql_python_benchmark51_v2/pyvul-bae2a9b05bba64edb040/patch.diff from Benchanything/checkerbench: direct link, hf CLI and curl.
- Browser
- Download file 4.38 kB
-
https://huggingface.co/datasets/Benchanything/checkerbench/resolve/main/tasks/codeql_python_benchmark51_v2/pyvul-bae2a9b05bba64edb040/patch.diff
- Command line
-
hf download hf://datasets/Benchanything/checkerbench/tasks/codeql_python_benchmark51_v2/pyvul-bae2a9b05bba64edb040/patch.diff
-
curl -L -o patch.diff https://huggingface.co/datasets/Benchanything/checkerbench/resolve/main/tasks/codeql_python_benchmark51_v2/pyvul-bae2a9b05bba64edb040/patch.diff
4.38 kB
| diff --git a/CHANGES.rst b/CHANGES.rst | |
| index 60d0d82..cc2aad0 100644 | |
| --- a/CHANGES.rst | |
| +++ b/CHANGES.rst | |
| 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>`_) | |
| 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 | |
| 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 | |
| class SnapshotExportContext(BaseContext): | |
| # 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): | |
| class SnapshotExportContext(BaseContext): | |
| 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 | |
| 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 | |
| class SetupToolTests(FilesystemTestBase, TarballTester, ConformsToISetupTool): | |
| 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' | |
| class SetupToolTests(FilesystemTestBase, TarballTester, ConformsToISetupTool): | |
| 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): | |
| class SetupToolTests(FilesystemTestBase, TarballTester, ConformsToISetupTool): | |
| 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 | |