Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BE-2343-cve-2022-40897 #2

Merged
merged 2 commits into from May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.rst
@@ -1,3 +1,8 @@
v44.1.1.1
-------

* #3659: Limit the amount of whitespace to search/backtrack (CVE-2022-40897)

v44.1.1
-------

Expand Down
6 changes: 4 additions & 2 deletions setuptools/package_index.py
Expand Up @@ -214,8 +214,10 @@ def wrapper(*args, **kwargs):
return wrapper


REL = re.compile(r"""<([^>]*\srel\s*=\s*['"]?([^'">]+)[^>]*)>""", re.I)
# this line is here to fix emacs' cruddy broken syntax highlighting
REL = re.compile(r"""<([^>]*\srel\s{0,10}=\s{0,10}['"]?([^'" >]+)[^>]*)>""", re.I)
"""
Regex for an HTML tag with 'rel="val"' attributes.
"""


@unique_values
Expand Down
8 changes: 8 additions & 0 deletions setuptools/tests/test_packageindex.py
Expand Up @@ -337,3 +337,11 @@ def test_percent_in_password(self, tmpdir, monkeypatch):
cred = cfg.creds_by_repository['https://pypi.org']
assert cred.username == 'jaraco'
assert cred.password == 'pity%'


@pytest.mark.timeout(1)
def test_REL_DoS():
"""
REL should not hang on a contrived attack string.
"""
setuptools.package_index.REL.search('< rel=' + ' ' * 2**12)