SQL injection with Jinja 2 templates: how to escape values? #18358
Replies: 7 comments 2 replies
-
As a temporary poor man's solution I've added custom functions for jinja2 templates to escape PrestoDb strings. These functions use replacement of single quote with
|
Beta Was this translation helpful? Give feedback.
-
So code above becomes:
|
Beta Was this translation helpful? Give feedback.
-
I want to improve |
Beta Was this translation helpful? Give feedback.
-
I think it's good practise to deny requests with non printable characters and check field length. |
Beta Was this translation helpful? Give feedback.
-
@andrey-mikhailov don't have what?
Superset uses python, not php |
Beta Was this translation helpful? Give feedback.
-
I know it's an older topic, but since this didn't provide the answer and I've found it since, I figured that for future people looking for the same solution I figured I'd post what I found. Sample code that allows you to search partial matches of a list of values provided in a dashboard filter, but escapes the unsafe characters like the single quote:
Test SQL injection by providing this in a dashboard filter: |
Beta Was this translation helpful? Give feedback.
-
It should be very important point to use Jinja templates. I consider that the Superset doc should mention that using Jinja Template is vulnerable to SQL injection so we need manual escaping or |
Beta Was this translation helpful? Give feedback.
-
(Assuming we have
)
For example, I have a filter
How can I escape SQL values in
{{ "'" + "','".join(filter_city) + "'" }}
expression to make this filter template safe?See also:
Beta Was this translation helpful? Give feedback.
All reactions