From 484fe82d1fb6237134c8acd866e01e705210e2bc Mon Sep 17 00:00:00 2001 From: tharun06 Date: Mon, 21 Sep 2026 21:27:48 -0400 Subject: [PATCH] Fix host-only cookie domain serialization --- .../v1/azure_functions_runtime_v1/bindings/datumdef.py | 2 +- runtimes/v1/tests/unittests/test_datumdef.py | 10 ++++++++++ .../v2/azure_functions_runtime/bindings/datumdef.py | 2 +- runtimes/v2/tests/unittests/test_datumdef.py | 10 ++++++++++ workers/azure_functions_worker/bindings/datumdef.py | 2 +- workers/tests/unittests/test_datumref.py | 10 ++++++++++ workers/tests/unittests/test_http_functions.py | 2 +- 7 files changed, 34 insertions(+), 4 deletions(-) diff --git a/runtimes/v1/azure_functions_runtime_v1/bindings/datumdef.py b/runtimes/v1/azure_functions_runtime_v1/bindings/datumdef.py index a4a11cc8e..5e25a7dcb 100644 --- a/runtimes/v1/azure_functions_runtime_v1/bindings/datumdef.py +++ b/runtimes/v1/azure_functions_runtime_v1/bindings/datumdef.py @@ -166,7 +166,7 @@ def parse_to_rpc_http_cookie_list(cookies: Optional[List[SimpleCookie]], protos) protos.RpcHttpCookie(name=name, value=cookie_entity.value, domain=to_nullable_string( - cookie_entity['domain'], + cookie_entity['domain'] or None, 'cookie.domain', protos), path=to_nullable_string( diff --git a/runtimes/v1/tests/unittests/test_datumdef.py b/runtimes/v1/tests/unittests/test_datumdef.py index 31f4fb859..7af716174 100644 --- a/runtimes/v1/tests/unittests/test_datumdef.py +++ b/runtimes/v1/tests/unittests/test_datumdef.py @@ -67,6 +67,16 @@ def test_parse_cookie_attr_same_site_explicit_none(self): def test_parse_to_rpc_http_cookie_list_none(self): self.assertEqual(parse_to_rpc_http_cookie_list(None, protos), None) + def test_host_only_cookie_omits_domain(self): + cookie = SimpleCookie() + cookie.load('__Host-test=value; Path=/; Secure; HttpOnly; SameSite=Lax') + + rpc_cookie = parse_to_rpc_http_cookie_list([cookie], protos)[0] + + self.assertFalse(rpc_cookie.HasField('domain')) + self.assertEqual(rpc_cookie.path.value, '/') + self.assertTrue(rpc_cookie.secure.value) + def test_parse_to_rpc_http_cookie_list_valid(self): headers = [ 'foo=bar; Path=/some/path; Secure; HttpOnly; Domain=123; ' diff --git a/runtimes/v2/azure_functions_runtime/bindings/datumdef.py b/runtimes/v2/azure_functions_runtime/bindings/datumdef.py index d4dbc31cf..552da917c 100644 --- a/runtimes/v2/azure_functions_runtime/bindings/datumdef.py +++ b/runtimes/v2/azure_functions_runtime/bindings/datumdef.py @@ -165,7 +165,7 @@ def parse_to_rpc_http_cookie_list(cookies: Optional[List[SimpleCookie]], protos) protos.RpcHttpCookie(name=name, value=cookie_entity.value, domain=to_nullable_string( - cookie_entity['domain'], + cookie_entity['domain'] or None, 'cookie.domain', protos), path=to_nullable_string( diff --git a/runtimes/v2/tests/unittests/test_datumdef.py b/runtimes/v2/tests/unittests/test_datumdef.py index 47faad283..897e79ca9 100644 --- a/runtimes/v2/tests/unittests/test_datumdef.py +++ b/runtimes/v2/tests/unittests/test_datumdef.py @@ -67,6 +67,16 @@ def test_parse_cookie_attr_same_site_explicit_none(self): def test_parse_to_rpc_http_cookie_list_none(self): self.assertEqual(parse_to_rpc_http_cookie_list(None, protos), None) + def test_host_only_cookie_omits_domain(self): + cookie = SimpleCookie() + cookie.load('__Host-test=value; Path=/; Secure; HttpOnly; SameSite=Lax') + + rpc_cookie = parse_to_rpc_http_cookie_list([cookie], protos)[0] + + self.assertFalse(rpc_cookie.HasField('domain')) + self.assertEqual(rpc_cookie.path.value, '/') + self.assertTrue(rpc_cookie.secure.value) + def test_parse_to_rpc_http_cookie_list_valid(self): headers = [ 'foo=bar; Path=/some/path; Secure; HttpOnly; Domain=123; ' diff --git a/workers/azure_functions_worker/bindings/datumdef.py b/workers/azure_functions_worker/bindings/datumdef.py index 0e2a9c538..b734531a0 100644 --- a/workers/azure_functions_worker/bindings/datumdef.py +++ b/workers/azure_functions_worker/bindings/datumdef.py @@ -241,7 +241,7 @@ def parse_to_rpc_http_cookie_list(cookies: Optional[List[SimpleCookie]]): protos.RpcHttpCookie(name=name, value=cookie_entity.value, domain=to_nullable_string( - cookie_entity['domain'], + cookie_entity['domain'] or None, 'cookie.domain'), path=to_nullable_string( cookie_entity['path'], 'cookie.path'), diff --git a/workers/tests/unittests/test_datumref.py b/workers/tests/unittests/test_datumref.py index 78813ef22..80ee54242 100644 --- a/workers/tests/unittests/test_datumref.py +++ b/workers/tests/unittests/test_datumref.py @@ -66,6 +66,16 @@ def test_parse_cookie_attr_same_site_explicit_none(self): def test_parse_to_rpc_http_cookie_list_none(self): self.assertEqual(parse_to_rpc_http_cookie_list(None), None) + def test_host_only_cookie_omits_domain(self): + cookie = SimpleCookie() + cookie.load('__Host-test=value; Path=/; Secure; HttpOnly; SameSite=Lax') + + rpc_cookie = parse_to_rpc_http_cookie_list([cookie])[0] + + self.assertFalse(rpc_cookie.HasField('domain')) + self.assertEqual(rpc_cookie.path.value, '/') + self.assertTrue(rpc_cookie.secure.value) + def test_parse_to_rpc_http_cookie_list_valid(self): headers = [ 'foo=bar; Path=/some/path; Secure; HttpOnly; Domain=123; ' diff --git a/workers/tests/unittests/test_http_functions.py b/workers/tests/unittests/test_http_functions.py index 4d90fa19d..92a76fe3e 100644 --- a/workers/tests/unittests/test_http_functions.py +++ b/workers/tests/unittests/test_http_functions.py @@ -376,7 +376,7 @@ def test_set_cookie_header_in_response_default_value(self): 'set_cookie_resp_header_default_values') self.assertEqual(r.status_code, 200) self.assertEqual(r.headers.get('Set-Cookie'), - 'foo=bar; domain=; path=') + 'foo=bar; path=') def test_response_cookie_header_nullable_timestamp_err(self): r = self.webhost.request(