Skip to content

Fix empty cookie domain/path sent as empty string (partial fix for #1794) - #1955

Open
Allen (Allen5288) wants to merge 19 commits into
Azure:devfrom
Allen5288:fix-cookie-domain-empty
Open

Allen (Allen5288) wants to merge 19 commits into
Azure:devfrom
Allen5288:fix-cookie-domain-empty

Conversation

@Allen5288

Copy link
Copy Markdown

Description

Partially fixes #1794

This is a partial fix for #1794. It fixes the spurious empty domain= (and path=) half of the issue: when a cookie has no Domain (or Path) attribute, the worker was sending an empty string to the Functions Host, which rendered it as an empty domain= attribute on the Set-Cookie header. Unset domain/path are now sent as null instead of an empty string, so the Host leaves the attribute off.

This does not fix the %2F URL-encoding of the cookie value reported in #1794 (for example, test=hello//world arriving as test=hello%2F%2Fworld). That encoding happens in the Functions Host: ASP.NET Core Response.Cookies.Append applies Uri.EscapeDataString to the value. That half needs a follow-up change in Azure/azure-functions-host (stop routing worker cookies through Response.Cookies.Append, or write the Set-Cookie header directly).

Changes

  • workers/azure_functions_worker/bindings/datumdef.py, runtimes/v1/azure_functions_runtime_v1/bindings/datumdef.py and runtimes/v2/azure_functions_runtime/bindings/datumdef.py: parse_to_rpc_http_cookie_list now sends cookie_entity['domain'] or None / cookie_entity['path'] or None, matching the existing to_nullable_double precedent (empty string → None).
  • workers/r2p2/bridge/bridge.py: _flatten_cookies now emits 'domain': morsel['domain'] or None / 'path': morsel['path'] or None (was or ''), with the docstring updated.
  • workers/r2p2/src/convert.rs: new optional_nullable_string() helper (None/empty → None, otherwise Some(NullableString)); http_cookies_from_list uses it for domain/path, and the existing test now asserts domain/path are None.
  • Regression tests: new test_parse_to_rpc_http_cookie_list_no_domain in the worker, v1 and v2 test suites; new test_flatten_cookies_issue_1794_value_preserved_and_domain_absent in the r2p2 bridge tests; and a new Rust test http_output_cookie_value_with_slashes_is_preserved_and_domain_absent. All use SimpleCookie('test="hello//world"; Path=/; SameSite=lax') and assert the value is preserved and domain is absent/None.

Testing

  • 125 Python tests pass locally: 61 worker + bridge tests, 32 v1 tests (test_datumdef.py + test_nullable_converters.py), 32 v2 tests (same).
  • Negative control: with only the source changes stashed (tests kept), all 4 new Python regression tests fail; with the fix they pass.
  • Rust tests could not run locally (no cargo in the sandbox) — please let CI run cargo test before merge.

Pull Request Checklist

Host-Worker Contract

  • Does this PR impact the host-worker contract (e.g., gRPC messages, shared interfaces)?
    • If yes, have the changes been applied to:
      • azure_functions_worker (Python <= 3.12)
      • proxy_worker (Python 3.13-3.14)
      • r2p2 (Python >= 3.15)
    • If no, please explain why:
    • Note: the gRPC message shape is unchanged; only the values carried in RpcHttpCookie.domain/path change from an empty string to null when the attribute is unset. The proxy worker change is in runtimes/v1 and runtimes/v2.

Worker Execution Logic

  • Does this PR affect worker execution logic (e.g., function invocation, bindings, lifecycle)?
    If yes, please answer the following:

Python Version Coverage

  • Does this change apply to all supported worker models?
  • If yes, have the changes been made to:
    • azure_functions_worker (Python <= 3.12)
    • proxy_worker (Python 3.13-3.14)
    • r2p2 (Python >= 3.15)
    • runtimes/v1 / runtimes/v2 (Python >= 3.13)
  • If no, please explain why:

Programming Model Compatibility (proxy_worker and r2p2)

  • Does this change apply to both:
    • V1 programming model (runtimes/v1)?
    • V2 programming model (runtimes/v2)?
  • Explanation (if limited to one model):

Added regression test for handling cookies without a Domain attribute to ensure proper value retention.
Added a regression test for handling cookies without a Domain attribute, ensuring the value remains intact and domain is set to None.
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@Allen5288

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Python Azure Function worker incorrectly URL encodes cookie value

1 participant