Skip to content

Commit

Permalink
[PR #7821/366ba40f backport][3.9] Only check origin if insecure schem…
Browse files Browse the repository at this point in the history
…e and there are origins to treat as secure, in CookieJar.filter_cookies() (#7825)

**This is a backport of PR #7821 as merged into master
(366ba40).**

Co-authored-by: Rongrong <i@rong.moe>
  • Loading branch information
patchback[bot] and Rongronggg9 authored Nov 12, 2023
1 parent 9d498ca commit c0f9017
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGES/7821.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Only check origin if insecure scheme and there are origins to treat as secure, in ``CookieJar.filter_cookies()``.
13 changes: 6 additions & 7 deletions aiohttp/cookiejar.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,13 @@ def filter_cookies(
return filtered
request_url = URL(request_url)
hostname = request_url.raw_host or ""
request_origin = URL()
with contextlib.suppress(ValueError):
request_origin = request_url.origin()

is_not_secure = (
request_url.scheme not in ("https", "wss")
and request_origin not in self._treat_as_secure_origin
)
is_not_secure = request_url.scheme not in ("https", "wss")
if is_not_secure and self._treat_as_secure_origin:
request_origin = URL()
with contextlib.suppress(ValueError):
request_origin = request_url.origin()
is_not_secure = request_origin not in self._treat_as_secure_origin

# Point 2: https://www.rfc-editor.org/rfc/rfc6265.html#section-5.4
for cookie in sorted(self, key=lambda c: len(c["path"])):
Expand Down

0 comments on commit c0f9017

Please sign in to comment.