streamlit: Misconfigured _xsrf cookies
Checklist
- I have searched the existing issues for similar issues.
- I added a very descriptive title to this issue.
- I have provided sufficient information below to help reproduce this issue.
Summary
Hi,
I am running a Streamlit app on Azure, requiring authentication with AD, and st.file_uploader returns a 403 Forbidden error if enableXsrfProtection is on. It works locally, and I suspect that this is caused by the _xsrf cookie not getting though, because I can see the cookie in dev tools locally, but not when deployed.
In particular, the cookie is missing the SameSite and Secure attributes.
Reproducible Code Example
No response
Steps To Reproduce
- Open any Streamlit app
- Open browser developer tools
Expected Behavior
Cookies have SameSite=None; Secure attribute.
Current Behavior
_xsrf cookie is not transmitted when deployed on the cloud with SSO and HTTPS-only.
Locally this is what I am getting:

Plus the deprecation warning:
Some cookies are misusing the recommended “SameSite“ attribute Cookie “_xsrf” does not have a proper “SameSite” attribute value. Soon, cookies without the “SameSite” attribute or with an invalid value will be treated as “Lax”. This means that the cookie will no longer be sent in third-party contexts. If your application depends on this cookie being available in such contexts, please add the “SameSite=None“ attribute to it. To know more about the “SameSite“ attribute, read https://developer.mozilla.org/docs/Web/HTTP/Headers/Set-Cookie/SameSite
Is this a regression?
- Yes, this used to work in a previous version.
Debug info
- Streamlit version: 1.15.0
- Python version: 3.10, 3.11
- Operating System: Ubuntu 22.04 (WSL)
- Browser: Firefox, Chrome
- Virtual environment: yes
Additional Information
This has been touched on in https://github.com/streamlit/streamlit/issues/2517 and particularly https://github.com/streamlit/streamlit/issues/2517#issuecomment-1321281460. Feel free to close if you consider this is a duplicate, but I believe that the cookie configuration and Streamlit overwriting Jupyter’s cookies are two different issues.
There are multiple reports of this on the forum:
https://discuss.streamlit.io/t/azure-ad-xsrf-protection-and-st-file-uploader/33612
https://discuss.streamlit.io/t/file-uploader-403-error-when-embedding-streamlit-app-in-iframe/24109
Whether they all have the same underlying cause, I cannot tell.
Are you willing to submit a PR?
- Yes, I am willing to submit a PR!
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 19
- Comments: 15
Any updates on this issue ? We are deploying streamlit application to Azure App service with Azure AD authentication and have the same issue with file upload. Could you kindly clarify if this is addressed in any of the recent versions or if there is a plan to address the same ?
If this issue affects you, please react with a 👍 (thumbs up emoji) to the initial post.
Your feedback helps us prioritize which bugs to investigate and address first.
@kajarenc Thank you for your reply.
I develop in an environment where I do not have access to the NGINX proxy. I am sure many other Streamlit library users do not understand or do not administer their proxies.
I am not suggesting that logs be exposed to a Streamlit user. I am suggesting that when the status is set to 403, it would be helpful to SREs and developers to do a
_LOGGER.debug("ComponentRequestHandler: GET %s forbidden (component_root %s)", abspath, component_root)so that the problem can be diagnosed more quickly. (Or possibly_LOGGER.infolevel.)I was able to get my code working with
--server.enableXsrfProtection=falsebut I am still trying to understand if a cookie was dropped, by which component, and whatbrowser.serverAddressStreamlit believes it is deployed on.Yeah, I’m still running into this issue on Streamlit 1.31.0 unfortunately.
+1
This is still an issue on Streamlit 1.30
If I’m not mistaken, this issue should maybe be reopened as https://github.com/streamlit/streamlit/pull/7482 reverted the fix. @kajarenc
Thanks!