Skip to content

Commit

Permalink
Harden the database deletion against SQL injections
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-bach-by committed Feb 1, 2018
1 parent 7cd8d01 commit ed2e895
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ def delete_database(db_name, config):
con.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
with con.cursor() as cur:
try:
cur.execute('''DROP DATABASE "{}";'''.format(db_name))
cur.execute(SQL('DROP DATABASE {};').format(
Identifier(db_name),
))
except psycopg2.ProgrammingError as e:
raise ValueError(e.args[0])

Expand All @@ -79,6 +81,8 @@ def delete_user(username, config):
con.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
with con.cursor() as cur:
try:
cur.execute('''DROP USER "{}";'''.format(get_normalized_username(username)))
cur.execute(SQL('DROP USER {};').format(
Identifier(get_normalized_username(username)),
))
except psycopg2.ProgrammingError as e:
raise ValueError(e.args[0])

0 comments on commit ed2e895

Please sign in to comment.