You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] Python Azure Function worker incorrectly URL encodes cookie value #1794
I can confirm. Same on Python 3.13. Problem is one way only (responses) and affects Set-Cookie's cookie value portion only. Cookies sent back from the browser arrive intact even with URL unsafe chars.
Happened to incur in this bug while coding a FastAPI app using starlette session middleware.
Workaround is to add a custom middleware to perform 2-way base64url encoding/decoding of cookie values in Set-Cookie headers (just values!, not other Set-Cookies parts). Also beware Python's base64.urlsafe_b64encode is not compliant to base64url standards, so you also have to workaround this as well by manually dropping and readding the padding chars.
I hope you'll figure out how to fix this without breaking your header injection vulnerability countermeasures. 😉
Hi — I've opened a pull request with a partial fix for the empty domain=/path= half of this issue: #1955.
The PR sends unset cookie domain/path as null instead of an empty string, so the Functions Host leaves the attribute off the Set-Cookie header instead of rendering an empty domain=.
It does not fix the %2F URL-encoding of the cookie value — that happens in the Functions Host (ASP.NET Core Response.Cookies.Append uses Uri.EscapeDataString), so that half still needs a host-side follow-up in azure-functions-host.
Activity
LuKePicci commentedon Feb 6, 2026
I can confirm. Same on Python 3.13. Problem is one way only (responses) and affects Set-Cookie's cookie value portion only. Cookies sent back from the browser arrive intact even with URL unsafe chars.
Happened to incur in this bug while coding a FastAPI app using starlette session middleware.
Workaround is to add a custom middleware to perform 2-way base64url encoding/decoding of cookie values in Set-Cookie headers (just values!, not other Set-Cookies parts). Also beware Python's base64.urlsafe_b64encode is not compliant to base64url standards, so you also have to workaround this as well by manually dropping and readding the padding chars.
I hope you'll figure out how to fix this without breaking your header injection vulnerability countermeasures. 😉
Allen5288 commentedon Nov 22, 2026
Hi — I've opened a pull request with a partial fix for the empty
domain=/path=half of this issue: #1955.The PR sends unset cookie domain/path as null instead of an empty string, so the Functions Host leaves the attribute off the
Set-Cookieheader instead of rendering an emptydomain=.It does not fix the
%2FURL-encoding of the cookie value — that happens in the Functions Host (ASP.NET CoreResponse.Cookies.AppendusesUri.EscapeDataString), so that half still needs a host-side follow-up inazure-functions-host.