Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
8a68f26
Fix empty cookie domain/path being sent as empty string
Allen5288 Nov 22, 2026
c78ce30
Fix empty cookie domain/path being sent as empty string
Allen5288 Nov 22, 2026
aed92a8
Fix empty cookie domain/path being sent as empty string
Allen5288 Nov 22, 2026
b0f0e20
Fix empty cookie domain/path being sent as empty string
Allen5288 Nov 22, 2026
3232899
Fix empty cookie domain/path being sent as empty string
Allen5288 Nov 22, 2026
55e85ab
Fix empty cookie domain/path being sent as empty string
Allen5288 Nov 22, 2026
f410a70
Fix empty cookie domain/path being sent as empty string
Allen5288 Nov 22, 2026
ed038c6
Fix empty cookie domain/path being sent as empty string
Allen5288 Nov 22, 2026
0c32b39
Fix empty cookie domain/path being sent as empty string
Allen5288 Nov 22, 2026
5179610
Fix empty cookie domain/path being sent as empty string
Allen5288 Nov 22, 2026
2fa8084
Fix empty cookie domain/path being sent as empty string
Allen5288 Nov 22, 2026
6ff335e
Fix empty cookie domain/path being sent as empty string
Allen5288 Nov 22, 2026
87cb14c
Fix empty cookie domain/path being sent as empty string
Allen5288 Nov 22, 2026
5779db4
Fix empty cookie domain/path being sent as empty string
Allen5288 Nov 22, 2026
f1bb6c7
Fix empty cookie domain/path being sent as empty string
Allen5288 Nov 22, 2026
338f8ef
Fix empty cookie domain/path being sent as empty string
Allen5288 Nov 22, 2026
3ef827f
Fix empty cookie domain/path being sent as empty string
Allen5288 Nov 22, 2026
f869885
Fix empty cookie domain/path being sent as empty string
Allen5288 Nov 22, 2026
2d8240f
Fix empty cookie domain/path being sent as empty string
Allen5288 Nov 22, 2026
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
4 changes: 2 additions & 2 deletions runtimes/v1/azure_functions_runtime_v1/bindings/datumdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,11 @@ 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(
cookie_entity['path'],
cookie_entity['path'] or None,
'cookie.path',
protos),
expires=to_nullable_timestamp(
Expand Down
24 changes: 24 additions & 0 deletions runtimes/v1/tests/unittests/test_datumdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,30 @@ def test_parse_to_rpc_http_cookie_list_valid(self):
self.assertEqual(cookie1, rpc_cookies[0])
self.assertEqual(cookie2, rpc_cookies[1])

def test_parse_to_rpc_http_cookie_list_no_domain(self):
# Regression test for Azure/azure-functions-python-worker#1794:
# a cookie without a Domain (e.g. `test="hello//world"; Path=/;
# SameSite=lax`) must keep its value intact and must not gain an
# empty `domain=` attribute, so domain is sent as None.
cookies = SimpleCookie('test="hello//world"; Path=/; SameSite=lax')

cookie = protos.RpcHttpCookie(name="test",
value="hello//world",
domain=None,
path=to_nullable_string(
"/", "cookie.path", protos),
expires=None,
secure=to_nullable_bool(
False, 'cookie.secure', protos),
http_only=to_nullable_bool(
False, 'cookie.httpOnly', protos),
same_site=parse_cookie_attr_same_site(
{"samesite": "Lax"}, protos),
max_age=None)

rpc_cookies = parse_to_rpc_http_cookie_list([cookies], protos)
self.assertEqual(cookie, rpc_cookies[0])

def test_parse_to_rpc_http_cookie_list_no_cookie(self):
datum = Datum(
type='http',
Expand Down
4 changes: 2 additions & 2 deletions runtimes/v2/azure_functions_runtime/bindings/datumdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,11 @@ 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(
cookie_entity['path'],
cookie_entity['path'] or None,
'cookie.path',
protos),
expires=to_nullable_timestamp(
Expand Down
24 changes: 24 additions & 0 deletions runtimes/v2/tests/unittests/test_datumdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,30 @@ def test_parse_to_rpc_http_cookie_list_valid(self):
self.assertEqual(cookie1, rpc_cookies[0])
self.assertEqual(cookie2, rpc_cookies[1])

def test_parse_to_rpc_http_cookie_list_no_domain(self):
# Regression test for Azure/azure-functions-python-worker#1794:
# a cookie without a Domain (e.g. `test="hello//world"; Path=/;
# SameSite=lax`) must keep its value intact and must not gain an
# empty `domain=` attribute, so domain is sent as None.
cookies = SimpleCookie('test="hello//world"; Path=/; SameSite=lax')

cookie = protos.RpcHttpCookie(name="test",
value="hello//world",
domain=None,
path=to_nullable_string(
"/", "cookie.path", protos),
expires=None,
secure=to_nullable_bool(
False, 'cookie.secure', protos),
http_only=to_nullable_bool(
False, 'cookie.httpOnly', protos),
same_site=parse_cookie_attr_same_site(
{"samesite": "Lax"}, protos),
max_age=None)

rpc_cookies = parse_to_rpc_http_cookie_list([cookies], protos)
self.assertEqual(cookie, rpc_cookies[0])

def test_parse_to_rpc_http_cookie_list_no_cookie(self):
datum = Datum(
type='http',
Expand Down
5 changes: 3 additions & 2 deletions workers/azure_functions_worker/bindings/datumdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,11 @@ 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'),
cookie_entity['path'] or None,
'cookie.path'),
expires=to_nullable_timestamp(
parse_cookie_attr_expires(
cookie_entity), 'cookie.expires'),
Expand Down
7 changes: 4 additions & 3 deletions workers/r2p2/bridge/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,8 @@ def _flatten_cookies(cookies):
without any Python protobuf on the native path.

Mirrors the runtime's ``parse_to_rpc_http_cookie_list`` semantics: ``domain``
and ``path`` are always emitted (possibly empty), ``secure``/``http_only`` are
and ``path`` are emitted when set (``None`` when unset, so the host does
not render an empty ``domain=``/``path=`` attribute), ``secure``/``http_only`` are
always booleans, ``same_site`` is pre-resolved to the RpcHttpCookie.SameSite
enum integer (None=0, Lax=1, Strict=2, 'none'->ExplicitNone=3), ``expires`` is
epoch seconds (or None) and ``max_age`` is a float (or None).
Expand Down Expand Up @@ -878,8 +879,8 @@ def _flatten_cookies(cookies):
out.append({
'name': name,
'value': morsel.value,
'domain': morsel['domain'] or '',
'path': morsel['path'] or '',
'domain': morsel['domain'] or None,
'path': morsel['path'] or None,
'secure': bool(morsel['secure']),
'http_only': bool(morsel['httponly']),
'same_site': same_site,
Expand Down
76 changes: 68 additions & 8 deletions workers/r2p2/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,22 @@ fn http_out_from_dict(py: Python<'_>, d: &Bound<'_, PyAny>) -> Result<RpcHttp> {
})
}

/// Map an optional cookie string (`domain`/`path`) to the `NullableString`
/// the Host expects: Python `None` or an empty string stays `None`, so the
/// Host leaves the attribute unset instead of rendering `domain=`/`path=`.
fn optional_nullable_string(obj: Bound<'_, PyAny>) -> Result<Option<NullableString>> {
if obj.is_none() {
return Ok(None);
}
let s: String = obj.extract()?;
if s.is_empty() {
return Ok(None);
}
Ok(Some(NullableString {
string: Some(nullable_string::String::Value(s)),
}))
}

/// Build the `RpcHttpCookie` list from the flat cookie dicts the bridge emits.
///
/// The bridge (bridge.py `_flatten_cookies`) pre-computes every field as a plain
Expand All @@ -185,8 +201,11 @@ fn http_cookies_from_list(list_obj: &Bound<'_, PyAny>) -> Result<Vec<RpcHttpCook
let c = item?;
let name: String = c.get_item("name")?.extract()?;
let value: String = c.get_item("value")?.extract()?;
let domain: String = c.get_item("domain")?.extract()?;
let path: String = c.get_item("path")?.extract()?;
// `domain`/`path` are `None` when unset (see bridge.py
// `_flatten_cookies`); an empty string is also treated as unset so
// the Host does not render an empty `domain=`/`path=` attribute.
let domain = optional_nullable_string(c.get_item("domain")?)?;
let path = optional_nullable_string(c.get_item("path")?)?;
let secure: bool = c.get_item("secure")?.extract()?;
let http_only: bool = c.get_item("http_only")?.extract()?;
let same_site: i32 = c.get_item("same_site")?.extract()?;
Expand Down Expand Up @@ -218,12 +237,8 @@ fn http_cookies_from_list(list_obj: &Bound<'_, PyAny>) -> Result<Vec<RpcHttpCook
cookies.push(RpcHttpCookie {
name,
value,
domain: Some(NullableString {
string: Some(nullable_string::String::Value(domain)),
}),
path: Some(NullableString {
string: Some(nullable_string::String::Value(path)),
}),
domain,
path,
expires,
secure: Some(NullableBool {
bool: Some(nullable_bool::Bool::Value(secure)),
Expand Down Expand Up @@ -483,6 +498,51 @@ mod tests {

assert!(http.cookies[0].expires.is_none());
assert!(http.cookies[0].max_age.is_none());
// Empty domain/path are sent as `None`, not empty strings, so
// the Host does not render `domain=`/`path=` attributes.
assert!(http.cookies[0].domain.is_none());
assert!(http.cookies[0].path.is_none());
});
}

#[test]
fn http_output_cookie_value_with_slashes_is_preserved_and_domain_absent() {
// Regression test for Azure/azure-functions-python-worker#1794:
// a cookie like `test="hello//world"; Path=/; SameSite=lax` must
// keep its value intact and must not gain an empty `domain=`.
Python::attach(|py| {
let cookie = PyDict::new(py);
cookie.set_item("name", "test").unwrap();
cookie.set_item("value", "hello//world").unwrap();
cookie.set_item("domain", py.None()).unwrap();
cookie.set_item("path", "/").unwrap();
cookie.set_item("secure", false).unwrap();
cookie.set_item("http_only", false).unwrap();
cookie.set_item("same_site", 1).unwrap();
cookie.set_item("expires", py.None()).unwrap();
cookie.set_item("max_age", py.None()).unwrap();

let d = PyDict::new(py);
d.set_item("status_code", "200").unwrap();
d.set_item("headers", PyDict::new(py)).unwrap();
d.set_item("body", py.None()).unwrap();
d.set_item("cookies", vec![cookie]).unwrap();

let tup = datum_tuple(py, "http", d.into_any());
let out = tuple_to_typed_data(py, &tup).unwrap();
let Some(typed_data::Data::Http(http)) = out.data else {
panic!("expected Http variant");
};

assert_eq!(http.cookies.len(), 1);
assert_eq!(http.cookies[0].name, "test");
assert_eq!(http.cookies[0].value, "hello//world");
assert!(http.cookies[0].domain.is_none());
assert_eq!(
http.cookies[0].path.as_ref().unwrap().string,
Some(nullable_string::String::Value("/".to_string()))
);
assert_eq!(http.cookies[0].same_site, 1);
});
}

Expand Down
16 changes: 16 additions & 0 deletions workers/tests/unittest_r2p2/test_bridge_invocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,22 @@ def test_flatten_cookies_maps_same_site_times_and_invalid_values():
assert bridge._flatten_cookies(None) == []


def test_flatten_cookies_issue_1794_value_preserved_and_domain_absent():
# Regression test for Azure/azure-functions-python-worker#1794:
# `test="hello//world"; Path=/; SameSite=lax` must keep its value
# intact and must not gain an empty `domain=`.
cookies = [SimpleCookie('test="hello//world"; Path=/; SameSite=lax')]

flattened = bridge._flatten_cookies(cookies)

assert len(flattened) == 1
assert flattened[0]["name"] == "test"
assert flattened[0]["value"] == "hello//world"
assert flattened[0]["domain"] is None
assert flattened[0]["path"] == "/"
assert flattened[0]["same_site"] == 1


def test_datum_to_tuple_flattens_http_outputs(monkeypatch):
cookie = _cookie("session", "Strict")
datum = _Datum({
Expand Down
23 changes: 23 additions & 0 deletions workers/tests/unittests/test_datumref.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,29 @@ def test_parse_to_rpc_http_cookie_list_valid(self):
self.assertEqual(cookie1, rpc_cookies[0])
self.assertEqual(cookie2, rpc_cookies[1])

def test_parse_to_rpc_http_cookie_list_no_domain(self):
# Regression test for Azure/azure-functions-python-worker#1794:
# a cookie without a Domain (e.g. `test="hello//world"; Path=/;
# SameSite=lax`) must keep its value intact and must not gain an
# empty `domain=` attribute, so domain is sent as None.
cookies = SimpleCookie('test="hello//world"; Path=/; SameSite=lax')

cookie = RpcHttpCookie(name="test",
value="hello//world",
domain=None,
path=to_nullable_string("/", "cookie.path"),
expires=None,
secure=to_nullable_bool(
False, 'cookie.secure'),
http_only=to_nullable_bool(
False, 'cookie.httpOnly'),
same_site=parse_cookie_attr_same_site(
{"samesite": "Lax"}),
max_age=None)

rpc_cookies = parse_to_rpc_http_cookie_list([cookies])
self.assertEqual(cookie, rpc_cookies[0])

def test_parse_to_rpc_http_cookie_list_no_cookie(self):
datum = Datum(
type='http',
Expand Down