Skip to content
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

Feature/params on embeds #995

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions rd_ui/app/scripts/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,21 @@ angular.module('redash', [
}
])
.controller('EmbedCtrl', ['$scope', function ($scope) {} ])
.controller('EmbeddedVisualizationCtrl', ['$scope', 'Query', 'QueryResult',
function ($scope, Query, QueryResult) {
.controller('EmbeddedVisualizationCtrl', ['$scope', '$location', 'Query', 'QueryResult',
function ($scope, $location, Query, QueryResult) {
$scope.embed = true;
$scope.visualization = visualization;
$scope.query = visualization.query;
query = new Query(visualization.query);
$scope.queryResult = new QueryResult({query_result:query_result});

//max age from querystring, default to -1
maxAge = $location.search()['maxAge'];
if (maxAge === undefined) {
maxAge = -1;
}

qr = query.getQueryResult(maxAge, Query.collectParamsFromQueryString($location, query));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that you don't use the query_result object, which means:

  1. This won't work for unautheticated users (the call to query result will be without the API key).
  2. No point in passing it or preloading it.

I think your direction is the right one, but needs a bit more work to work in all scenarios.

My suggestion is:
Rewrite the embed endpoint to be more like public_dashboard and use the same template (public.html). We can drop the embed.js file and move the routes definitions into app.js.

Pass in the seed_data only the query object, but use the API to receive the query result (either a new one or existing one with the query result id). In app.js we already take care of passing the API key to subsequent API calls so it will work both for signed in and signed out users.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback, @arikfr. I'll have a dig into your suggestion and see what I can come up with.


$scope.queryResult = qr;
} ])
;
9 changes: 8 additions & 1 deletion redash/handlers/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ def embed(query_id, visualization_id, org_slug=None):

qr = project(qr, ('data', 'id', 'retrieved_at'))
vis = project(vis, ('description', 'name', 'id', 'options', 'query', 'type', 'updated_at'))
vis['query'] = project(vis['query'], ('created_at', 'description', 'name', 'id', 'latest_query_data_id', 'name', 'updated_at'))

if settings.ALLOW_PARAMETERS_IN_EMBEDS == True:
#this will enable embedding parameters, but in doing so will expose the query sql
#the query sql will be passed to clients with the security token
vis['query'] = project(vis['query'], ('created_at', 'description', 'name', 'id', 'latest_query_data_id', 'name', 'updated_at', 'latest_query_data', 'data_source_id', 'query'))
else:
vis['query'] = project(vis['query'], ('created_at', 'description', 'name', 'id', 'latest_query_data_id', 'name', 'updated_at'))


return render_template("embed.html",

Expand Down
6 changes: 6 additions & 0 deletions redash/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ def all_settings():
# Enhance schema fetching
SCHEMA_RUN_TABLE_SIZE_CALCULATIONS = parse_boolean(os.environ.get("REDASH_SCHEMA_RUN_TABLE_SIZE_CALCULATIONS", "false"))

# Allow Parameters in Embeds
# Warning: This will expose the full sql query and query attributes in the embed javascript
# If you are exposing embeds publicly, be aware that this setting can leak your sql queries
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth mentioning that there is also the danger of SQL injection.

ALLOW_PARAMETERS_IN_EMBEDS = parse_boolean(os.environ.get("REDASH_ALLOW_PARAMETERS_IN_EMBEDS", "false"))


### Common Client config
COMMON_CLIENT_CONFIG = {
'allowScriptsInUserInput': ALLOW_SCRIPTS_IN_USER_INPUT,
Expand Down