Skip to content

Commit

Permalink
Return 404 instead of IndexError for traversal past the root (#1219)
Browse files Browse the repository at this point in the history
  • Loading branch information
davisagli authored Jun 12, 2024
1 parent 77f7c0d commit 558a8f7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ https://github.com/zopefoundation/Zope/blob/4.x/CHANGES.rst

- Update to newest compatible versions of dependencies.

- Added CC-BY 4.0 license to the Zope logo.
- Added CC-BY 4.0 license to the Zope logo.

- Fix ``IndexError`` on traversal past the root using `..`.
(`#1218 <https://github.com/zopefoundation/Zope/issues/1218>`_)


5.10 (2024-05-18)
Expand Down
2 changes: 2 additions & 0 deletions src/ZPublisher/BaseRequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,8 @@ def traverse(self, path, response=None, validated_hook=None):
if not item or item == '.':
continue
elif item == '..':
if not len(clean):
return response.notFoundError(path)
del clean[-1]
else:
clean.append(item)
Expand Down
12 changes: 12 additions & 0 deletions src/ZPublisher/tests/testBaseRequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,18 @@ def test_traverse_slash(self):
self.assertEqual(r.URL, '/index_html')
self.assertEqual(r.response.base, '')

def test_traverse_special_names(self):
root, folder = self._makeRootAndFolder()
r = self._makeOne(root)
self.assertRaises(NotFound, r.traverse, 'REQUEST')
self.assertRaises(NotFound, r.traverse, 'aq_self')
self.assertRaises(NotFound, r.traverse, 'aq_base')

def test_traverse_past_root(self):
root, folder = self._makeRootAndFolder()
r = self._makeOne(root)
self.assertRaises(NotFound, r.traverse, '..')

def test_traverse_attribute_with_docstring(self, use_docstring=None):
root, folder = self._makeRootAndFolder()
folder._setObject('objBasic', self._makeBasicObject(use_docstring))
Expand Down

0 comments on commit 558a8f7

Please sign in to comment.