You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2021/12/11 18:37:24 UTC

[GitHub] [superset] d9k commented on issue #17719: SQL injection with Jinja 2 templates: how to escape values?

d9k commented on issue #17719:
URL: https://github.com/apache/superset/issues/17719#issuecomment-991742527


   As a temporary poor man's solution I've added custom functions for jinja2 templates to escape [PrestoDb](https://prestodb.io/) strings. These functions use replacement of single quote with `CHR(39)` concatenation:
   
   ```
   # >> escape_presto_string("Dr's")
   # "Dr' || CHR(39) || 's"
   def escape_presto_string(s = ''):
     return s.replace("'", "' || CHR(39) || '")
   
   # >> escape_presto_strings(["Dr's", 't'])
   # ["Dr' || CHR(39) || 's", 't']
   def escape_presto_strings(ar = []):
     return list(map(escape_presto_string, ar))
   
   # >> escape_presto_strings_in(["Dr's", 't'])
   # "'Dr' || CHR(39) || 's','t'"
   def escape_presto_strings_in(ar = []):
     escaped_ar = escape_presto_strings(ar)
     if (len(escaped_ar) == 0):
       return ""
     return "'" + "','".join(escaped_ar) + "'"
   
   JINJA_CONTEXT_ADDONS = {
       "escape_presto_string": escape_presto_string,
       "escape_presto_strings": escape_presto_strings,
       "escape_presto_strings_in": escape_presto_strings_in,
       "list": list,
   }
   ```


-- 
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