You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "loretoparisi (via GitHub)" <gi...@apache.org> on 2024/03/04 11:01:01 UTC
[I] Cannot send Cross-Origin-Resource-Policy from embed code [superset]
loretoparisi opened a new issue, #27376:
URL: https://github.com/apache/superset/issues/27376
### Bug description
I cannot force the embedded chart to sent the `Cross-Origin-Resource-Policy` header. I have set the CORS options and embedding parameters for iframe embedding as well as Cookie and CSP policy.
Superset is hosted at `localhost:8088` while I'm embedding charts at `localhost:9000`.
I have followed the configuraiton of Flask `CORS_OPTIONS` [here](https://github.com/apache/superset/issues/20425), but I cannot get rid of sending the right headers from the embedded chart.
This is my `superset_config.py`
```python
# CORS OPTIONS
ENABLE_CORS = True
CORS_OPTIONS = {
'supports_credentials': True,
'allow_headers': ['*'],
'resources':['*'],
'origins': [ 'http://localhost:9000', 'http://localhost:8088']
}
SUPERSET_FEATURE_EMBEDDED_SUPERSET=True
# EMBED CODE IFRAME OPTIONS
OVERRIDE_HTTP_HEADERS = {'X-Frame-Options': 'ALLOWALL'}
HTTP_HEADERS = {"X-Frame-Options":"ALLOWALL"}
SUPERSET_WEBSERVER_DOMAINS = [ 'localhost', 'localhost:8088', 'localhost:9000']
# SESSION_COOKIE_DOMAIN
# (default: "Lax") Prevents the browser from sending this cookie along with cross-site requests.
SESSION_COOKIE_SAMESITE = "None"
# (default: False): Controls if cookies should be set with the HttpOnly flag.
SESSION_COOKIE_HTTPONLY = False
# (default: False) Browsers will only send cookies with requests over HTTPS if the cookie is marked “secure”.
# The application must be served over HTTPS for this to make sense.
SESSION_COOKIE_SECURE = False
#CSRF_COOKIE_HTTPONLY = False
WTF_CSRF_ENABLED = False
# TALISMAN_ENABLED defaults to True; set this to False in order to disable CSP
# @see https://superset.apache.org/docs/security/#csp-requirements
TALISMAN_ENABLED = False
# you grant public role the same set of permissions as for the GAMMA role.
# This is useful if one wants to enable anonymous users to view dashboards.
# @see https://apache-superset.readthedocs.io/en/0.35.1/security.html
PUBLIC_ROLE_LIKE_GAMMA = False
# For environments where CSP policies are defined outside of Superset using other software, administrators can disable this warning
CONTENT_SECURITY_POLICY_WARNING = False
```
and the iframe was
```html
<iframe
width="600"
height="400"
seamless
frameBorder="0"
allowfullscreen
scrolling="no"
src="http://localhost:8088/superset/explore/p/a8yN1wGMobp/?standalone=1&height=400&show_filters=true&expand_filters=true"
>
</iframe>
```
while the python server serving that iframe is
```python
#!/usr/bin/env python3
from http.server import HTTPServer, SimpleHTTPRequestHandler, test
import sys
class CORSRequestHandler (SimpleHTTPRequestHandler):
def end_headers (self):
"""
Cross-Origin-Resource-Policy: cross-origin if the resource is served from another location than your website. ⚠️If you set this header, any website can embed this resource.
Cross-Origin-Resource-Policy: same-site if the resource and your site are served from the same site.
Cross-Origin-Embedder-Policy: credentialless instead of require-corp. It allows loading the resource, despite the missing CORP header, at the cost of requesting it without credentials like Cookies.
"""
self.send_header('Cross-Origin-Embedder-Policy', 'credentialless') #require-corp
self.send_header('Cross-Origin-Opener-Policy', 'cross-origin') #same-origin
self.send_header('Cross-Origin-Resource-Policy', ' cross-origin')
self.send_header('X-Frame-Options', 'allow-from *')
self.send_header("Access-Control-Allow-Origin", "*")
SimpleHTTPRequestHandler.end_headers(self)
test(CORSRequestHandler, HTTPServer, port=int(sys.argv[1]) if len(sys.argv) > 1 else 8000)
```
### How to reproduce the bug
1. Copy the `superset_config.py` provided above
2. Copy the `html` code above in a `embed.html` page
3. Create a `cors.py` python code
4. execute `python cors.py 9000` to serve the embedded chart
### Screenshots/recordings
The Chrome error was
```
Specify a Cross-Origin Resource Policy to prevent a resource from being blocked
Because your site has the Cross-Origin Embedder Policy (COEP) enabled, each resource must specify a suitable Cross-Origin Resource Policy (CORP). This behavior prevents a document from loading cross-origin resources which don’t explicitly grant permission to be loaded.
To solve this, add the following to the resource’ response header:
Cross-Origin-Resource-Policy: same-site if the resource and your site are served from the same site.
Cross-Origin-Resource-Policy: cross-origin if the resource is served from another location than your website. ⚠️If you set this header, any website can embed this resource.
Alternatively, the document can use the variant: Cross-Origin-Embedder-Policy: credentialless instead of require-corp. It allows loading the resource, despite the missing CORP header, at the cost of requesting it without credentials like Cookies.
```
### Superset version
master / latest-dev
### Python version
3.9
### Node version
18 or greater
### Browser
Chrome
### Additional context
_No response_
### Checklist
- [X] I have searched Superset docs and Slack and didn't find a solution to my problem.
- [X] I have searched the GitHub issue tracker and didn't find a similar bug report.
- [X] I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [I] Cannot send Cross-Origin-Resource-Policy from embed code [superset]
Posted by "loretoparisi (via GitHub)" <gi...@apache.org>.
loretoparisi commented on issue #27376:
URL: https://github.com/apache/superset/issues/27376#issuecomment-1984123978
My solution was to write a Flask Middlware to send the proper headers, specifically
```python
response.headers.add("Cross-Origin-Embedder-Policy", 'require-corp')
response.headers.add("Cross-Origin-Resource-Policy", 'cross-origin')
```
As alternative, when using a reverse proxy (e.g. nginix) it is possible to add to the `nginix/nginix.conf`
```nginx
add_header Cross-Origin-Resource-Policy "cross-origin";
```
Of course the Flask middleware solution is more flexible for development purposes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [I] Cannot send Cross-Origin-Resource-Policy from embed code [superset]
Posted by "WaudoDavid (via GitHub)" <gi...@apache.org>.
WaudoDavid commented on issue #27376:
URL: https://github.com/apache/superset/issues/27376#issuecomment-2071994774
This will only work if you disable Talisman and set your own content security policy.
**TALISMAN_ENABLED = False
#Allows any website to embed the iframe on its website
#OVERRIDE_HTTP_HEADERS = { "X-Frame-Options": "ALLOWALL" }
#Allows only your website to be the only website allowed to embed dashboards
OVERRIDE_HTTP_HEADERS = { "Content-Security-Policy": "frame-ancestors http://your.domain.com;" }
# @loretoparisi**
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [I] Cannot send Cross-Origin-Resource-Policy from embed code [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas closed issue #27376: Cannot send Cross-Origin-Resource-Policy from embed code
URL: https://github.com/apache/superset/issues/27376
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [I] Cannot send Cross-Origin-Resource-Policy from embed code [superset]
Posted by "loretoparisi (via GitHub)" <gi...@apache.org>.
loretoparisi commented on issue #27376:
URL: https://github.com/apache/superset/issues/27376#issuecomment-1976383340
**[NOTE]**
Using
```python
OVERRIDE_HTTP_HEADERS = { 'X-Frame-Options': 'ALLOWALL' }
HTTP_HEADERS = { "X-Frame-Options" : "ALLOWALL" }
```
or as detailed [here](https://github.com/apache/superset/issues/6418)
```python
HTTP_HEADERS = {}
```
does not solve this issue.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [I] Cannot send Cross-Origin-Resource-Policy from embed code [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on issue #27376:
URL: https://github.com/apache/superset/issues/27376#issuecomment-2734971766
This has gone silent for nearly a year, so I'll respectfully close it. If anyone is still facing this in currently supported versions, please provide updated context and we'll re-open :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org