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

Strip leading . from cookie domain names. #1041

Merged
merged 6 commits into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ https://github.com/zopefoundation/Zope/blob/4.x/CHANGES.rst

- Quote all components of a redirect URL (not only the path component)
(`#1027 <https://github.com/zopefoundation/Zope/issues/1027>`_)

- Drop the convenience script generation from the buildout configuration
in order to get rid of a lot of dependency version pins.
These were only needed for maintainers who can install them manually.
Expand All @@ -28,6 +28,9 @@ https://github.com/zopefoundation/Zope/blob/4.x/CHANGES.rst
to the complete matrix view when more than 30 roles are defined.
(`#1039 <https://github.com/zopefoundation/Zope/pull/1039>`_)

- Strip leading ``.`` in cookie domain names.
(`#1041 <https://github.com/zopefoundation/Zope/pull/1041>`_)


5.5.1 (2022-04-05)
------------------
Expand Down
4 changes: 4 additions & 0 deletions src/ZPublisher/cookie.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ def domain_converter(value):
return value
from encodings.idna import ToASCII
from encodings.idna import nameprep
dataflake marked this conversation as resolved.
Show resolved Hide resolved
# According to https://www.rfc-editor.org/rfc/rfc6265#section-4.1.2.3 a
# leading dot is ignored. If it is there `ToASCII` breaks on the empty
# string:
u_value = u_value.lstrip('.')
return ".".join(to_str(ToASCII(nameprep(c))) for c in u_value.split("."))


Expand Down
4 changes: 4 additions & 0 deletions src/ZPublisher/tests/test_cookie.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ def test_domain(self):
_, v = convertCookieParameter("domain",
"Fußball.example".encode())
self.assertEqual(v, "fussball.example")
# a leading dot is stripped as it is ignored according to
# https://www.rfc-editor.org/rfc/rfc6265#section-4.1.2.3
_, v = convertCookieParameter("domain", ".zope.dev")
self.assertEqual(v, "zope.dev")

def test_path(self):
# test object
Expand Down