question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Move parameters merging to the backend and make it safe

See original GitHub issue

Currently the way parameters work in Redash is that we use the query text as a Mustache template and merge the parameter values with it before running the query.

This very simple implementation has one major issue: it’s open to SQL injections. It’s a non issue when a “regular” Redash user uses parameters, as they can run any query anyway. But it limits the use of parameters to users with full access to the data source.

To provide any user with the ability to use parameters, we need to change our implementation to make it safe and SQL injections proof.

The idea is:

  1. Change the API to handle all parameters merging in the backend (today we send the final query from frontend).
  2. Make the API safe.

While every database driver we use (that supports DB-API) has its own way of taking query text with parameters, it’s better that we find a single way that is DB agnostic. Also need to remember that some of our datasources take queries as JSON/YAML.

It’s also preferable that we can support current parameters syntax ({{ parameter }}), but we don’t have to support the full range of Mustache functions (although it can be nice).


Some “prior art” that might be useful:

  1. https://github.com/hashedin/jinjasql
  2. sqlalchemy.sql.expression.text
  3. psycopg2.sql module
  4. https://github.com/deadpixi/dpdb

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:14 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
arikfrcommented, May 13, 2019

@shinsuke-nara we ended up implementing validation of parameters on the backend. Read only users can now use parameters except for the text parameter type, which isn’t safe as we can’t validate it at the moment.

Once we are done with enabling parameters in various scenarios, we will get back to allowing the use of text parameters. Either by passing them to the query runner or sanitizing them ourselves.

1reaction
rauchycommented, Nov 12, 2018

Are you referring to injections via the WHERE clause only? Because I think all the other clauses are susceptible to SQL injection. (select 1; drop table midgets)

Read more comments on GitHub >

github_iconTop Results From Across the Web

django - Move POST parameters to query ... - Stack Overflow
I am using datatables, with a DRF backend, which is working fine. I am moving the application to integration and ... it stops...
Read more >
How to Secure Frontend Code by Moving to Serverless Cloud
We look at modern best practices for securely moving frontend code to the cloud using a serverless cloud approach, walking step-by-step ...
Read more >
Merging results from different Explores | Looker - Google Cloud
Combine data from multiple Explores using Merged Results. ... Merged results do not perform an actual SQL join.
Read more >
How to add configurable parameters for a Merge Module
In your Merge Module project go to Custom Actions Page. · Select your defined custom action. · From the context menu select the...
Read more >
git-merge Documentation - Git
Note that fast-forward updates do not create a merge commit and therefore there is no way to stop those merges with --no-commit. Thus,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found