Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
migrations: Escape more pedantically in pgroonga.0001_enable.
Anders Kaseorg0cc897d08d15
diff --git a/pgroonga/migrations/0001_enable.py b/pgroonga/migrations/0001_enable.pyindex 9c0797e1efe..2e5f645a93d 100644--- a/pgroonga/migrations/0001_enable.py+++ b/pgroonga/migrations/0001_enable.py@@ -11,8 +11,9 @@ class Migration(migrations.Migration):database_setting = settings.DATABASES["default"]if "postgres" in database_setting["ENGINE"]:operations = [- migrations.RunSQL("""-ALTER ROLE %(USER)s SET search_path TO %(SCHEMA)s,public,pgroonga,pg_catalog;+ migrations.RunSQL([("""+DO $$BEGIN+EXECUTE format('ALTER ROLE %%I SET search_path TO %%L,public,pgroonga,pg_catalog', %(USER)s, %(SCHEMA)s);SET search_path = %(SCHEMA)s,public,pgroonga,pg_catalog;@@ -23,8 +24,10 @@ ALTER TABLE zerver_message ADD COLUMN search_pgroonga text;-- Django 1.10 may solve the problem.CREATE INDEX zerver_message_search_pgroonga ON zerver_messageUSING pgroonga(search_pgroonga pgroonga.text_full_text_search_ops);-""" % database_setting,- """+END$$+""", database_setting)],+ [("""+DO $$BEGINSET search_path = %(SCHEMA)s,public,pgroonga,pg_catalog;DROP INDEX zerver_message_search_pgroonga;@@ -32,8 +35,9 @@ ALTER TABLE zerver_message DROP COLUMN search_pgroonga;SET search_path = %(SCHEMA)s,public;-ALTER ROLE %(USER)s SET search_path TO %(SCHEMA)s,public;-""" % database_setting),+EXECUTE format('ALTER ROLE %%I SET search_path TO %%L,public', %(USER)s, %(SCHEMA)s);+END$$+""", database_setting)]),]else:operations = []diff --git a/tools/semgrep.yml b/tools/semgrep.ymlindex 77123f831c4..94982715edb 100644--- a/tools/semgrep.yml+++ b/tools/semgrep.yml@@ -72,6 +72,8 @@ rules:- pattern: ... .execute("...".format(...))- pattern: psycopg2.sql.SQL(... % ...)- pattern: psycopg2.sql.SQL(... .format(...))+ - pattern: django.db.migrations.RunSQL(..., ... % ..., ...)+ - pattern: django.db.migrations.RunSQL(..., "..." .format(...), ...)severity: ERRORmessage: "Do not write a SQL injection vulnerability please"