-
Notifications
You must be signed in to change notification settings - Fork 14.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error The CSRF session token is missing
when embed superset in iframe
#8382
Comments
Issue-Label Bot is automatically applying the label Links: app homepage, dashboard and code for this bot. |
I have solved this problem. |
Where did you set this? I've installed superset using pip and can't tell where I can set that variable; thanks. |
set in superset/config.py。This is flask session cookie options |
In superset 0.36 it is also necessary to set |
This issue produce quiet some confusion because browsers behaviors aren't aligned... Actually, what I found is the following:
This above setup is stated in a IETF proposal: Incrementally Better Cookies and was ported to my attention in this article: Cookies and Iframes. More over, I noticed the following:
|
If your Superset is not under https, the following setup worked for me:
Superset v.1.0.1, Chrome 89 |
I use version 1.1.0
|
how can this issue be solved in a helm deployment?? |
Also changing "CSRF_ENABLED" to False worked for me:
|
Please note, its |
I am still getting the same error even after applying all the configurations. I have tried setting
It is working fine when i am trying to call API from Postman. However, in the app, I keep getting the same error. I have also attached |
In the "app", when you get the CSRF Token, it responds with a Set-Cookie header alongside the token. You need to use that same cookie when requesting the guest token. Depending on how you're doing the requests, if you create a "client" that does all of the requests it'll probably store the cookies automatically. If not, you need to add the cookies in manually. |
I have added complete blog on integration of embed superset dashboard - https://medium.com/@vishalsadriya1224/embedding-apache-superset-dashboards-in-ruby-on-rails-and-react-a-role-level-security-guide-697da01676af |
I think disabling CSP, is a somewhat dangerous way of doing it. You should copy across the talisman config in config.py to superset_config.py, but allow frame ancestors from hosts you choose. Or even '*', but disabling talisman altogether and replacing it with custom CORS options is a bit complex and potentially dangerous if you do not know what you're doing. Anyway, yes, from what I can tell, the issue is from the cookie not being set, so it is good you are including this. |
headersauth = { |
Try |
@Alvie Nope still the same error. |
For me, the cookie |
I don't think the cookie is meant to be a header by the way, it might be an independent parameter. If you are using python requests, it is something like this: cookies = {'enwiki_session': '17ab96bd8ffbe8ca58a78657a918558'}
r = requests.post('http://wikipedia.org', cookies=cookies) |
@Alvie #8382 (comment) |
You misunderstood. The server responds with the Set-Cookie header, so your client application should set that cookie. Many libraries don't persist cookies, so this is something you need to do yourself. Whatever the Set-Cookie has the server has responded with e.g. |
I'm still having this issue, the cookie is stored on the browser and is being sent to API but the same error persists. Did anyone find a solution for this? |
Can you send an example of your API Request Headers inc cookies |
"I could be wrong but it looks like there's no cookies being sent in the request. Maybe the cookie from the Set-Cookie response hasn't been applied to the client" Do you know how I can apply that cookie to the client? |
Sorry, I'm not entirely sure. I think it depends on the library you are using. Apparently (for example), the fetch API doesn't include it by default, and you need to use Do you see the |
Actually adding { credentials: "include" } to fetch() options solved the issue, thanks! |
You're very welcome! Glad to hear your issue is fixed :) |
your config.py should look like this ................. |
This will work, but it's dangerous to present it as the solution because you disabled many security features in the process. This will disable CSP, CSRF, and Talisman, and allows CORS from anywhere. Instead of disabling Talisman and a lot of security features, you should just just add the frame ancestors you wish to allow in the TALISMAN_CONFIG (copy it from TALISMAN_CONFIG = {
"content_security_policy": {
"base-uri": ["'self'"],
"default-src": ["'self'"],
"img-src": [
"'self'",
"blob:",
"data:",
"https://apachesuperset.gateway.scarf.sh",
"https://static.scarf.sh/",
# "https://avatars.slack-edge.com", # Uncomment when SLACK_ENABLE_AVATARS is True
],
"worker-src": ["'self'", "blob:"],
"connect-src": [
"'self'",
"https://api.mapbox.com",
"https://events.mapbox.com",
],
"object-src": "'none'",
"style-src": [
"'self'",
"'unsafe-inline'",
],
"script-src": ["'self'", "'strict-dynamic'"],
"frame-ancestors": ["*"], # MAKE SURE TO ADD ORIGIN HERE TO ALLOW
},
"content_security_policy_nonce_in": ["script-src"],
"force_https": False,
"session_cookie_secure": False,
} |
Error
The CSRF session token is missing
when embed superset in iframeExpected results
Embed charts or dashboard in my web page via iframe
Code
Actual results
Access in chrome address bar
Successful access
When access my web page via iframe
admin
When I login, Receive Error "
Bad Request
The CSRF session token is missing.
"public
Receive Error
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <title>400 Bad Request</title> <h1>Bad Request</h1> <p>The CSRF session token is missing.</p>
Screenshots
How to reproduce the bug
superset run -h 0.0.0.0 -p 8088
Environment
(please complete the following information):
0.999.0dev / master 2019-10-13
3.7.3
v10.15.2
5.8.0
Checklist
Make sure these boxes are checked before submitting your issue - thank you!
Additional context
config.py setting
PUBLIC_ROLE_LIKE_GAMMA = True
The text was updated successfully, but these errors were encountered: