Skip to content

Commit

Permalink
fix: add csp header for iframe embedding (#1442)
Browse files Browse the repository at this point in the history
  • Loading branch information
jczhong84 authored Apr 17, 2024
1 parent 302b6ac commit 80a9eee
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs_website/docs/configurations/infra_config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ Otherwise you can also pass the environment variable directly when launching the

`WS_CORS_ALLOWED_ORIGINS`: (**required for production**): This is the allowed list of origins for CORS. For dev environment, all origins will be allowed.

### Iframe Embedding

`IFRAME_ALLOWED_ORIGINS`: This is the allowed list for embedding Querybook in an iframe. By default it can only be embedded by itself.

### Database

`DATABASE_CONN` (**required**): A sqlalchemy connection string to the database. Please check here https://docs.sqlalchemy.org/en/13/core/engines.html for formatting.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "querybook",
"version": "3.33.3",
"version": "3.33.4",
"description": "A Big Data Webapp",
"private": true,
"scripts": {
Expand Down
10 changes: 10 additions & 0 deletions querybook/server/app/flask_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ def make_flask_app():
if QuerybookSettings.TABLE_MAX_UPLOAD_SIZE is not None:
app.config["MAX_CONTENT_LENGTH"] = int(QuerybookSettings.TABLE_MAX_UPLOAD_SIZE)

# Add Content-Security-Policy header to restrict iframe embedding to the allowed origins
csp_header_value = "frame-ancestors 'self' " + " ".join(
QuerybookSettings.IFRAME_ALLOWED_ORIGINS or []
)

@app.after_request
def add_csp_header(response):
response.headers["Content-Security-Policy"] = csp_header_value
return response

return app


Expand Down
1 change: 1 addition & 0 deletions querybook/server/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class QuerybookSettings(object):
FLASK_SECRET_KEY = get_env_config("FLASK_SECRET_KEY", optional=False)
FLASK_CACHE_CONFIG = get_env_config("FLASK_CACHE_CONFIG")
WS_CORS_ALLOWED_ORIGINS = get_env_config("WS_CORS_ALLOWED_ORIGINS", optional=False)
IFRAME_ALLOWED_ORIGINS = get_env_config("IFRAME_ALLOWED_ORIGINS")

# Celery
REDIS_URL = get_env_config("REDIS_URL", optional=False)
Expand Down

0 comments on commit 80a9eee

Please sign in to comment.