Dataset Viewer
Auto-converted to Parquet Duplicate
func_name
stringlengths
2
38
code
stringlengths
63
7.98k
vul_type
stringclasses
6 values
line_changes
stringlengths
194
5.09k
char_changes
stringlengths
83
6.45k
is_vulnerable
bool
2 classes
vul_type_name
stringclasses
6 values
vul_type_description
stringclasses
6 values
build_board
def build_board(conn, game,size): # we'll build the empty board, and then fill in with the move list that # we get from the DB. board = [] for i in range(size): board.append([""]*size) # search for all moves that have happenend during this game. cursor = conn.cursor() cursor.execute("SELECT x,y,letter FROM moves WHERE gameID = %d;" % game) counts = {"X":0, "O":0} for move in cursor.fetchall(): (x,y,letter) = move x = int(x) y = int(y) assert x >= 0 and x < size assert y >= 0 and y < size assert letter in "XO" assert board[x][y] == "" board[x][y] = letter counts[letter] += 1 cursor.close() assert counts["X"] >= counts["O"] assert counts["X"] <= counts["O"]+1 if counts["X"] == counts["O"]: nextPlayer = 0 else: nextPlayer = 1 letter = "XO"[nextPlayer] return (board,nextPlayer,letter)
cwe-089
{'deleted': [{'line_no': 11, 'char_start': 303, 'char_end': 380, 'line': ' cursor.execute("SELECT x,y,letter FROM moves WHERE gameID = %d;" % game)\n'}], 'added': [{'line_no': 11, 'char_start': 303, 'char_end': 382, 'line': ' cursor.execute("SELECT x,y,letter FROM moves WHERE gameID = %d;", (game,))\n'}]}
{'deleted': [{'char_start': 371, 'char_end': 373, 'chars': ' %'}], 'added': [{'char_start': 371, 'char_end': 372, 'chars': ','}, {'char_start': 373, 'char_end': 374, 'chars': '('}, {'char_start': 378, 'char_end': 380, 'chars': ',)'}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
build_board
def build_board(conn, game,size): # we'll build the empty board, and then fill in with the move list that # we get from the DB. board = [] for i in range(size): board.append([""]*size) # search for all moves that have happenend during this game. cursor = conn.cursor() cursor.execute("SELECT x,y,letter FROM moves WHERE gameID = %d;", (game,)) counts = {"X":0, "O":0} for move in cursor.fetchall(): (x,y,letter) = move x = int(x) y = int(y) assert x >= 0 and x < size assert y >= 0 and y < size assert letter in "XO" assert board[x][y] == "" board[x][y] = letter counts[letter] += 1 cursor.close() assert counts["X"] >= counts["O"] assert counts["X"] <= counts["O"]+1 if counts["X"] == counts["O"]: nextPlayer = 0 else: nextPlayer = 1 letter = "XO"[nextPlayer] return (board,nextPlayer,letter)
cwe-089
{'deleted': [{'line_no': 11, 'char_start': 303, 'char_end': 380, 'line': ' cursor.execute("SELECT x,y,letter FROM moves WHERE gameID = %d;" % game)\n'}], 'added': [{'line_no': 11, 'char_start': 303, 'char_end': 382, 'line': ' cursor.execute("SELECT x,y,letter FROM moves WHERE gameID = %d;", (game,))\n'}]}
{'deleted': [{'char_start': 371, 'char_end': 373, 'chars': ' %'}], 'added': [{'char_start': 371, 'char_end': 372, 'chars': ','}, {'char_start': 373, 'char_end': 374, 'chars': '('}, {'char_start': 378, 'char_end': 380, 'chars': ',)'}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
check_and_update_ranks
def check_and_update_ranks(self, scene): # There are 2 cases here: # 1) Ranks have never been calculated for this scene before # - This means we need to calculate what the ranks were every month of this scenes history # - We should only do this if ranks don't already exist for this scene # 2) Ranks have been calculated for this scene before # - We already have bulk ranks. We should check if it has been more than 1 month since we last # calculated ranks. If so, calculate again with the brackets that have come out this month LOG.info('About to check if ranks need updating for {}'.format(scene)) # First, do we have any ranks for this scene already? sql = 'select count(*) from ranks where scene="{}";'.format(scene) res = self.db.exec(sql) count = res[0][0] n = 5 if (scene == 'pro' or scene == 'pro_wiiu') else constants.TOURNAMENTS_PER_RANK if count == 0: LOG.info('Detected that we need to bulk update ranks for {}'.format(scene)) # Alright, we have nothing. Bulk update ranks first_month = bracket_utils.get_first_month(self.db, scene) last_month = bracket_utils.get_last_month(self.db, scene) # Iterate through all tournaments going month by month, and calculate ranks months = bracket_utils.iter_months(first_month, last_month, include_first=False, include_last=True) for month in months: urls, _ = bracket_utils.get_n_tournaments_before_date(self.db, scene, month, n) self.process_ranks(scene, urls, month) else: # Get the date of the last time we calculated ranks sql = "select date from ranks where scene='{}' order by date desc limit 1;".format(scene) res = self.db.exec(sql) last_rankings_date = res[0][0] # Check to see if it's been more than 1 month since we last calculated ranks more_than_one_month = bracket_utils.has_month_passed(last_rankings_date) if more_than_one_month: # Get only the last n tournaments, so it doesn't take too long to process today = datetime.datetime.today().strftime('%Y-%m-%d') msg = 'Detected that we need up update monthly ranks for {}, on {}'.format(scene, today) LOG.info(msg) # We should only ever calculate ranks on the 1st. If today is not the first, log error if not today.split('-')[-1] == '1': LOG.exc('We are calculating ranks today, {}, but it isnt the first'.format(today)) months = bracket_utils.iter_months(last_rankings_date, today, include_first=False, include_last=True) for month in months: # Make sure that we actually have matches during this month # Say we are trying to calculate ranks for 2018-05-01, the player would need to have matches during 2018-04-01, 2018-04-30 prev_date = bracket_utils.get_previous_month(month) brackets_during_month = bracket_utils.get_tournaments_during_month(self.db, scene, prev_date) if len(brackets_during_month) > 0: tweet('Calculating {} ranks for {}'.format(month, scene)) urls, _ = bracket_utils.get_n_tournaments_before_date(self.db, scene, month, n) self.process_ranks(scene, urls, month) else: LOG.info('It has not yet been 1 month since we calculated ranks for {}. Skipping'.format(scene))
cwe-089
{'deleted': [{'line_no': 12, 'char_start': 763, 'char_end': 838, 'line': ' sql = \'select count(*) from ranks where scene="{}";\'.format(scene)\n'}, {'line_no': 13, 'char_start': 838, 'char_end': 870, 'line': ' res = self.db.exec(sql)\n'}, {'line_no': 31, 'char_start': 1777, 'char_end': 1879, 'line': ' sql = "select date from ranks where scene=\'{}\' order by date desc limit 1;".format(scene)\n'}, {'line_no': 32, 'char_start': 1879, 'char_end': 1915, 'line': ' res = self.db.exec(sql)\n'}], 'added': [{'line_no': 12, 'char_start': 763, 'char_end': 829, 'line': ' sql = \'select count(*) from ranks where scene="{scene}";\'\n'}, {'line_no': 13, 'char_start': 829, 'char_end': 861, 'line': " args = {'scene': scene}\n"}, {'line_no': 14, 'char_start': 861, 'char_end': 899, 'line': ' res = self.db.exec(sql, args)\n'}, {'line_no': 32, 'char_start': 1806, 'char_end': 1899, 'line': ' sql = "select date from ranks where scene=\'{scene}\' order by date desc limit 1;"\n'}, {'line_no': 33, 'char_start': 1899, 'char_end': 1935, 'line': " args = {'scene': scene}\n"}, {'line_no': 34, 'char_start': 1935, 'char_end': 1977, 'line': ' res = self.db.exec(sql, args)\n'}]}
{'deleted': [{'char_start': 823, 'char_end': 826, 'chars': '.fo'}, {'char_start': 827, 'char_end': 831, 'chars': 'mat('}, {'char_start': 836, 'char_end': 837, 'chars': ')'}, {'char_start': 1864, 'char_end': 1867, 'chars': '.fo'}, {'char_start': 1868, 'char_end': 1872, 'chars': 'mat('}, {'char_start': 1877, 'char_end': 1878, 'chars': ')'}], 'added': [{'char_start': 819, 'char_end': 824, 'chars': 'scene'}, {'char_start': 828, 'char_end': 837, 'chars': '\n '}, {'char_start': 838, 'char_end': 846, 'chars': "rgs = {'"}, {'char_start': 851, 'char_end': 860, 'chars': "': scene}"}, {'char_start': 891, 'char_end': 897, 'chars': ', args'}, {'char_start': 1862, 'char_end': 1867, 'chars': 'scene'}, {'char_start': 1898, 'char_end': 1911, 'chars': '\n '}, {'char_start': 1912, 'char_end': 1920, 'chars': "rgs = {'"}, {'char_start': 1925, 'char_end': 1934, 'chars': "': scene}"}, {'char_start': 1969, 'char_end': 1975, 'chars': ', args'}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
check_and_update_ranks
def check_and_update_ranks(self, scene): # There are 2 cases here: # 1) Ranks have never been calculated for this scene before # - This means we need to calculate what the ranks were every month of this scenes history # - We should only do this if ranks don't already exist for this scene # 2) Ranks have been calculated for this scene before # - We already have bulk ranks. We should check if it has been more than 1 month since we last # calculated ranks. If so, calculate again with the brackets that have come out this month LOG.info('About to check if ranks need updating for {}'.format(scene)) # First, do we have any ranks for this scene already? sql = 'select count(*) from ranks where scene="{scene}";' args = {'scene': scene} res = self.db.exec(sql, args) count = res[0][0] n = 5 if (scene == 'pro' or scene == 'pro_wiiu') else constants.TOURNAMENTS_PER_RANK if count == 0: LOG.info('Detected that we need to bulk update ranks for {}'.format(scene)) # Alright, we have nothing. Bulk update ranks first_month = bracket_utils.get_first_month(self.db, scene) last_month = bracket_utils.get_last_month(self.db, scene) # Iterate through all tournaments going month by month, and calculate ranks months = bracket_utils.iter_months(first_month, last_month, include_first=False, include_last=True) for month in months: urls, _ = bracket_utils.get_n_tournaments_before_date(self.db, scene, month, n) self.process_ranks(scene, urls, month) else: # Get the date of the last time we calculated ranks sql = "select date from ranks where scene='{scene}' order by date desc limit 1;" args = {'scene': scene} res = self.db.exec(sql, args) last_rankings_date = res[0][0] # Check to see if it's been more than 1 month since we last calculated ranks more_than_one_month = bracket_utils.has_month_passed(last_rankings_date) if more_than_one_month: # Get only the last n tournaments, so it doesn't take too long to process today = datetime.datetime.today().strftime('%Y-%m-%d') msg = 'Detected that we need up update monthly ranks for {}, on {}'.format(scene, today) LOG.info(msg) # We should only ever calculate ranks on the 1st. If today is not the first, log error if not today.split('-')[-1] == '1': LOG.exc('We are calculating ranks today, {}, but it isnt the first'.format(today)) months = bracket_utils.iter_months(last_rankings_date, today, include_first=False, include_last=True) for month in months: # Make sure that we actually have matches during this month # Say we are trying to calculate ranks for 2018-05-01, the player would need to have matches during 2018-04-01, 2018-04-30 prev_date = bracket_utils.get_previous_month(month) brackets_during_month = bracket_utils.get_tournaments_during_month(self.db, scene, prev_date) if len(brackets_during_month) > 0: tweet('Calculating {} ranks for {}'.format(month, scene)) urls, _ = bracket_utils.get_n_tournaments_before_date(self.db, scene, month, n) self.process_ranks(scene, urls, month) else: LOG.info('It has not yet been 1 month since we calculated ranks for {}. Skipping'.format(scene))
cwe-089
{'deleted': [{'line_no': 12, 'char_start': 763, 'char_end': 838, 'line': ' sql = \'select count(*) from ranks where scene="{}";\'.format(scene)\n'}, {'line_no': 13, 'char_start': 838, 'char_end': 870, 'line': ' res = self.db.exec(sql)\n'}, {'line_no': 31, 'char_start': 1777, 'char_end': 1879, 'line': ' sql = "select date from ranks where scene=\'{}\' order by date desc limit 1;".format(scene)\n'}, {'line_no': 32, 'char_start': 1879, 'char_end': 1915, 'line': ' res = self.db.exec(sql)\n'}], 'added': [{'line_no': 12, 'char_start': 763, 'char_end': 829, 'line': ' sql = \'select count(*) from ranks where scene="{scene}";\'\n'}, {'line_no': 13, 'char_start': 829, 'char_end': 861, 'line': " args = {'scene': scene}\n"}, {'line_no': 14, 'char_start': 861, 'char_end': 899, 'line': ' res = self.db.exec(sql, args)\n'}, {'line_no': 32, 'char_start': 1806, 'char_end': 1899, 'line': ' sql = "select date from ranks where scene=\'{scene}\' order by date desc limit 1;"\n'}, {'line_no': 33, 'char_start': 1899, 'char_end': 1935, 'line': " args = {'scene': scene}\n"}, {'line_no': 34, 'char_start': 1935, 'char_end': 1977, 'line': ' res = self.db.exec(sql, args)\n'}]}
{'deleted': [{'char_start': 823, 'char_end': 826, 'chars': '.fo'}, {'char_start': 827, 'char_end': 831, 'chars': 'mat('}, {'char_start': 836, 'char_end': 837, 'chars': ')'}, {'char_start': 1864, 'char_end': 1867, 'chars': '.fo'}, {'char_start': 1868, 'char_end': 1872, 'chars': 'mat('}, {'char_start': 1877, 'char_end': 1878, 'chars': ')'}], 'added': [{'char_start': 819, 'char_end': 824, 'chars': 'scene'}, {'char_start': 828, 'char_end': 837, 'chars': '\n '}, {'char_start': 838, 'char_end': 846, 'chars': "rgs = {'"}, {'char_start': 851, 'char_end': 860, 'chars': "': scene}"}, {'char_start': 891, 'char_end': 897, 'chars': ', args'}, {'char_start': 1862, 'char_end': 1867, 'chars': 'scene'}, {'char_start': 1898, 'char_end': 1911, 'chars': '\n '}, {'char_start': 1912, 'char_end': 1920, 'chars': "rgs = {'"}, {'char_start': 1925, 'char_end': 1934, 'chars': "': scene}"}, {'char_start': 1969, 'char_end': 1975, 'chars': ', args'}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
tag_num_to_tag
def tag_num_to_tag(self, tag_num): ''' Returns tag given tag_num. ''' q = "SELECT tag FROM tags WHERE rowid = '" + str(tag_num) + "'" self.query(q) return self.c.fetchone()[0]
cwe-089
{'deleted': [{'line_no': 4, 'char_start': 83, 'char_end': 155, 'line': ' q = "SELECT tag FROM tags WHERE rowid = \'" + str(tag_num) + "\'"\n'}, {'line_no': 5, 'char_start': 155, 'char_end': 177, 'line': ' self.query(q)\n'}], 'added': [{'line_no': 4, 'char_start': 83, 'char_end': 134, 'line': ' q = "SELECT tag FROM tags WHERE rowid = ?"\n'}, {'line_no': 5, 'char_start': 134, 'char_end': 165, 'line': ' self.query(q, tag_num)\n'}]}
{'deleted': [{'char_start': 131, 'char_end': 153, 'chars': '\'" + str(tag_num) + "\''}], 'added': [{'char_start': 131, 'char_end': 132, 'chars': '?'}, {'char_start': 154, 'char_end': 163, 'chars': ', tag_num'}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
tag_num_to_tag
def tag_num_to_tag(self, tag_num): ''' Returns tag given tag_num. ''' q = "SELECT tag FROM tags WHERE rowid = ?" self.query(q, tag_num) return self.c.fetchone()[0]
cwe-089
{'deleted': [{'line_no': 4, 'char_start': 83, 'char_end': 155, 'line': ' q = "SELECT tag FROM tags WHERE rowid = \'" + str(tag_num) + "\'"\n'}, {'line_no': 5, 'char_start': 155, 'char_end': 177, 'line': ' self.query(q)\n'}], 'added': [{'line_no': 4, 'char_start': 83, 'char_end': 134, 'line': ' q = "SELECT tag FROM tags WHERE rowid = ?"\n'}, {'line_no': 5, 'char_start': 134, 'char_end': 165, 'line': ' self.query(q, tag_num)\n'}]}
{'deleted': [{'char_start': 131, 'char_end': 153, 'chars': '\'" + str(tag_num) + "\''}], 'added': [{'char_start': 131, 'char_end': 132, 'chars': '?'}, {'char_start': 154, 'char_end': 163, 'chars': ', tag_num'}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
get_item
@api.route('/items/<int:item_id>', methods=['GET']) def get_item(item_id): sql = '''SELECT id, name_enus FROM tblDBCItem WHERE id = {} AND auctionable = true;'''.format(item_id) cursor = mysql.connection.cursor() cursor.execute(sql) data = cursor.fetchone() if data: item = {} for tup in zip([column[0] for column in cursor.description], data): item[tup[0]] = tup[1] else: return jsonify({"error": "item not found"}), 404 return jsonify(item)
cwe-089
{'deleted': [{'line_no': 3, 'char_start': 75, 'char_end': 182, 'line': " sql = '''SELECT id, name_enus FROM tblDBCItem WHERE id = {} AND auctionable = true;'''.format(item_id)\n"}, {'line_no': 5, 'char_start': 221, 'char_end': 245, 'line': ' cursor.execute(sql)\n'}], 'added': [{'line_no': 3, 'char_start': 75, 'char_end': 166, 'line': " sql = '''SELECT id, name_enus FROM tblDBCItem WHERE id = %s AND auctionable = true;'''\n"}, {'line_no': 5, 'char_start': 205, 'char_end': 240, 'line': ' cursor.execute(sql, [item_id])\n'}]}
{'deleted': [{'char_start': 136, 'char_end': 138, 'chars': '{}'}, {'char_start': 165, 'char_end': 181, 'chars': '.format(item_id)'}], 'added': [{'char_start': 136, 'char_end': 138, 'chars': '%s'}, {'char_start': 227, 'char_end': 238, 'chars': ', [item_id]'}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
get_item
@api.route('/items/<int:item_id>', methods=['GET']) def get_item(item_id): sql = '''SELECT id, name_enus FROM tblDBCItem WHERE id = %s AND auctionable = true;''' cursor = mysql.connection.cursor() cursor.execute(sql, [item_id]) data = cursor.fetchone() if data: item = {} for tup in zip([column[0] for column in cursor.description], data): item[tup[0]] = tup[1] else: return jsonify({"error": "item not found"}), 404 return jsonify(item)
cwe-089
{'deleted': [{'line_no': 3, 'char_start': 75, 'char_end': 182, 'line': " sql = '''SELECT id, name_enus FROM tblDBCItem WHERE id = {} AND auctionable = true;'''.format(item_id)\n"}, {'line_no': 5, 'char_start': 221, 'char_end': 245, 'line': ' cursor.execute(sql)\n'}], 'added': [{'line_no': 3, 'char_start': 75, 'char_end': 166, 'line': " sql = '''SELECT id, name_enus FROM tblDBCItem WHERE id = %s AND auctionable = true;'''\n"}, {'line_no': 5, 'char_start': 205, 'char_end': 240, 'line': ' cursor.execute(sql, [item_id])\n'}]}
{'deleted': [{'char_start': 136, 'char_end': 138, 'chars': '{}'}, {'char_start': 165, 'char_end': 181, 'chars': '.format(item_id)'}], 'added': [{'char_start': 136, 'char_end': 138, 'chars': '%s'}, {'char_start': 227, 'char_end': 238, 'chars': ', [item_id]'}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
getPostsByPostid
def getPostsByPostid(self,postid): sqlText="select users.name,post.comment from users,post where \ users.userid=post.userid and post.postid=%d"%(postid) result=sql.queryDB(self.conn,sqlText) return result;
cwe-089
{'deleted': [{'line_no': 3, 'char_start': 111, 'char_end': 181, 'line': ' users.userid=post.userid and post.postid=%d"%(postid)\n'}, {'line_no': 4, 'char_start': 181, 'char_end': 227, 'line': ' result=sql.queryDB(self.conn,sqlText)\n'}], 'added': [{'line_no': 3, 'char_start': 111, 'char_end': 172, 'line': ' users.userid=post.userid and post.postid=%s"\n'}, {'line_no': 4, 'char_start': 172, 'char_end': 196, 'line': ' params=[postid]\n'}, {'line_no': 5, 'char_start': 196, 'char_end': 249, 'line': ' result=sql.queryDB(self.conn,sqlText,params)\n'}]}
{'deleted': [{'char_start': 169, 'char_end': 170, 'chars': 'd'}, {'char_start': 171, 'char_end': 173, 'chars': '%('}, {'char_start': 179, 'char_end': 180, 'chars': ')'}], 'added': [{'char_start': 169, 'char_end': 170, 'chars': 's'}, {'char_start': 171, 'char_end': 188, 'chars': '\n params=['}, {'char_start': 194, 'char_end': 195, 'chars': ']'}, {'char_start': 240, 'char_end': 247, 'chars': ',params'}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
getPostsByPostid
def getPostsByPostid(self,postid): sqlText="select users.name,post.comment from users,post where \ users.userid=post.userid and post.postid=%s" params=[postid] result=sql.queryDB(self.conn,sqlText,params) return result;
cwe-089
{'deleted': [{'line_no': 3, 'char_start': 111, 'char_end': 181, 'line': ' users.userid=post.userid and post.postid=%d"%(postid)\n'}, {'line_no': 4, 'char_start': 181, 'char_end': 227, 'line': ' result=sql.queryDB(self.conn,sqlText)\n'}], 'added': [{'line_no': 3, 'char_start': 111, 'char_end': 172, 'line': ' users.userid=post.userid and post.postid=%s"\n'}, {'line_no': 4, 'char_start': 172, 'char_end': 196, 'line': ' params=[postid]\n'}, {'line_no': 5, 'char_start': 196, 'char_end': 249, 'line': ' result=sql.queryDB(self.conn,sqlText,params)\n'}]}
{'deleted': [{'char_start': 169, 'char_end': 170, 'chars': 'd'}, {'char_start': 171, 'char_end': 173, 'chars': '%('}, {'char_start': 179, 'char_end': 180, 'chars': ')'}], 'added': [{'char_start': 169, 'char_end': 170, 'chars': 's'}, {'char_start': 171, 'char_end': 188, 'chars': '\n params=['}, {'char_start': 194, 'char_end': 195, 'chars': ']'}, {'char_start': 240, 'char_end': 247, 'chars': ',params'}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
getFileCacheID
def getFileCacheID(self, pth): """ Returns ID of a cached file on Telegram from DB. None if file doesn't exist or has no cached ID. :param pth: :return: """ command = "SELECT file_id FROM {0} WHERE path='{1}'".format(TABLE_NAME, pth) data = self._run_command(command) try: data = data[0][0] except IndexError: data = None return data
cwe-089
{'deleted': [{'line_no': 7, 'char_start': 168, 'char_end': 247, 'line': '\t\tcommand = "SELECT file_id FROM {0} WHERE path=\'{1}\'".format(TABLE_NAME, pth)\n'}, {'line_no': 8, 'char_start': 247, 'char_end': 283, 'line': '\t\tdata = self._run_command(command)\n'}], 'added': [{'line_no': 7, 'char_start': 168, 'char_end': 239, 'line': '\t\tcommand = "SELECT file_id FROM {0} WHERE path=?;".format(TABLE_NAME)\n'}, {'line_no': 8, 'char_start': 239, 'char_end': 257, 'line': '\t\tparams = (pth,)\n'}, {'line_no': 9, 'char_start': 257, 'char_end': 301, 'line': '\t\tdata = self._run_command(command, params)\n'}]}
{'deleted': [{'char_start': 216, 'char_end': 221, 'chars': "'{1}'"}, {'char_start': 240, 'char_end': 241, 'chars': ','}], 'added': [{'char_start': 216, 'char_end': 218, 'chars': '?;'}, {'char_start': 237, 'char_end': 247, 'chars': ')\n\t\tparams'}, {'char_start': 248, 'char_end': 251, 'chars': '= ('}, {'char_start': 254, 'char_end': 255, 'chars': ','}, {'char_start': 291, 'char_end': 299, 'chars': ', params'}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
getFileCacheID
def getFileCacheID(self, pth): """ Returns ID of a cached file on Telegram from DB. None if file doesn't exist or has no cached ID. :param pth: :return: """ command = "SELECT file_id FROM {0} WHERE path=?;".format(TABLE_NAME) params = (pth,) data = self._run_command(command, params) try: data = data[0][0] except IndexError: data = None return data
cwe-089
{'deleted': [{'line_no': 7, 'char_start': 168, 'char_end': 247, 'line': '\t\tcommand = "SELECT file_id FROM {0} WHERE path=\'{1}\'".format(TABLE_NAME, pth)\n'}, {'line_no': 8, 'char_start': 247, 'char_end': 283, 'line': '\t\tdata = self._run_command(command)\n'}], 'added': [{'line_no': 7, 'char_start': 168, 'char_end': 239, 'line': '\t\tcommand = "SELECT file_id FROM {0} WHERE path=?;".format(TABLE_NAME)\n'}, {'line_no': 8, 'char_start': 239, 'char_end': 257, 'line': '\t\tparams = (pth,)\n'}, {'line_no': 9, 'char_start': 257, 'char_end': 301, 'line': '\t\tdata = self._run_command(command, params)\n'}]}
{'deleted': [{'char_start': 216, 'char_end': 221, 'chars': "'{1}'"}, {'char_start': 240, 'char_end': 241, 'chars': ','}], 'added': [{'char_start': 216, 'char_end': 218, 'chars': '?;'}, {'char_start': 237, 'char_end': 247, 'chars': ')\n\t\tparams'}, {'char_start': 248, 'char_end': 251, 'chars': '= ('}, {'char_start': 254, 'char_end': 255, 'chars': ','}, {'char_start': 291, 'char_end': 299, 'chars': ', params'}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
add_post
def add_post(content): """Add a post to the 'database' with the current timestamp.""" db = psycopg2.connect(database=DBNAME) c = db.cursor() c.execute("insert into posts values('%s')" % content) db.commit() db.close()
cwe-089
{'deleted': [{'line_no': 5, 'char_start': 147, 'char_end': 203, 'line': ' c.execute("insert into posts values(\'%s\')" % content)\n'}], 'added': [{'line_no': 5, 'char_start': 147, 'char_end': 202, 'line': ' c.execute("insert into posts values(%s)",(content,))\n'}]}
{'deleted': [{'char_start': 185, 'char_end': 186, 'chars': "'"}, {'char_start': 188, 'char_end': 189, 'chars': "'"}, {'char_start': 191, 'char_end': 194, 'chars': ' % '}], 'added': [{'char_start': 189, 'char_end': 191, 'chars': ',('}, {'char_start': 198, 'char_end': 200, 'chars': ',)'}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
add_post
def add_post(content): """Add a post to the 'database' with the current timestamp.""" db = psycopg2.connect(database=DBNAME) c = db.cursor() c.execute("insert into posts values(%s)",(content,)) db.commit() db.close()
cwe-089
{'deleted': [{'line_no': 5, 'char_start': 147, 'char_end': 203, 'line': ' c.execute("insert into posts values(\'%s\')" % content)\n'}], 'added': [{'line_no': 5, 'char_start': 147, 'char_end': 202, 'line': ' c.execute("insert into posts values(%s)",(content,))\n'}]}
{'deleted': [{'char_start': 185, 'char_end': 186, 'chars': "'"}, {'char_start': 188, 'char_end': 189, 'chars': "'"}, {'char_start': 191, 'char_end': 194, 'chars': ' % '}], 'added': [{'char_start': 189, 'char_end': 191, 'chars': ',('}, {'char_start': 198, 'char_end': 200, 'chars': ',)'}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
getSubmissionDateFromDatabase
def getSubmissionDateFromDatabase(submission): database = sqlite3.connect('database.db') cursor = database.cursor() return cursor.execute("SELECT Date FROM ChallengeRankings WHERE SubmissionID = '" + str(submission.id) + "'").fetchone()[0] database.close()
cwe-089
{'deleted': [{'line_no': 4, 'char_start': 124, 'char_end': 252, 'line': ' return cursor.execute("SELECT Date FROM ChallengeRankings WHERE SubmissionID = \'" + str(submission.id) + "\'").fetchone()[0]\n'}], 'added': [{'line_no': 4, 'char_start': 124, 'char_end': 247, 'line': ' return cursor.execute("SELECT Date FROM ChallengeRankings WHERE SubmissionID = ?", [str(submission.id)]).fetchone()[0]\n'}]}
{'deleted': [{'char_start': 207, 'char_end': 208, 'chars': "'"}, {'char_start': 209, 'char_end': 211, 'chars': ' +'}, {'char_start': 230, 'char_end': 236, 'chars': ' + "\'"'}], 'added': [{'char_start': 207, 'char_end': 208, 'chars': '?'}, {'char_start': 209, 'char_end': 210, 'chars': ','}, {'char_start': 211, 'char_end': 212, 'chars': '['}, {'char_start': 230, 'char_end': 231, 'chars': ']'}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
getSubmissionDateFromDatabase
def getSubmissionDateFromDatabase(submission): database = sqlite3.connect('database.db') cursor = database.cursor() return cursor.execute("SELECT Date FROM ChallengeRankings WHERE SubmissionID = ?", [str(submission.id)]).fetchone()[0] database.close()
cwe-089
{'deleted': [{'line_no': 4, 'char_start': 124, 'char_end': 252, 'line': ' return cursor.execute("SELECT Date FROM ChallengeRankings WHERE SubmissionID = \'" + str(submission.id) + "\'").fetchone()[0]\n'}], 'added': [{'line_no': 4, 'char_start': 124, 'char_end': 247, 'line': ' return cursor.execute("SELECT Date FROM ChallengeRankings WHERE SubmissionID = ?", [str(submission.id)]).fetchone()[0]\n'}]}
{'deleted': [{'char_start': 207, 'char_end': 208, 'chars': "'"}, {'char_start': 209, 'char_end': 211, 'chars': ' +'}, {'char_start': 230, 'char_end': 236, 'chars': ' + "\'"'}], 'added': [{'char_start': 207, 'char_end': 208, 'chars': '?'}, {'char_start': 209, 'char_end': 210, 'chars': ','}, {'char_start': 211, 'char_end': 212, 'chars': '['}, {'char_start': 230, 'char_end': 231, 'chars': ']'}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
ranks
@endpoints.route("/ranks") def ranks(): if db == None: init() scene = request.args.get('scene', default='austin') date = request.args.get('date') # If no date was provided, pick the date of the latest tournament if date == None: sql = "SELECT distinct date FROM ranks WHERE scene='{}' ORDER BY date DESC LIMIT 1;".format(scene) res = db.exec(sql) date = res[0][0] # Get all the urls that this player has participated in sql = "SELECT * FROM ranks WHERE scene = '{}' and date='{}'".format(scene, date) res = db.exec(sql) # Make a dict out of this data # eg {'christmasmike': 50} cur_ranks = {} for r in res: tag = r[1] rank = r[2] cur_ranks[tag] = rank # Now get the ranks from last month, so we know if these players went up or down y, m, d = date.split('-') prev_date = bracket_utils.get_previous_month(date) # Get all the urls that this player has participated in sql = "SELECT * FROM ranks WHERE scene = '{}' and date='{}'".format(scene, prev_date) res = db.exec(sql) # Make a dict out of this data # eg {'christmasmike': 50} prev_ranks = {} for r in res: tag = r[1] rank = r[2] prev_ranks[tag] = rank return render_template('libraries/html/ranks.html', cur_ranks=cur_ranks, prev_ranks=prev_ranks, scene=scene, date=date)
cwe-089
{'deleted': [{'line_no': 11, 'char_start': 260, 'char_end': 367, 'line': ' sql = "SELECT distinct date FROM ranks WHERE scene=\'{}\' ORDER BY date DESC LIMIT 1;".format(scene)\n'}, {'line_no': 12, 'char_start': 367, 'char_end': 394, 'line': ' res = db.exec(sql)\n'}, {'line_no': 16, 'char_start': 480, 'char_end': 565, 'line': ' sql = "SELECT * FROM ranks WHERE scene = \'{}\' and date=\'{}\'".format(scene, date)\n'}, {'line_no': 17, 'char_start': 565, 'char_end': 588, 'line': ' res = db.exec(sql)\n'}, {'line_no': 33, 'char_start': 994, 'char_end': 1084, 'line': ' sql = "SELECT * FROM ranks WHERE scene = \'{}\' and date=\'{}\'".format(scene, prev_date)\n'}, {'line_no': 34, 'char_start': 1084, 'char_end': 1107, 'line': ' res = db.exec(sql)\n'}], 'added': [{'line_no': 11, 'char_start': 260, 'char_end': 358, 'line': ' sql = "SELECT distinct date FROM ranks WHERE scene=\'{scene}\' ORDER BY date DESC LIMIT 1;"\n'}, {'line_no': 12, 'char_start': 358, 'char_end': 390, 'line': " args = {'scene': scene}\n"}, {'line_no': 13, 'char_start': 390, 'char_end': 423, 'line': ' res = db.exec(sql, args)\n'}, {'line_no': 17, 'char_start': 509, 'char_end': 583, 'line': ' sql = "SELECT * FROM ranks WHERE scene = \'{scene}\' and date=\'{date}\'"\n'}, {'line_no': 18, 'char_start': 583, 'char_end': 625, 'line': " args = {'scene': scene, 'date': date}\n"}, {'line_no': 19, 'char_start': 625, 'char_end': 654, 'line': ' res = db.exec(sql, args)\n'}, {'line_no': 35, 'char_start': 1060, 'char_end': 1134, 'line': ' sql = "SELECT * FROM ranks WHERE scene = \'{scene}\' and date=\'{date}\'"\n'}, {'line_no': 36, 'char_start': 1134, 'char_end': 1181, 'line': " args = {'scene': scene, 'date': prev_date}\n"}, {'line_no': 37, 'char_start': 1181, 'char_end': 1210, 'line': ' res = db.exec(sql, args)\n'}]}
{'deleted': [{'char_start': 352, 'char_end': 355, 'chars': '.fo'}, {'char_start': 356, 'char_end': 360, 'chars': 'mat('}, {'char_start': 365, 'char_end': 366, 'chars': ')'}, {'char_start': 544, 'char_end': 547, 'chars': '.fo'}, {'char_start': 548, 'char_end': 552, 'chars': 'mat('}, {'char_start': 563, 'char_end': 564, 'chars': ')'}, {'char_start': 1058, 'char_end': 1061, 'chars': '.fo'}, {'char_start': 1062, 'char_end': 1066, 'chars': 'mat('}, {'char_start': 1082, 'char_end': 1083, 'chars': ')'}], 'added': [{'char_start': 321, 'char_end': 326, 'chars': 'scene'}, {'char_start': 357, 'char_end': 366, 'chars': '\n '}, {'char_start': 367, 'char_end': 375, 'chars': "rgs = {'"}, {'char_start': 380, 'char_end': 389, 'chars': "': scene}"}, {'char_start': 415, 'char_end': 421, 'chars': ', args'}, {'char_start': 556, 'char_end': 561, 'chars': 'scene'}, {'char_start': 575, 'char_end': 579, 'chars': 'date'}, {'char_start': 582, 'char_end': 587, 'chars': '\n '}, {'char_start': 588, 'char_end': 604, 'chars': "rgs = {'scene': "}, {'char_start': 611, 'char_end': 612, 'chars': "'"}, {'char_start': 616, 'char_end': 624, 'chars': "': date}"}, {'char_start': 646, 'char_end': 652, 'chars': ', args'}, {'char_start': 1107, 'char_end': 1112, 'chars': 'scene'}, {'char_start': 1126, 'char_end': 1130, 'chars': 'date'}, {'char_start': 1133, 'char_end': 1138, 'chars': '\n '}, {'char_start': 1139, 'char_end': 1155, 'chars': "rgs = {'scene': "}, {'char_start': 1162, 'char_end': 1170, 'chars': "'date': "}, {'char_start': 1179, 'char_end': 1180, 'chars': '}'}, {'char_start': 1202, 'char_end': 1208, 'chars': ', args'}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
ranks
@endpoints.route("/ranks") def ranks(): if db == None: init() scene = request.args.get('scene', default='austin') date = request.args.get('date') # If no date was provided, pick the date of the latest tournament if date == None: sql = "SELECT distinct date FROM ranks WHERE scene='{scene}' ORDER BY date DESC LIMIT 1;" args = {'scene': scene} res = db.exec(sql, args) date = res[0][0] # Get all the urls that this player has participated in sql = "SELECT * FROM ranks WHERE scene = '{scene}' and date='{date}'" args = {'scene': scene, 'date': date} res = db.exec(sql, args) # Make a dict out of this data # eg {'christmasmike': 50} cur_ranks = {} for r in res: tag = r[1] rank = r[2] cur_ranks[tag] = rank # Now get the ranks from last month, so we know if these players went up or down y, m, d = date.split('-') prev_date = bracket_utils.get_previous_month(date) # Get all the urls that this player has participated in sql = "SELECT * FROM ranks WHERE scene = '{scene}' and date='{date}'" args = {'scene': scene, 'date': prev_date} res = db.exec(sql, args) # Make a dict out of this data # eg {'christmasmike': 50} prev_ranks = {} for r in res: tag = r[1] rank = r[2] prev_ranks[tag] = rank return render_template('libraries/html/ranks.html', cur_ranks=cur_ranks, prev_ranks=prev_ranks, scene=scene, date=date)
cwe-089
{'deleted': [{'line_no': 11, 'char_start': 260, 'char_end': 367, 'line': ' sql = "SELECT distinct date FROM ranks WHERE scene=\'{}\' ORDER BY date DESC LIMIT 1;".format(scene)\n'}, {'line_no': 12, 'char_start': 367, 'char_end': 394, 'line': ' res = db.exec(sql)\n'}, {'line_no': 16, 'char_start': 480, 'char_end': 565, 'line': ' sql = "SELECT * FROM ranks WHERE scene = \'{}\' and date=\'{}\'".format(scene, date)\n'}, {'line_no': 17, 'char_start': 565, 'char_end': 588, 'line': ' res = db.exec(sql)\n'}, {'line_no': 33, 'char_start': 994, 'char_end': 1084, 'line': ' sql = "SELECT * FROM ranks WHERE scene = \'{}\' and date=\'{}\'".format(scene, prev_date)\n'}, {'line_no': 34, 'char_start': 1084, 'char_end': 1107, 'line': ' res = db.exec(sql)\n'}], 'added': [{'line_no': 11, 'char_start': 260, 'char_end': 358, 'line': ' sql = "SELECT distinct date FROM ranks WHERE scene=\'{scene}\' ORDER BY date DESC LIMIT 1;"\n'}, {'line_no': 12, 'char_start': 358, 'char_end': 390, 'line': " args = {'scene': scene}\n"}, {'line_no': 13, 'char_start': 390, 'char_end': 423, 'line': ' res = db.exec(sql, args)\n'}, {'line_no': 17, 'char_start': 509, 'char_end': 583, 'line': ' sql = "SELECT * FROM ranks WHERE scene = \'{scene}\' and date=\'{date}\'"\n'}, {'line_no': 18, 'char_start': 583, 'char_end': 625, 'line': " args = {'scene': scene, 'date': date}\n"}, {'line_no': 19, 'char_start': 625, 'char_end': 654, 'line': ' res = db.exec(sql, args)\n'}, {'line_no': 35, 'char_start': 1060, 'char_end': 1134, 'line': ' sql = "SELECT * FROM ranks WHERE scene = \'{scene}\' and date=\'{date}\'"\n'}, {'line_no': 36, 'char_start': 1134, 'char_end': 1181, 'line': " args = {'scene': scene, 'date': prev_date}\n"}, {'line_no': 37, 'char_start': 1181, 'char_end': 1210, 'line': ' res = db.exec(sql, args)\n'}]}
{'deleted': [{'char_start': 352, 'char_end': 355, 'chars': '.fo'}, {'char_start': 356, 'char_end': 360, 'chars': 'mat('}, {'char_start': 365, 'char_end': 366, 'chars': ')'}, {'char_start': 544, 'char_end': 547, 'chars': '.fo'}, {'char_start': 548, 'char_end': 552, 'chars': 'mat('}, {'char_start': 563, 'char_end': 564, 'chars': ')'}, {'char_start': 1058, 'char_end': 1061, 'chars': '.fo'}, {'char_start': 1062, 'char_end': 1066, 'chars': 'mat('}, {'char_start': 1082, 'char_end': 1083, 'chars': ')'}], 'added': [{'char_start': 321, 'char_end': 326, 'chars': 'scene'}, {'char_start': 357, 'char_end': 366, 'chars': '\n '}, {'char_start': 367, 'char_end': 375, 'chars': "rgs = {'"}, {'char_start': 380, 'char_end': 389, 'chars': "': scene}"}, {'char_start': 415, 'char_end': 421, 'chars': ', args'}, {'char_start': 556, 'char_end': 561, 'chars': 'scene'}, {'char_start': 575, 'char_end': 579, 'chars': 'date'}, {'char_start': 582, 'char_end': 587, 'chars': '\n '}, {'char_start': 588, 'char_end': 604, 'chars': "rgs = {'scene': "}, {'char_start': 611, 'char_end': 612, 'chars': "'"}, {'char_start': 616, 'char_end': 624, 'chars': "': date}"}, {'char_start': 646, 'char_end': 652, 'chars': ', args'}, {'char_start': 1107, 'char_end': 1112, 'chars': 'scene'}, {'char_start': 1126, 'char_end': 1130, 'chars': 'date'}, {'char_start': 1133, 'char_end': 1138, 'chars': '\n '}, {'char_start': 1139, 'char_end': 1155, 'chars': "rgs = {'scene': "}, {'char_start': 1162, 'char_end': 1170, 'chars': "'date': "}, {'char_start': 1179, 'char_end': 1180, 'chars': '}'}, {'char_start': 1202, 'char_end': 1208, 'chars': ', args'}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
set_language
def set_language(self, lang): """ Update language of user in the User object and in the database :param lang: string with language tag like "en-US" :return: None """ log.debug('Updating info about user %s language ' 'in memory & database...', self) self.language = lang query = ("UPDATE users " f"SET language='{self.language}' " f"WHERE chat_id='{self.chat_id}'") try: db.add(query) except DatabaseError: log.error("Can't add new language of %s to the database", self) else: log.debug('Language updated.')
cwe-089
{'deleted': [{'line_no': 13, 'char_start': 383, 'char_end': 435, 'line': ' f"SET language=\'{self.language}\' "\n'}, {'line_no': 14, 'char_start': 435, 'char_end': 487, 'line': ' f"WHERE chat_id=\'{self.chat_id}\'")\n'}, {'line_no': 17, 'char_start': 501, 'char_end': 527, 'line': ' db.add(query)\n'}], 'added': [{'line_no': 13, 'char_start': 383, 'char_end': 420, 'line': ' f"SET language=%s "\n'}, {'line_no': 14, 'char_start': 420, 'char_end': 458, 'line': ' f"WHERE chat_id=%s")\n'}, {'line_no': 16, 'char_start': 459, 'char_end': 508, 'line': ' parameters = self.language, self.chat_id\n'}, {'line_no': 18, 'char_start': 521, 'char_end': 559, 'line': ' db.add(query, parameters)\n'}]}
{'deleted': [{'char_start': 415, 'char_end': 417, 'chars': "'{"}, {'char_start': 418, 'char_end': 432, 'chars': "elf.language}'"}, {'char_start': 468, 'char_end': 470, 'chars': "'{"}, {'char_start': 482, 'char_end': 487, 'chars': '}\'")\n'}], 'added': [{'char_start': 415, 'char_end': 416, 'chars': '%'}, {'char_start': 453, 'char_end': 495, 'chars': '%s")\n\n parameters = self.language, '}, {'char_start': 545, 'char_end': 557, 'chars': ', parameters'}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
set_language
def set_language(self, lang): """ Update language of user in the User object and in the database :param lang: string with language tag like "en-US" :return: None """ log.debug('Updating info about user %s language ' 'in memory & database...', self) self.language = lang query = ("UPDATE users " f"SET language=%s " f"WHERE chat_id=%s") parameters = self.language, self.chat_id try: db.add(query, parameters) except DatabaseError: log.error("Can't add new language of %s to the database", self) else: log.debug('Language updated.')
cwe-089
{'deleted': [{'line_no': 13, 'char_start': 383, 'char_end': 435, 'line': ' f"SET language=\'{self.language}\' "\n'}, {'line_no': 14, 'char_start': 435, 'char_end': 487, 'line': ' f"WHERE chat_id=\'{self.chat_id}\'")\n'}, {'line_no': 17, 'char_start': 501, 'char_end': 527, 'line': ' db.add(query)\n'}], 'added': [{'line_no': 13, 'char_start': 383, 'char_end': 420, 'line': ' f"SET language=%s "\n'}, {'line_no': 14, 'char_start': 420, 'char_end': 458, 'line': ' f"WHERE chat_id=%s")\n'}, {'line_no': 16, 'char_start': 459, 'char_end': 508, 'line': ' parameters = self.language, self.chat_id\n'}, {'line_no': 18, 'char_start': 521, 'char_end': 559, 'line': ' db.add(query, parameters)\n'}]}
{'deleted': [{'char_start': 415, 'char_end': 417, 'chars': "'{"}, {'char_start': 418, 'char_end': 432, 'chars': "elf.language}'"}, {'char_start': 468, 'char_end': 470, 'chars': "'{"}, {'char_start': 482, 'char_end': 487, 'chars': '}\'")\n'}], 'added': [{'char_start': 415, 'char_end': 416, 'chars': '%'}, {'char_start': 453, 'char_end': 495, 'chars': '%s")\n\n parameters = self.language, '}, {'char_start': 545, 'char_end': 557, 'chars': ', parameters'}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
tid_num_to_tag_nums
def tid_num_to_tag_nums(self, tid_num): ''' Returns list of the associated tag_nums to the given tid_num. ''' q = "SELECT tag FROM tid_tag WHERE tid = '" + str(tid_num) + "'" self.query(q) return [i[0] for i in self.c.fetchall()]
cwe-089
{'deleted': [{'line_no': 4, 'char_start': 123, 'char_end': 196, 'line': ' q = "SELECT tag FROM tid_tag WHERE tid = \'" + str(tid_num) + "\'"\n'}, {'line_no': 5, 'char_start': 196, 'char_end': 218, 'line': ' self.query(q)\n'}], 'added': [{'line_no': 4, 'char_start': 123, 'char_end': 175, 'line': ' q = "SELECT tag FROM tid_tag WHERE tid = ?"\n'}, {'line_no': 5, 'char_start': 175, 'char_end': 206, 'line': ' self.query(q, tid_num)\n'}]}
{'deleted': [{'char_start': 172, 'char_end': 194, 'chars': '\'" + str(tid_num) + "\''}], 'added': [{'char_start': 172, 'char_end': 173, 'chars': '?'}, {'char_start': 195, 'char_end': 204, 'chars': ', tid_num'}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
tid_num_to_tag_nums
def tid_num_to_tag_nums(self, tid_num): ''' Returns list of the associated tag_nums to the given tid_num. ''' q = "SELECT tag FROM tid_tag WHERE tid = ?" self.query(q, tid_num) return [i[0] for i in self.c.fetchall()]
cwe-089
{'deleted': [{'line_no': 4, 'char_start': 123, 'char_end': 196, 'line': ' q = "SELECT tag FROM tid_tag WHERE tid = \'" + str(tid_num) + "\'"\n'}, {'line_no': 5, 'char_start': 196, 'char_end': 218, 'line': ' self.query(q)\n'}], 'added': [{'line_no': 4, 'char_start': 123, 'char_end': 175, 'line': ' q = "SELECT tag FROM tid_tag WHERE tid = ?"\n'}, {'line_no': 5, 'char_start': 175, 'char_end': 206, 'line': ' self.query(q, tid_num)\n'}]}
{'deleted': [{'char_start': 172, 'char_end': 194, 'chars': '\'" + str(tid_num) + "\''}], 'added': [{'char_start': 172, 'char_end': 173, 'chars': '?'}, {'char_start': 195, 'char_end': 204, 'chars': ', tid_num'}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
summary
@app.route('/summary', methods=['GET']) def summary(): if 'username' in session: conn = mysql.connect() cursor = conn.cursor() #select the maximum score from the results table cursor.execute("SELECT courseConcentration FROM results WHERE total = (SELECT MAX(total) FROM (SELECT * FROM results WHERE courseId > 4) Temp) and courseId > 4 and emailAccount='" + session['username'] + "'"); courseConcentration = cursor.fetchone() return render_template('summary.html', courseConcentration = courseConcentration[0]) return redirect(url_for('login'))
cwe-089
{'deleted': [{'line_no': 9, 'char_start': 185, 'char_end': 397, 'line': '\t\tcursor.execute("SELECT courseConcentration FROM results WHERE total = (SELECT MAX(total) FROM (SELECT * FROM results WHERE courseId > 4) Temp) and courseId > 4 and emailAccount=\'" + session[\'username\'] + "\'");\n'}], 'added': [{'line_no': 9, 'char_start': 185, 'char_end': 393, 'line': '\t\tcursor.execute("SELECT courseConcentration FROM results WHERE total = (SELECT MAX(total) FROM (SELECT * FROM results WHERE courseId > 4) Temp) and courseId > 4 and emailAccount=%s", (session[\'username\']));\n'}]}
{'deleted': [{'char_start': 364, 'char_end': 365, 'chars': "'"}, {'char_start': 367, 'char_end': 369, 'chars': '+ '}, {'char_start': 388, 'char_end': 394, 'chars': ' + "\'"'}], 'added': [{'char_start': 364, 'char_end': 366, 'chars': '%s'}, {'char_start': 367, 'char_end': 368, 'chars': ','}, {'char_start': 369, 'char_end': 370, 'chars': '('}, {'char_start': 389, 'char_end': 390, 'chars': ')'}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
summary
@app.route('/summary', methods=['GET']) def summary(): if 'username' in session: conn = mysql.connect() cursor = conn.cursor() #select the maximum score from the results table cursor.execute("SELECT courseConcentration FROM results WHERE total = (SELECT MAX(total) FROM (SELECT * FROM results WHERE courseId > 4) Temp) and courseId > 4 and emailAccount=%s", (session['username'])); courseConcentration = cursor.fetchone() return render_template('summary.html', courseConcentration = courseConcentration[0]) return redirect(url_for('login'))
cwe-089
{'deleted': [{'line_no': 9, 'char_start': 185, 'char_end': 397, 'line': '\t\tcursor.execute("SELECT courseConcentration FROM results WHERE total = (SELECT MAX(total) FROM (SELECT * FROM results WHERE courseId > 4) Temp) and courseId > 4 and emailAccount=\'" + session[\'username\'] + "\'");\n'}], 'added': [{'line_no': 9, 'char_start': 185, 'char_end': 393, 'line': '\t\tcursor.execute("SELECT courseConcentration FROM results WHERE total = (SELECT MAX(total) FROM (SELECT * FROM results WHERE courseId > 4) Temp) and courseId > 4 and emailAccount=%s", (session[\'username\']));\n'}]}
{'deleted': [{'char_start': 364, 'char_end': 365, 'chars': "'"}, {'char_start': 367, 'char_end': 369, 'chars': '+ '}, {'char_start': 388, 'char_end': 394, 'chars': ' + "\'"'}], 'added': [{'char_start': 364, 'char_end': 366, 'chars': '%s'}, {'char_start': 367, 'char_end': 368, 'chars': ','}, {'char_start': 369, 'char_end': 370, 'chars': '('}, {'char_start': 389, 'char_end': 390, 'chars': ')'}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
add_post
def add_post(content): """Add a post to the 'database' with the current timestamp.""" conn = psycopg2.connect("dbname=forum") cursor = conn.cursor() cursor.execute("insert into posts values ('%s')" % content) conn.commit() conn.close()
cwe-089
{'deleted': [{'line_no': 5, 'char_start': 155, 'char_end': 217, 'line': ' cursor.execute("insert into posts values (\'%s\')" % content)\n'}], 'added': [{'line_no': 5, 'char_start': 155, 'char_end': 176, 'line': ' one_post = content\n'}, {'line_no': 6, 'char_start': 176, 'char_end': 239, 'line': ' cursor.execute("insert into posts values (%s)", (one_post,))\n'}]}
{'deleted': [{'char_start': 199, 'char_end': 200, 'chars': "'"}, {'char_start': 202, 'char_end': 203, 'chars': "'"}, {'char_start': 205, 'char_end': 207, 'chars': ' %'}, {'char_start': 208, 'char_end': 209, 'chars': 'c'}, {'char_start': 211, 'char_end': 212, 'chars': 't'}, {'char_start': 213, 'char_end': 214, 'chars': 'n'}], 'added': [{'char_start': 157, 'char_end': 178, 'chars': 'one_post = content\n '}, {'char_start': 224, 'char_end': 225, 'chars': ','}, {'char_start': 226, 'char_end': 227, 'chars': '('}, {'char_start': 230, 'char_end': 234, 'chars': '_pos'}, {'char_start': 235, 'char_end': 237, 'chars': ',)'}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
add_post
def add_post(content): """Add a post to the 'database' with the current timestamp.""" conn = psycopg2.connect("dbname=forum") cursor = conn.cursor() one_post = content cursor.execute("insert into posts values (%s)", (one_post,)) conn.commit() conn.close()
cwe-089
{'deleted': [{'line_no': 5, 'char_start': 155, 'char_end': 217, 'line': ' cursor.execute("insert into posts values (\'%s\')" % content)\n'}], 'added': [{'line_no': 5, 'char_start': 155, 'char_end': 176, 'line': ' one_post = content\n'}, {'line_no': 6, 'char_start': 176, 'char_end': 239, 'line': ' cursor.execute("insert into posts values (%s)", (one_post,))\n'}]}
{'deleted': [{'char_start': 199, 'char_end': 200, 'chars': "'"}, {'char_start': 202, 'char_end': 203, 'chars': "'"}, {'char_start': 205, 'char_end': 207, 'chars': ' %'}, {'char_start': 208, 'char_end': 209, 'chars': 'c'}, {'char_start': 211, 'char_end': 212, 'chars': 't'}, {'char_start': 213, 'char_end': 214, 'chars': 'n'}], 'added': [{'char_start': 157, 'char_end': 178, 'chars': 'one_post = content\n '}, {'char_start': 224, 'char_end': 225, 'chars': ','}, {'char_start': 226, 'char_end': 227, 'chars': '('}, {'char_start': 230, 'char_end': 234, 'chars': '_pos'}, {'char_start': 235, 'char_end': 237, 'chars': ',)'}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
delete_playlist
def delete_playlist(id, db): db.execute("DELETE FROM playlist where id={id};".format(id=id))
cwe-089
{'deleted': [{'line_no': 2, 'char_start': 29, 'char_end': 96, 'line': ' db.execute("DELETE FROM playlist where id={id};".format(id=id))\n'}], 'added': [{'line_no': 2, 'char_start': 29, 'char_end': 87, 'line': ' db.execute("DELETE FROM playlist where id=%s;", (id,))\n'}]}
{'deleted': [{'char_start': 75, 'char_end': 79, 'chars': '{id}'}, {'char_start': 81, 'char_end': 88, 'chars': '.format'}, {'char_start': 91, 'char_end': 94, 'chars': '=id'}], 'added': [{'char_start': 75, 'char_end': 77, 'chars': '%s'}, {'char_start': 79, 'char_end': 81, 'chars': ', '}, {'char_start': 84, 'char_end': 85, 'chars': ','}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
delete_playlist
def delete_playlist(id, db): db.execute("DELETE FROM playlist where id=%s;", (id,))
cwe-089
{'deleted': [{'line_no': 2, 'char_start': 29, 'char_end': 96, 'line': ' db.execute("DELETE FROM playlist where id={id};".format(id=id))\n'}], 'added': [{'line_no': 2, 'char_start': 29, 'char_end': 87, 'line': ' db.execute("DELETE FROM playlist where id=%s;", (id,))\n'}]}
{'deleted': [{'char_start': 75, 'char_end': 79, 'chars': '{id}'}, {'char_start': 81, 'char_end': 88, 'chars': '.format'}, {'char_start': 91, 'char_end': 94, 'chars': '=id'}], 'added': [{'char_start': 75, 'char_end': 77, 'chars': '%s'}, {'char_start': 79, 'char_end': 81, 'chars': ', '}, {'char_start': 84, 'char_end': 85, 'chars': ','}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
writeToDb
def writeToDb(self, url): try: self.cursor.execute("INSERT INTO queue (url, visited) VALUES ('{}', '0');".format(url)) self.db.commit() except Exception as e: print(e)
cwe-089
{'deleted': [{'line_no': 3, 'char_start': 43, 'char_end': 143, 'line': ' self.cursor.execute("INSERT INTO queue (url, visited) VALUES (\'{}\', \'0\');".format(url))\n'}], 'added': [{'line_no': 3, 'char_start': 43, 'char_end': 133, 'line': ' self.cursor.execute("INSERT INTO queue (url, visited) VALUES (?, \'0\');", url)\n'}]}
{'deleted': [{'char_start': 117, 'char_end': 121, 'chars': "'{}'"}, {'char_start': 129, 'char_end': 137, 'chars': '.format('}, {'char_start': 140, 'char_end': 141, 'chars': ')'}], 'added': [{'char_start': 117, 'char_end': 118, 'chars': '?'}, {'char_start': 126, 'char_end': 128, 'chars': ', '}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
writeToDb
def writeToDb(self, url): try: self.cursor.execute("INSERT INTO queue (url, visited) VALUES (?, '0');", url) self.db.commit() except Exception as e: print(e)
cwe-089
{'deleted': [{'line_no': 3, 'char_start': 43, 'char_end': 143, 'line': ' self.cursor.execute("INSERT INTO queue (url, visited) VALUES (\'{}\', \'0\');".format(url))\n'}], 'added': [{'line_no': 3, 'char_start': 43, 'char_end': 133, 'line': ' self.cursor.execute("INSERT INTO queue (url, visited) VALUES (?, \'0\');", url)\n'}]}
{'deleted': [{'char_start': 117, 'char_end': 121, 'chars': "'{}'"}, {'char_start': 129, 'char_end': 137, 'chars': '.format('}, {'char_start': 140, 'char_end': 141, 'chars': ')'}], 'added': [{'char_start': 117, 'char_end': 118, 'chars': '?'}, {'char_start': 126, 'char_end': 128, 'chars': ', '}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
send_message
@frappe.whitelist(allow_guest=True) def send_message(subject="Website Query", message="", sender="", status="Open"): from frappe.www.contact import send_message as website_send_message lead = customer = None website_send_message(subject, message, sender) customer = frappe.db.sql("""select distinct dl.link_name from `tabDynamic Link` dl left join `tabContact` c on dl.parent=c.name where dl.link_doctype='Customer' and c.email_id='{email_id}'""".format(email_id=sender)) if not customer: lead = frappe.db.get_value('Lead', dict(email_id=sender)) if not lead: new_lead = frappe.get_doc(dict( doctype='Lead', email_id = sender, lead_name = sender.split('@')[0].title() )).insert(ignore_permissions=True) opportunity = frappe.get_doc(dict( doctype ='Opportunity', enquiry_from = 'Customer' if customer else 'Lead', status = 'Open', title = subject, contact_email = sender, to_discuss = message )) if customer: opportunity.customer = customer[0][0] elif lead: opportunity.lead = lead else: opportunity.lead = new_lead.name opportunity.insert(ignore_permissions=True) comm = frappe.get_doc({ "doctype":"Communication", "subject": subject, "content": message, "sender": sender, "sent_or_received": "Received", 'reference_doctype': 'Opportunity', 'reference_name': opportunity.name }) comm.insert(ignore_permissions=True) return "okay"
cwe-089
{'deleted': [{'line_no': 10, 'char_start': 424, 'char_end': 482, 'line': '\t\tand c.email_id=\'{email_id}\'""".format(email_id=sender))\n'}], 'added': [{'line_no': 10, 'char_start': 424, 'char_end': 458, 'line': '\t\tand c.email_id = %s""", sender)\n'}]}
{'deleted': [{'char_start': 441, 'char_end': 453, 'chars': "'{email_id}'"}, {'char_start': 456, 'char_end': 473, 'chars': '.format(email_id='}, {'char_start': 479, 'char_end': 480, 'chars': ')'}], 'added': [{'char_start': 440, 'char_end': 441, 'chars': ' '}, {'char_start': 442, 'char_end': 445, 'chars': ' %s'}, {'char_start': 448, 'char_end': 450, 'chars': ', '}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
send_message
@frappe.whitelist(allow_guest=True) def send_message(subject="Website Query", message="", sender="", status="Open"): from frappe.www.contact import send_message as website_send_message lead = customer = None website_send_message(subject, message, sender) customer = frappe.db.sql("""select distinct dl.link_name from `tabDynamic Link` dl left join `tabContact` c on dl.parent=c.name where dl.link_doctype='Customer' and c.email_id = %s""", sender) if not customer: lead = frappe.db.get_value('Lead', dict(email_id=sender)) if not lead: new_lead = frappe.get_doc(dict( doctype='Lead', email_id = sender, lead_name = sender.split('@')[0].title() )).insert(ignore_permissions=True) opportunity = frappe.get_doc(dict( doctype ='Opportunity', enquiry_from = 'Customer' if customer else 'Lead', status = 'Open', title = subject, contact_email = sender, to_discuss = message )) if customer: opportunity.customer = customer[0][0] elif lead: opportunity.lead = lead else: opportunity.lead = new_lead.name opportunity.insert(ignore_permissions=True) comm = frappe.get_doc({ "doctype":"Communication", "subject": subject, "content": message, "sender": sender, "sent_or_received": "Received", 'reference_doctype': 'Opportunity', 'reference_name': opportunity.name }) comm.insert(ignore_permissions=True) return "okay"
cwe-089
{'deleted': [{'line_no': 10, 'char_start': 424, 'char_end': 482, 'line': '\t\tand c.email_id=\'{email_id}\'""".format(email_id=sender))\n'}], 'added': [{'line_no': 10, 'char_start': 424, 'char_end': 458, 'line': '\t\tand c.email_id = %s""", sender)\n'}]}
{'deleted': [{'char_start': 441, 'char_end': 453, 'chars': "'{email_id}'"}, {'char_start': 456, 'char_end': 473, 'chars': '.format(email_id='}, {'char_start': 479, 'char_end': 480, 'chars': ')'}], 'added': [{'char_start': 440, 'char_end': 441, 'chars': ' '}, {'char_start': 442, 'char_end': 445, 'chars': ' %s'}, {'char_start': 448, 'char_end': 450, 'chars': ', '}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
delete
@jwt_required def delete(self, email): """ Deletes admin with the corresponding email """ return database_utilities.execute_query(f"""delete from admins where email = '{email}'""")
cwe-089
{'deleted': [{'line_no': 4, 'char_start': 106, 'char_end': 204, 'line': ' return database_utilities.execute_query(f"""delete from admins where email = \'{email}\'""")\n'}], 'added': [{'line_no': 4, 'char_start': 106, 'char_end': 208, 'line': ' return database_utilities.execute_query(f"""delete from admins where email = %s""", (email, ))'}]}
{'deleted': [{'char_start': 191, 'char_end': 193, 'chars': "'{"}, {'char_start': 198, 'char_end': 203, 'chars': '}\'"""'}], 'added': [{'char_start': 191, 'char_end': 199, 'chars': '%s""", ('}, {'char_start': 204, 'char_end': 207, 'chars': ', )'}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
delete
@jwt_required def delete(self, email): """ Deletes admin with the corresponding email """ return database_utilities.execute_query(f"""delete from admins where email = %s""", (email, ))
cwe-089
{'deleted': [{'line_no': 4, 'char_start': 106, 'char_end': 204, 'line': ' return database_utilities.execute_query(f"""delete from admins where email = \'{email}\'""")\n'}], 'added': [{'line_no': 4, 'char_start': 106, 'char_end': 208, 'line': ' return database_utilities.execute_query(f"""delete from admins where email = %s""", (email, ))'}]}
{'deleted': [{'char_start': 191, 'char_end': 193, 'chars': "'{"}, {'char_start': 198, 'char_end': 203, 'chars': '}\'"""'}], 'added': [{'char_start': 191, 'char_end': 199, 'chars': '%s""", ('}, {'char_start': 204, 'char_end': 207, 'chars': ', )'}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
delete_playlists_videos
def delete_playlists_videos(playlist_id, db): db.execute("DELETE FROM video where playlist_id={playlist_id};".format( playlist_id=playlist_id))
cwe-089
{'deleted': [{'line_no': 2, 'char_start': 46, 'char_end': 122, 'line': ' db.execute("DELETE FROM video where playlist_id={playlist_id};".format(\n'}, {'line_no': 3, 'char_start': 122, 'char_end': 155, 'line': ' playlist_id=playlist_id))\n'}], 'added': [{'line_no': 2, 'char_start': 46, 'char_end': 119, 'line': ' db.execute("DELETE FROM video where playlist_id=%s;", (playlist_id,))\n'}]}
{'deleted': [{'char_start': 98, 'char_end': 105, 'chars': '{playli'}, {'char_start': 106, 'char_end': 111, 'chars': 't_id}'}, {'char_start': 113, 'char_end': 127, 'chars': '.format(\n '}, {'char_start': 128, 'char_end': 142, 'chars': ' playlist_id='}], 'added': [{'char_start': 98, 'char_end': 99, 'chars': '%'}, {'char_start': 102, 'char_end': 104, 'chars': ', '}, {'char_start': 116, 'char_end': 117, 'chars': ','}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
delete_playlists_videos
def delete_playlists_videos(playlist_id, db): db.execute("DELETE FROM video where playlist_id=%s;", (playlist_id,))
cwe-089
{'deleted': [{'line_no': 2, 'char_start': 46, 'char_end': 122, 'line': ' db.execute("DELETE FROM video where playlist_id={playlist_id};".format(\n'}, {'line_no': 3, 'char_start': 122, 'char_end': 155, 'line': ' playlist_id=playlist_id))\n'}], 'added': [{'line_no': 2, 'char_start': 46, 'char_end': 119, 'line': ' db.execute("DELETE FROM video where playlist_id=%s;", (playlist_id,))\n'}]}
{'deleted': [{'char_start': 98, 'char_end': 105, 'chars': '{playli'}, {'char_start': 106, 'char_end': 111, 'chars': 't_id}'}, {'char_start': 113, 'char_end': 127, 'chars': '.format(\n '}, {'char_start': 128, 'char_end': 142, 'chars': ' playlist_id='}], 'added': [{'char_start': 98, 'char_end': 99, 'chars': '%'}, {'char_start': 102, 'char_end': 104, 'chars': ', '}, {'char_start': 116, 'char_end': 117, 'chars': ','}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
upsert_mapped_projects
@staticmethod def upsert_mapped_projects(user_id: int, project_id: int): """ Adds projects to mapped_projects if it doesn't exist """ sql = "select * from users where id = {0} and projects_mapped @> '{{{1}}}'".format(user_id, project_id) result = db.engine.execute(sql) if result.rowcount > 0: return # User has previously mapped this project so return sql = '''update users set projects_mapped = array_append(projects_mapped, {0}) where id = {1}'''.format(project_id, user_id) db.engine.execute(sql)
cwe-089
{'deleted': [{'line_no': 4, 'char_start': 150, 'char_end': 262, 'line': ' sql = "select * from users where id = {0} and projects_mapped @> \'{{{1}}}\'".format(user_id, project_id)\n'}, {'line_no': 5, 'char_start': 262, 'char_end': 302, 'line': ' result = db.engine.execute(sql)\n'}, {'line_no': 11, 'char_start': 438, 'char_end': 515, 'line': ' set projects_mapped = array_append(projects_mapped, {0})\n'}, {'line_no': 12, 'char_start': 515, 'char_end': 579, 'line': " where id = {1}'''.format(project_id, user_id)\n"}, {'line_no': 14, 'char_start': 580, 'char_end': 610, 'line': ' db.engine.execute(sql)\n'}], 'added': [{'line_no': 4, 'char_start': 150, 'char_end': 247, 'line': ' sql = "select * from users where id = :user_id and projects_mapped @> \'{{:project_id}}\'"\n'}, {'line_no': 5, 'char_start': 247, 'char_end': 333, 'line': ' result = db.engine.execute(text(sql), user_id=user_id, project_id=project_id)\n'}, {'line_no': 11, 'char_start': 469, 'char_end': 554, 'line': ' set projects_mapped = array_append(projects_mapped, :project_id)\n'}, {'line_no': 12, 'char_start': 554, 'char_end': 595, 'line': " where id = :user_id'''\n"}, {'line_no': 14, 'char_start': 596, 'char_end': 672, 'line': ' db.engine.execute(text(sql), project_id=project_id, user_id=user_id)\n'}]}
{'deleted': [{'char_start': 196, 'char_end': 199, 'chars': '{0}'}, {'char_start': 226, 'char_end': 250, 'chars': '{1}}}\'".format(user_id, '}, {'char_start': 260, 'char_end': 261, 'chars': ')'}, {'char_start': 510, 'char_end': 513, 'chars': '{0}'}, {'char_start': 544, 'char_end': 570, 'chars': "{1}'''.format(project_id, "}, {'char_start': 577, 'char_end': 578, 'chars': ')'}], 'added': [{'char_start': 196, 'char_end': 204, 'chars': ':user_id'}, {'char_start': 231, 'char_end': 232, 'chars': ':'}, {'char_start': 242, 'char_end': 246, 'chars': '}}\'"'}, {'char_start': 282, 'char_end': 287, 'chars': 'text('}, {'char_start': 290, 'char_end': 331, 'chars': '), user_id=user_id, project_id=project_id'}, {'char_start': 541, 'char_end': 552, 'chars': ':project_id'}, {'char_start': 583, 'char_end': 584, 'chars': ':'}, {'char_start': 591, 'char_end': 594, 'chars': "'''"}, {'char_start': 622, 'char_end': 627, 'chars': 'text('}, {'char_start': 631, 'char_end': 672, 'chars': ', project_id=project_id, user_id=user_id)'}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
upsert_mapped_projects
@staticmethod def upsert_mapped_projects(user_id: int, project_id: int): """ Adds projects to mapped_projects if it doesn't exist """ sql = "select * from users where id = :user_id and projects_mapped @> '{{:project_id}}'" result = db.engine.execute(text(sql), user_id=user_id, project_id=project_id) if result.rowcount > 0: return # User has previously mapped this project so return sql = '''update users set projects_mapped = array_append(projects_mapped, :project_id) where id = :user_id''' db.engine.execute(text(sql), project_id=project_id, user_id=user_id)
cwe-089
{'deleted': [{'line_no': 4, 'char_start': 150, 'char_end': 262, 'line': ' sql = "select * from users where id = {0} and projects_mapped @> \'{{{1}}}\'".format(user_id, project_id)\n'}, {'line_no': 5, 'char_start': 262, 'char_end': 302, 'line': ' result = db.engine.execute(sql)\n'}, {'line_no': 11, 'char_start': 438, 'char_end': 515, 'line': ' set projects_mapped = array_append(projects_mapped, {0})\n'}, {'line_no': 12, 'char_start': 515, 'char_end': 579, 'line': " where id = {1}'''.format(project_id, user_id)\n"}, {'line_no': 14, 'char_start': 580, 'char_end': 610, 'line': ' db.engine.execute(sql)\n'}], 'added': [{'line_no': 4, 'char_start': 150, 'char_end': 247, 'line': ' sql = "select * from users where id = :user_id and projects_mapped @> \'{{:project_id}}\'"\n'}, {'line_no': 5, 'char_start': 247, 'char_end': 333, 'line': ' result = db.engine.execute(text(sql), user_id=user_id, project_id=project_id)\n'}, {'line_no': 11, 'char_start': 469, 'char_end': 554, 'line': ' set projects_mapped = array_append(projects_mapped, :project_id)\n'}, {'line_no': 12, 'char_start': 554, 'char_end': 595, 'line': " where id = :user_id'''\n"}, {'line_no': 14, 'char_start': 596, 'char_end': 672, 'line': ' db.engine.execute(text(sql), project_id=project_id, user_id=user_id)\n'}]}
{'deleted': [{'char_start': 196, 'char_end': 199, 'chars': '{0}'}, {'char_start': 226, 'char_end': 250, 'chars': '{1}}}\'".format(user_id, '}, {'char_start': 260, 'char_end': 261, 'chars': ')'}, {'char_start': 510, 'char_end': 513, 'chars': '{0}'}, {'char_start': 544, 'char_end': 570, 'chars': "{1}'''.format(project_id, "}, {'char_start': 577, 'char_end': 578, 'chars': ')'}], 'added': [{'char_start': 196, 'char_end': 204, 'chars': ':user_id'}, {'char_start': 231, 'char_end': 232, 'chars': ':'}, {'char_start': 242, 'char_end': 246, 'chars': '}}\'"'}, {'char_start': 282, 'char_end': 287, 'chars': 'text('}, {'char_start': 290, 'char_end': 331, 'chars': '), user_id=user_id, project_id=project_id'}, {'char_start': 541, 'char_end': 552, 'chars': ':project_id'}, {'char_start': 583, 'char_end': 584, 'chars': ':'}, {'char_start': 591, 'char_end': 594, 'chars': "'''"}, {'char_start': 622, 'char_end': 627, 'chars': 'text('}, {'char_start': 631, 'char_end': 672, 'chars': ', project_id=project_id, user_id=user_id)'}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
get_first_ranked_month
def get_first_ranked_month(db, scene, player): sql = "select date from ranks where scene='{}' and player='{}' order by date limit 1;".format(scene, player) res = db.exec(sql) date = res[0][0] return date
cwe-089
{'deleted': [{'line_no': 2, 'char_start': 47, 'char_end': 160, 'line': ' sql = "select date from ranks where scene=\'{}\' and player=\'{}\' order by date limit 1;".format(scene, player)\n'}, {'line_no': 3, 'char_start': 160, 'char_end': 183, 'line': ' res = db.exec(sql)\n'}], 'added': [{'line_no': 2, 'char_start': 47, 'char_end': 149, 'line': ' sql = "select date from ranks where scene=\'{scene}\' and player=\'{player}\' order by date limit 1;"\n'}, {'line_no': 3, 'char_start': 149, 'char_end': 195, 'line': " args = {'scene': scene, 'player': player}\n"}, {'line_no': 4, 'char_start': 195, 'char_end': 224, 'line': ' res = db.exec(sql, args)\n'}]}
{'deleted': [{'char_start': 137, 'char_end': 140, 'chars': '.fo'}, {'char_start': 141, 'char_end': 145, 'chars': 'mat('}, {'char_start': 158, 'char_end': 159, 'chars': ')'}], 'added': [{'char_start': 95, 'char_end': 100, 'chars': 'scene'}, {'char_start': 116, 'char_end': 122, 'chars': 'player'}, {'char_start': 148, 'char_end': 153, 'chars': '\n '}, {'char_start': 154, 'char_end': 170, 'chars': "rgs = {'scene': "}, {'char_start': 177, 'char_end': 178, 'chars': "'"}, {'char_start': 184, 'char_end': 194, 'chars': "': player}"}, {'char_start': 216, 'char_end': 222, 'chars': ', args'}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
get_first_ranked_month
def get_first_ranked_month(db, scene, player): sql = "select date from ranks where scene='{scene}' and player='{player}' order by date limit 1;" args = {'scene': scene, 'player': player} res = db.exec(sql, args) date = res[0][0] return date
cwe-089
{'deleted': [{'line_no': 2, 'char_start': 47, 'char_end': 160, 'line': ' sql = "select date from ranks where scene=\'{}\' and player=\'{}\' order by date limit 1;".format(scene, player)\n'}, {'line_no': 3, 'char_start': 160, 'char_end': 183, 'line': ' res = db.exec(sql)\n'}], 'added': [{'line_no': 2, 'char_start': 47, 'char_end': 149, 'line': ' sql = "select date from ranks where scene=\'{scene}\' and player=\'{player}\' order by date limit 1;"\n'}, {'line_no': 3, 'char_start': 149, 'char_end': 195, 'line': " args = {'scene': scene, 'player': player}\n"}, {'line_no': 4, 'char_start': 195, 'char_end': 224, 'line': ' res = db.exec(sql, args)\n'}]}
{'deleted': [{'char_start': 137, 'char_end': 140, 'chars': '.fo'}, {'char_start': 141, 'char_end': 145, 'chars': 'mat('}, {'char_start': 158, 'char_end': 159, 'chars': ')'}], 'added': [{'char_start': 95, 'char_end': 100, 'chars': 'scene'}, {'char_start': 116, 'char_end': 122, 'chars': 'player'}, {'char_start': 148, 'char_end': 153, 'chars': '\n '}, {'char_start': 154, 'char_end': 170, 'chars': "rgs = {'scene': "}, {'char_start': 177, 'char_end': 178, 'chars': "'"}, {'char_start': 184, 'char_end': 194, 'chars': "': player}"}, {'char_start': 216, 'char_end': 222, 'chars': ', args'}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
openPoll
@hook.command(adminonly=True) def openPoll(question, reply=None, db=None): """Creates a new poll.""" if not db_ready: db_init(db) try: active = db.execute("SELECT pollID FROM polls WHERE active = 1").fetchone()[0] if active: reply("There already is an open poll.") return except: db.execute("INSERT INTO polls (question, active) VALUES ('{}', 1)".format(question)) reply("Opened new poll: {}".format(question)) #reply("Poll opened!") return
cwe-089
{'deleted': [{'line_no': 11, 'char_start': 337, 'char_end': 430, 'line': ' db.execute("INSERT INTO polls (question, active) VALUES (\'{}\', 1)".format(question))\n'}], 'added': [{'line_no': 11, 'char_start': 337, 'char_end': 423, 'line': ' db.execute("INSERT INTO polls (question, active) VALUES (?, 1)", (question,))\n'}]}
{'deleted': [{'char_start': 402, 'char_end': 406, 'chars': "'{}'"}, {'char_start': 411, 'char_end': 418, 'chars': '.format'}], 'added': [{'char_start': 402, 'char_end': 403, 'chars': '?'}, {'char_start': 408, 'char_end': 410, 'chars': ', '}, {'char_start': 419, 'char_end': 420, 'chars': ','}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
openPoll
@hook.command(adminonly=True) def openPoll(question, reply=None, db=None): """Creates a new poll.""" if not db_ready: db_init(db) try: active = db.execute("SELECT pollID FROM polls WHERE active = 1").fetchone()[0] if active: reply("There already is an open poll.") return except: db.execute("INSERT INTO polls (question, active) VALUES (?, 1)", (question,)) reply("Opened new poll: {}".format(question)) #reply("Poll opened!") return
cwe-089
{'deleted': [{'line_no': 11, 'char_start': 337, 'char_end': 430, 'line': ' db.execute("INSERT INTO polls (question, active) VALUES (\'{}\', 1)".format(question))\n'}], 'added': [{'line_no': 11, 'char_start': 337, 'char_end': 423, 'line': ' db.execute("INSERT INTO polls (question, active) VALUES (?, 1)", (question,))\n'}]}
{'deleted': [{'char_start': 402, 'char_end': 406, 'chars': "'{}'"}, {'char_start': 411, 'char_end': 418, 'chars': '.format'}], 'added': [{'char_start': 402, 'char_end': 403, 'chars': '?'}, {'char_start': 408, 'char_end': 410, 'chars': ', '}, {'char_start': 419, 'char_end': 420, 'chars': ','}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
__init__.view_grocery_list
def view_grocery_list(): print("grocery== list") groceryListFrame = Frame(self) groceryListFrame.rowconfigure(0, weight=1) groceryListFrame.columnconfigure(0, weight=1) groceryListFrame.rowconfigure(1, weight=3) groceryListFrame.columnconfigure(1, weight=3) groceryListFrame.pack() menu.pack_forget() groceryButton.pack_forget() label.configure(text="Grocery List") i = 0 database_file = "meal_planner.db" item_array = [] with sqlite3.connect(database_file) as conn: cursor = conn.cursor() tableName = "ingredients_" + str(weekNumber) selection = cursor.execute("""SELECT * FROM """ + tableName) for result in [selection]: for row in result.fetchall(): print(row) for ingredient in row: print(ingredient) item_array.append(str(ingredient).split()) i = i +1 Label(groceryListFrame, text=ingredient, font=MEDIUM_FONT, justify=LEFT).grid(row=i, column=0, sticky="w") j = 0 for item in item_array: print(item) returnButton = Button(menuFrame, text = "Return to Menu", highlightbackground="#e7e7e7", command=lambda: [groceryListFrame.pack_forget(), menu.pack(), returnButton.pack_forget(), label.configure(text="Meal Planer"), groceryButton.pack(side=RIGHT)]) returnButton.pack(side=RIGHT)
cwe-089
{'deleted': [{'line_no': 20, 'char_start': 745, 'char_end': 822, 'line': ' selection = cursor.execute("""SELECT * FROM """ + tableName)\n'}], 'added': [{'line_no': 20, 'char_start': 745, 'char_end': 827, 'line': ' selection = cursor.execute("""SELECT * FROM ?;""", (tableName, ))\n'}]}
{'deleted': [{'char_start': 809, 'char_end': 811, 'chars': '+ '}], 'added': [{'char_start': 805, 'char_end': 807, 'chars': '?;'}, {'char_start': 810, 'char_end': 811, 'chars': ','}, {'char_start': 812, 'char_end': 813, 'chars': '('}, {'char_start': 822, 'char_end': 825, 'chars': ', )'}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
__init__.view_grocery_list
def view_grocery_list(): print("grocery== list") groceryListFrame = Frame(self) groceryListFrame.rowconfigure(0, weight=1) groceryListFrame.columnconfigure(0, weight=1) groceryListFrame.rowconfigure(1, weight=3) groceryListFrame.columnconfigure(1, weight=3) groceryListFrame.pack() menu.pack_forget() groceryButton.pack_forget() label.configure(text="Grocery List") i = 0 database_file = "meal_planner.db" item_array = [] with sqlite3.connect(database_file) as conn: cursor = conn.cursor() tableName = "ingredients_" + str(weekNumber) selection = cursor.execute("""SELECT * FROM ?;""", (tableName, )) for result in [selection]: for row in result.fetchall(): print(row) for ingredient in row: print(ingredient) item_array.append(str(ingredient).split()) i = i +1 Label(groceryListFrame, text=ingredient, font=MEDIUM_FONT, justify=LEFT).grid(row=i, column=0, sticky="w") j = 0 for item in item_array: print(item) returnButton = Button(menuFrame, text = "Return to Menu", highlightbackground="#e7e7e7", command=lambda: [groceryListFrame.pack_forget(), menu.pack(), returnButton.pack_forget(), label.configure(text="Meal Planer"), groceryButton.pack(side=RIGHT)]) returnButton.pack(side=RIGHT)
cwe-089
{'deleted': [{'line_no': 20, 'char_start': 745, 'char_end': 822, 'line': ' selection = cursor.execute("""SELECT * FROM """ + tableName)\n'}], 'added': [{'line_no': 20, 'char_start': 745, 'char_end': 827, 'line': ' selection = cursor.execute("""SELECT * FROM ?;""", (tableName, ))\n'}]}
{'deleted': [{'char_start': 809, 'char_end': 811, 'chars': '+ '}], 'added': [{'char_start': 805, 'char_end': 807, 'chars': '?;'}, {'char_start': 810, 'char_end': 811, 'chars': ','}, {'char_start': 812, 'char_end': 813, 'chars': '('}, {'char_start': 822, 'char_end': 825, 'chars': ', )'}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
view_page_record
@app.route('/<page_name>/history/record') def view_page_record(page_name): content_id = request.args.get('id') query = db.query("select page_content.content, page_content.timestamp from page, page_content where page.id = page_content.page_id and page_content.id = '%s'" % content_id) page_record = query.namedresult()[0] return render_template( 'page_record.html', page_name = page_name, page_record = page_record )
cwe-089
{'deleted': [{'line_no': 4, 'char_start': 115, 'char_end': 292, 'line': ' query = db.query("select page_content.content, page_content.timestamp from page, page_content where page.id = page_content.page_id and page_content.id = \'%s\'" % content_id)\n'}], 'added': [{'line_no': 4, 'char_start': 115, 'char_end': 289, 'line': ' query = db.query("select page_content.content, page_content.timestamp from page, page_content where page.id = page_content.page_id and page_content.id = $1", content_id)\n'}]}
{'deleted': [{'char_start': 272, 'char_end': 276, 'chars': "'%s'"}, {'char_start': 277, 'char_end': 279, 'chars': ' %'}], 'added': [{'char_start': 272, 'char_end': 274, 'chars': '$1'}, {'char_start': 275, 'char_end': 276, 'chars': ','}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
view_page_record
@app.route('/<page_name>/history/record') def view_page_record(page_name): content_id = request.args.get('id') query = db.query("select page_content.content, page_content.timestamp from page, page_content where page.id = page_content.page_id and page_content.id = $1", content_id) page_record = query.namedresult()[0] return render_template( 'page_record.html', page_name = page_name, page_record = page_record )
cwe-089
{'deleted': [{'line_no': 4, 'char_start': 115, 'char_end': 292, 'line': ' query = db.query("select page_content.content, page_content.timestamp from page, page_content where page.id = page_content.page_id and page_content.id = \'%s\'" % content_id)\n'}], 'added': [{'line_no': 4, 'char_start': 115, 'char_end': 289, 'line': ' query = db.query("select page_content.content, page_content.timestamp from page, page_content where page.id = page_content.page_id and page_content.id = $1", content_id)\n'}]}
{'deleted': [{'char_start': 272, 'char_end': 276, 'chars': "'%s'"}, {'char_start': 277, 'char_end': 279, 'chars': ' %'}], 'added': [{'char_start': 272, 'char_end': 274, 'chars': '$1'}, {'char_start': 275, 'char_end': 276, 'chars': ','}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
update_inverter
def update_inverter(self, inverter_serial, ts, status, etoday, etotal): query = ''' UPDATE Inverters SET TimeStamp='%s', Status='%s', eToday='%s', eTotal='%s' WHERE Serial='%s'; ''' % (ts, status, etoday, etotal, inverter_serial) self.c.execute(query)
cwe-089
{'deleted': [{'line_no': 5, 'char_start': 146, 'char_end': 179, 'line': " TimeStamp='%s', \n"}, {'line_no': 6, 'char_start': 179, 'char_end': 209, 'line': " Status='%s', \n"}, {'line_no': 7, 'char_start': 209, 'char_end': 238, 'line': " eToday='%s',\n"}, {'line_no': 8, 'char_start': 238, 'char_end': 266, 'line': " eTotal='%s'\n"}, {'line_no': 9, 'char_start': 266, 'char_end': 297, 'line': " WHERE Serial='%s';\n"}, {'line_no': 10, 'char_start': 297, 'char_end': 357, 'line': " ''' % (ts, status, etoday, etotal, inverter_serial)\n"}, {'line_no': 11, 'char_start': 357, 'char_end': 386, 'line': ' self.c.execute(query)\n'}], 'added': [{'line_no': 5, 'char_start': 146, 'char_end': 176, 'line': ' TimeStamp=?, \n'}, {'line_no': 6, 'char_start': 176, 'char_end': 203, 'line': ' Status=?, \n'}, {'line_no': 7, 'char_start': 203, 'char_end': 229, 'line': ' eToday=?,\n'}, {'line_no': 8, 'char_start': 229, 'char_end': 254, 'line': ' eTotal=?\n'}, {'line_no': 9, 'char_start': 254, 'char_end': 282, 'line': ' WHERE Serial=?;\n'}, {'line_no': 10, 'char_start': 282, 'char_end': 294, 'line': " '''\n"}, {'line_no': 11, 'char_start': 294, 'char_end': 370, 'line': ' self.c.execute(query, (ts, status, etoday, etotal, inverter_serial))\n'}]}
{'deleted': [{'char_start': 172, 'char_end': 176, 'chars': "'%s'"}, {'char_start': 202, 'char_end': 206, 'chars': "'%s'"}, {'char_start': 232, 'char_end': 236, 'chars': "'%s'"}, {'char_start': 261, 'char_end': 265, 'chars': "'%s'"}, {'char_start': 291, 'char_end': 295, 'chars': "'%s'"}, {'char_start': 309, 'char_end': 310, 'chars': '%'}, {'char_start': 356, 'char_end': 385, 'chars': '\n self.c.execute(query'}], 'added': [{'char_start': 172, 'char_end': 173, 'chars': '?'}, {'char_start': 199, 'char_end': 200, 'chars': '?'}, {'char_start': 226, 'char_end': 227, 'chars': '?'}, {'char_start': 252, 'char_end': 253, 'chars': '?'}, {'char_start': 279, 'char_end': 280, 'chars': '?'}, {'char_start': 293, 'char_end': 300, 'chars': '\n '}, {'char_start': 301, 'char_end': 323, 'chars': ' self.c.execute(query,'}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
update_inverter
def update_inverter(self, inverter_serial, ts, status, etoday, etotal): query = ''' UPDATE Inverters SET TimeStamp=?, Status=?, eToday=?, eTotal=? WHERE Serial=?; ''' self.c.execute(query, (ts, status, etoday, etotal, inverter_serial))
cwe-089
{'deleted': [{'line_no': 5, 'char_start': 146, 'char_end': 179, 'line': " TimeStamp='%s', \n"}, {'line_no': 6, 'char_start': 179, 'char_end': 209, 'line': " Status='%s', \n"}, {'line_no': 7, 'char_start': 209, 'char_end': 238, 'line': " eToday='%s',\n"}, {'line_no': 8, 'char_start': 238, 'char_end': 266, 'line': " eTotal='%s'\n"}, {'line_no': 9, 'char_start': 266, 'char_end': 297, 'line': " WHERE Serial='%s';\n"}, {'line_no': 10, 'char_start': 297, 'char_end': 357, 'line': " ''' % (ts, status, etoday, etotal, inverter_serial)\n"}, {'line_no': 11, 'char_start': 357, 'char_end': 386, 'line': ' self.c.execute(query)\n'}], 'added': [{'line_no': 5, 'char_start': 146, 'char_end': 176, 'line': ' TimeStamp=?, \n'}, {'line_no': 6, 'char_start': 176, 'char_end': 203, 'line': ' Status=?, \n'}, {'line_no': 7, 'char_start': 203, 'char_end': 229, 'line': ' eToday=?,\n'}, {'line_no': 8, 'char_start': 229, 'char_end': 254, 'line': ' eTotal=?\n'}, {'line_no': 9, 'char_start': 254, 'char_end': 282, 'line': ' WHERE Serial=?;\n'}, {'line_no': 10, 'char_start': 282, 'char_end': 294, 'line': " '''\n"}, {'line_no': 11, 'char_start': 294, 'char_end': 370, 'line': ' self.c.execute(query, (ts, status, etoday, etotal, inverter_serial))\n'}]}
{'deleted': [{'char_start': 172, 'char_end': 176, 'chars': "'%s'"}, {'char_start': 202, 'char_end': 206, 'chars': "'%s'"}, {'char_start': 232, 'char_end': 236, 'chars': "'%s'"}, {'char_start': 261, 'char_end': 265, 'chars': "'%s'"}, {'char_start': 291, 'char_end': 295, 'chars': "'%s'"}, {'char_start': 309, 'char_end': 310, 'chars': '%'}, {'char_start': 356, 'char_end': 385, 'chars': '\n self.c.execute(query'}], 'added': [{'char_start': 172, 'char_end': 173, 'chars': '?'}, {'char_start': 199, 'char_end': 200, 'chars': '?'}, {'char_start': 226, 'char_end': 227, 'chars': '?'}, {'char_start': 252, 'char_end': 253, 'chars': '?'}, {'char_start': 279, 'char_end': 280, 'chars': '?'}, {'char_start': 293, 'char_end': 300, 'chars': '\n '}, {'char_start': 301, 'char_end': 323, 'chars': ' self.c.execute(query,'}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
insert
def insert(key, value): connection = psycopg2.connect(host=config['HOST'], port=config['PORT'], database=config['NAME'], user=config['USER'], password=config['PASSWORD']) cur = connection.cursor() try: cur.execute("insert into reply_map values('{}', '{}')".format(key, value)) connection.commit() except: pass
cwe-089
{'deleted': [{'line_no': 5, 'char_start': 214, 'char_end': 297, 'line': ' cur.execute("insert into reply_map values(\'{}\', \'{}\')".format(key, value))\n'}], 'added': [{'line_no': 5, 'char_start': 214, 'char_end': 286, 'line': ' cur.execute("insert into reply_map values(?, ?)", (key, value))\n'}]}
{'deleted': [{'char_start': 264, 'char_end': 268, 'chars': "'{}'"}, {'char_start': 270, 'char_end': 274, 'chars': "'{}'"}, {'char_start': 276, 'char_end': 283, 'chars': '.format'}], 'added': [{'char_start': 264, 'char_end': 265, 'chars': '?'}, {'char_start': 267, 'char_end': 268, 'chars': '?'}, {'char_start': 270, 'char_end': 272, 'chars': ', '}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
insert
def insert(key, value): connection = psycopg2.connect(host=config['HOST'], port=config['PORT'], database=config['NAME'], user=config['USER'], password=config['PASSWORD']) cur = connection.cursor() try: cur.execute("insert into reply_map values(?, ?)", (key, value)) connection.commit() except: pass
cwe-089
{'deleted': [{'line_no': 5, 'char_start': 214, 'char_end': 297, 'line': ' cur.execute("insert into reply_map values(\'{}\', \'{}\')".format(key, value))\n'}], 'added': [{'line_no': 5, 'char_start': 214, 'char_end': 286, 'line': ' cur.execute("insert into reply_map values(?, ?)", (key, value))\n'}]}
{'deleted': [{'char_start': 264, 'char_end': 268, 'chars': "'{}'"}, {'char_start': 270, 'char_end': 274, 'chars': "'{}'"}, {'char_start': 276, 'char_end': 283, 'chars': '.format'}], 'added': [{'char_start': 264, 'char_end': 265, 'chars': '?'}, {'char_start': 267, 'char_end': 268, 'chars': '?'}, {'char_start': 270, 'char_end': 272, 'chars': ', '}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
save_failure_transaction
def save_failure_transaction(self, user_id, project_id, money): self.cursor.execute("insert into transactions (project_id,user_id, money, timestamp, state) values (%s, %s, %s, now(), 'failed' )" % (project_id, user_id, money)) self.db.commit()
cwe-089
{'deleted': [{'line_no': 2, 'char_start': 68, 'char_end': 239, 'line': ' self.cursor.execute("insert into transactions (project_id,user_id, money, timestamp, state) values (%s, %s, %s, now(), \'failed\' )" % (project_id, user_id, money))\n'}], 'added': [{'line_no': 2, 'char_start': 68, 'char_end': 186, 'line': ' self.cursor.execute("insert into transactions (project_id,user_id, money, timestamp, state) values (%s, %s, "\n'}, {'line_no': 3, 'char_start': 186, 'char_end': 269, 'line': ' "%s, now(), \'failed\' )", (project_id, user_id, money))\n'}]}
{'deleted': [{'char_start': 206, 'char_end': 208, 'chars': ' %'}], 'added': [{'char_start': 184, 'char_end': 215, 'chars': '"\n "'}, {'char_start': 237, 'char_end': 238, 'chars': ','}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
save_failure_transaction
def save_failure_transaction(self, user_id, project_id, money): self.cursor.execute("insert into transactions (project_id,user_id, money, timestamp, state) values (%s, %s, " "%s, now(), 'failed' )", (project_id, user_id, money)) self.db.commit()
cwe-089
{'deleted': [{'line_no': 2, 'char_start': 68, 'char_end': 239, 'line': ' self.cursor.execute("insert into transactions (project_id,user_id, money, timestamp, state) values (%s, %s, %s, now(), \'failed\' )" % (project_id, user_id, money))\n'}], 'added': [{'line_no': 2, 'char_start': 68, 'char_end': 186, 'line': ' self.cursor.execute("insert into transactions (project_id,user_id, money, timestamp, state) values (%s, %s, "\n'}, {'line_no': 3, 'char_start': 186, 'char_end': 269, 'line': ' "%s, now(), \'failed\' )", (project_id, user_id, money))\n'}]}
{'deleted': [{'char_start': 206, 'char_end': 208, 'chars': ' %'}], 'added': [{'char_start': 184, 'char_end': 215, 'chars': '"\n "'}, {'char_start': 237, 'char_end': 238, 'chars': ','}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
test_process_as_form
@unpack def test_process_as_form(self, job_number, dcn_key, was_prev_matched, was_prev_closed, was_prev_tracked): email_obj = { 'sender' : "Alex Roy <Alex.Roy@dilfo.com>", 'subject' : "DO NOT MODIFY MESSAGE BELOW - JUST HIT `SEND`", 'date' : "Tue, 7 May 2019 17:34:17 +0000", 'content' : ( f"job_number={job_number}&title=TEST_ENTRY&city=Ottawa&" f"address=2562+Del+Zotto+Ave.%2C+Ottawa%2C+Ontario&" f"contractor=GCN&engineer=Goodkey&owner=Douglas+Stalker&" f"quality=2&cc_email=&link_to_cert={dcn_key}\r\n" ) } # set-up new entries in db, if necessary fake_dilfo_insert = """ INSERT INTO df_dilfo (job_number, receiver_email, closed) VALUES ({}, 'alex.roy616@gmail.com', {}) """ fake_match_insert = """ INSERT INTO df_matched (job_number, verifier, ground_truth) VALUES ({}, 'alex.roy616@gmail.com', {}) """ with create_connection() as conn: if was_prev_closed or was_prev_tracked: conn.cursor().execute(fake_dilfo_insert.format(job_number, was_prev_closed)) if was_prev_matched: if was_prev_closed: conn.cursor().execute(fake_match_insert.format(job_number, 1)) else: conn.cursor().execute(fake_match_insert.format(job_number, 0)) with create_connection() as conn: df_dilfo_pre = pd.read_sql(f"SELECT * FROM df_dilfo WHERE job_number={job_number}", conn) df_matched_pre = pd.read_sql(f"SELECT * FROM df_matched WHERE job_number={job_number}", conn) process_as_form(email_obj) # make assertions about db now that reply has been processed with create_connection() as conn: df_dilfo_post = pd.read_sql(f"SELECT * FROM df_dilfo WHERE job_number={job_number}", conn) df_matched_post = pd.read_sql(f"SELECT * FROM df_matched WHERE job_number={job_number}", conn) self.assertEqual(len(df_dilfo_post), 1) self.assertEqual(bool(df_dilfo_post.iloc[0].closed), bool(was_prev_closed or dcn_key)) self.assertEqual(any(df_matched_post.ground_truth), bool(was_prev_closed or dcn_key)) self.assertEqual(len(df_matched_pre) + bool(dcn_key and not(was_prev_closed)), len(df_matched_post)) self.assertEqual(list(df_matched_pre.columns), list(df_matched_post.columns)) self.assertEqual(list(df_dilfo_pre.columns), list(df_dilfo_post.columns))
cwe-089
{'deleted': [{'line_no': 18, 'char_start': 823, 'char_end': 876, 'line': " VALUES ({}, 'alex.roy616@gmail.com', {})\n"}, {'line_no': 22, 'char_start': 992, 'char_end': 1045, 'line': " VALUES ({}, 'alex.roy616@gmail.com', {})\n"}, {'line_no': 26, 'char_start': 1151, 'char_end': 1244, 'line': ' conn.cursor().execute(fake_dilfo_insert.format(job_number, was_prev_closed))\n'}, {'line_no': 29, 'char_start': 1313, 'char_end': 1396, 'line': ' conn.cursor().execute(fake_match_insert.format(job_number, 1))\n'}, {'line_no': 31, 'char_start': 1418, 'char_end': 1501, 'line': ' conn.cursor().execute(fake_match_insert.format(job_number, 0))\n'}, {'line_no': 33, 'char_start': 1543, 'char_end': 1645, 'line': ' df_dilfo_pre = pd.read_sql(f"SELECT * FROM df_dilfo WHERE job_number={job_number}", conn)\n'}, {'line_no': 34, 'char_start': 1645, 'char_end': 1751, 'line': ' df_matched_pre = pd.read_sql(f"SELECT * FROM df_matched WHERE job_number={job_number}", conn)\n'}, {'line_no': 38, 'char_start': 1897, 'char_end': 2000, 'line': ' df_dilfo_post = pd.read_sql(f"SELECT * FROM df_dilfo WHERE job_number={job_number}", conn)\n'}, {'line_no': 39, 'char_start': 2000, 'char_end': 2107, 'line': ' df_matched_post = pd.read_sql(f"SELECT * FROM df_matched WHERE job_number={job_number}", conn)\n'}], 'added': [{'line_no': 18, 'char_start': 823, 'char_end': 874, 'line': " VALUES (?, 'alex.roy616@gmail.com', ?)\n"}, {'line_no': 22, 'char_start': 990, 'char_end': 1041, 'line': " VALUES (?, 'alex.roy616@gmail.com', ?)\n"}, {'line_no': 26, 'char_start': 1147, 'char_end': 1235, 'line': ' conn.cursor().execute(fake_dilfo_insert, [job_number, was_prev_closed])\n'}, {'line_no': 29, 'char_start': 1304, 'char_end': 1382, 'line': ' conn.cursor().execute(fake_match_insert, [job_number, 1])\n'}, {'line_no': 31, 'char_start': 1404, 'char_end': 1482, 'line': ' conn.cursor().execute(fake_match_insert, [job_number, 0])\n'}, {'line_no': 33, 'char_start': 1524, 'char_end': 1635, 'line': ' df_dilfo_pre = pd.read_sql("SELECT * FROM df_dilfo WHERE job_number=?", conn, params=[job_number])\n'}, {'line_no': 34, 'char_start': 1635, 'char_end': 1750, 'line': ' df_matched_pre = pd.read_sql("SELECT * FROM df_matched WHERE job_number=?", conn, params=[job_number])\n'}, {'line_no': 38, 'char_start': 1896, 'char_end': 2008, 'line': ' df_dilfo_post = pd.read_sql("SELECT * FROM df_dilfo WHERE job_number=?", conn, params=[job_number])\n'}, {'line_no': 39, 'char_start': 2008, 'char_end': 2124, 'line': ' df_matched_post = pd.read_sql("SELECT * FROM df_matched WHERE job_number=?", conn, params=[job_number])\n'}]}
{'deleted': [{'char_start': 843, 'char_end': 845, 'chars': '{}'}, {'char_start': 872, 'char_end': 874, 'chars': '{}'}, {'char_start': 1012, 'char_end': 1014, 'chars': '{}'}, {'char_start': 1041, 'char_end': 1043, 'chars': '{}'}, {'char_start': 1206, 'char_end': 1214, 'chars': '.format('}, {'char_start': 1241, 'char_end': 1242, 'chars': ')'}, {'char_start': 1372, 'char_end': 1380, 'chars': '.format('}, {'char_start': 1393, 'char_end': 1394, 'chars': ')'}, {'char_start': 1477, 'char_end': 1485, 'chars': '.format('}, {'char_start': 1498, 'char_end': 1499, 'chars': ')'}, {'char_start': 1582, 'char_end': 1583, 'chars': 'f'}, {'char_start': 1624, 'char_end': 1625, 'chars': '{'}, {'char_start': 1635, 'char_end': 1643, 'chars': '}", conn'}, {'char_start': 1686, 'char_end': 1687, 'chars': 'f'}, {'char_start': 1730, 'char_end': 1731, 'chars': '{'}, {'char_start': 1741, 'char_end': 1749, 'chars': '}", conn'}, {'char_start': 1937, 'char_end': 1938, 'chars': 'f'}, {'char_start': 1979, 'char_end': 1980, 'chars': '{'}, {'char_start': 1990, 'char_end': 1998, 'chars': '}", conn'}, {'char_start': 2042, 'char_end': 2043, 'chars': 'f'}, {'char_start': 2086, 'char_end': 2087, 'chars': '{'}, {'char_start': 2097, 'char_end': 2105, 'chars': '}", conn'}], 'added': [{'char_start': 843, 'char_end': 844, 'chars': '?'}, {'char_start': 871, 'char_end': 872, 'chars': '?'}, {'char_start': 1010, 'char_end': 1011, 'chars': '?'}, {'char_start': 1038, 'char_end': 1039, 'chars': '?'}, {'char_start': 1202, 'char_end': 1205, 'chars': ', ['}, {'char_start': 1232, 'char_end': 1233, 'chars': ']'}, {'char_start': 1363, 'char_end': 1366, 'chars': ', ['}, {'char_start': 1379, 'char_end': 1380, 'chars': ']'}, {'char_start': 1463, 'char_end': 1466, 'chars': ', ['}, {'char_start': 1479, 'char_end': 1480, 'chars': ']'}, {'char_start': 1604, 'char_end': 1622, 'chars': '?", conn, params=['}, {'char_start': 1632, 'char_end': 1633, 'chars': ']'}, {'char_start': 1719, 'char_end': 1737, 'chars': '?", conn, params=['}, {'char_start': 1747, 'char_end': 1748, 'chars': ']'}, {'char_start': 1977, 'char_end': 1995, 'chars': '?", conn, params=['}, {'char_start': 2005, 'char_end': 2006, 'chars': ']'}, {'char_start': 2093, 'char_end': 2111, 'chars': '?", conn, params=['}, {'char_start': 2121, 'char_end': 2122, 'chars': ']'}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
test_process_as_form
@unpack def test_process_as_form(self, job_number, dcn_key, was_prev_matched, was_prev_closed, was_prev_tracked): email_obj = { 'sender' : "Alex Roy <Alex.Roy@dilfo.com>", 'subject' : "DO NOT MODIFY MESSAGE BELOW - JUST HIT `SEND`", 'date' : "Tue, 7 May 2019 17:34:17 +0000", 'content' : ( f"job_number={job_number}&title=TEST_ENTRY&city=Ottawa&" f"address=2562+Del+Zotto+Ave.%2C+Ottawa%2C+Ontario&" f"contractor=GCN&engineer=Goodkey&owner=Douglas+Stalker&" f"quality=2&cc_email=&link_to_cert={dcn_key}\r\n" ) } # set-up new entries in db, if necessary fake_dilfo_insert = """ INSERT INTO df_dilfo (job_number, receiver_email, closed) VALUES (?, 'alex.roy616@gmail.com', ?) """ fake_match_insert = """ INSERT INTO df_matched (job_number, verifier, ground_truth) VALUES (?, 'alex.roy616@gmail.com', ?) """ with create_connection() as conn: if was_prev_closed or was_prev_tracked: conn.cursor().execute(fake_dilfo_insert, [job_number, was_prev_closed]) if was_prev_matched: if was_prev_closed: conn.cursor().execute(fake_match_insert, [job_number, 1]) else: conn.cursor().execute(fake_match_insert, [job_number, 0]) with create_connection() as conn: df_dilfo_pre = pd.read_sql("SELECT * FROM df_dilfo WHERE job_number=?", conn, params=[job_number]) df_matched_pre = pd.read_sql("SELECT * FROM df_matched WHERE job_number=?", conn, params=[job_number]) process_as_form(email_obj) # make assertions about db now that reply has been processed with create_connection() as conn: df_dilfo_post = pd.read_sql("SELECT * FROM df_dilfo WHERE job_number=?", conn, params=[job_number]) df_matched_post = pd.read_sql("SELECT * FROM df_matched WHERE job_number=?", conn, params=[job_number]) self.assertEqual(len(df_dilfo_post), 1) self.assertEqual(bool(df_dilfo_post.iloc[0].closed), bool(was_prev_closed or dcn_key)) self.assertEqual(any(df_matched_post.ground_truth), bool(was_prev_closed or dcn_key)) self.assertEqual(len(df_matched_pre) + bool(dcn_key and not(was_prev_closed)), len(df_matched_post)) self.assertEqual(list(df_matched_pre.columns), list(df_matched_post.columns)) self.assertEqual(list(df_dilfo_pre.columns), list(df_dilfo_post.columns))
cwe-089
{'deleted': [{'line_no': 18, 'char_start': 823, 'char_end': 876, 'line': " VALUES ({}, 'alex.roy616@gmail.com', {})\n"}, {'line_no': 22, 'char_start': 992, 'char_end': 1045, 'line': " VALUES ({}, 'alex.roy616@gmail.com', {})\n"}, {'line_no': 26, 'char_start': 1151, 'char_end': 1244, 'line': ' conn.cursor().execute(fake_dilfo_insert.format(job_number, was_prev_closed))\n'}, {'line_no': 29, 'char_start': 1313, 'char_end': 1396, 'line': ' conn.cursor().execute(fake_match_insert.format(job_number, 1))\n'}, {'line_no': 31, 'char_start': 1418, 'char_end': 1501, 'line': ' conn.cursor().execute(fake_match_insert.format(job_number, 0))\n'}, {'line_no': 33, 'char_start': 1543, 'char_end': 1645, 'line': ' df_dilfo_pre = pd.read_sql(f"SELECT * FROM df_dilfo WHERE job_number={job_number}", conn)\n'}, {'line_no': 34, 'char_start': 1645, 'char_end': 1751, 'line': ' df_matched_pre = pd.read_sql(f"SELECT * FROM df_matched WHERE job_number={job_number}", conn)\n'}, {'line_no': 38, 'char_start': 1897, 'char_end': 2000, 'line': ' df_dilfo_post = pd.read_sql(f"SELECT * FROM df_dilfo WHERE job_number={job_number}", conn)\n'}, {'line_no': 39, 'char_start': 2000, 'char_end': 2107, 'line': ' df_matched_post = pd.read_sql(f"SELECT * FROM df_matched WHERE job_number={job_number}", conn)\n'}], 'added': [{'line_no': 18, 'char_start': 823, 'char_end': 874, 'line': " VALUES (?, 'alex.roy616@gmail.com', ?)\n"}, {'line_no': 22, 'char_start': 990, 'char_end': 1041, 'line': " VALUES (?, 'alex.roy616@gmail.com', ?)\n"}, {'line_no': 26, 'char_start': 1147, 'char_end': 1235, 'line': ' conn.cursor().execute(fake_dilfo_insert, [job_number, was_prev_closed])\n'}, {'line_no': 29, 'char_start': 1304, 'char_end': 1382, 'line': ' conn.cursor().execute(fake_match_insert, [job_number, 1])\n'}, {'line_no': 31, 'char_start': 1404, 'char_end': 1482, 'line': ' conn.cursor().execute(fake_match_insert, [job_number, 0])\n'}, {'line_no': 33, 'char_start': 1524, 'char_end': 1635, 'line': ' df_dilfo_pre = pd.read_sql("SELECT * FROM df_dilfo WHERE job_number=?", conn, params=[job_number])\n'}, {'line_no': 34, 'char_start': 1635, 'char_end': 1750, 'line': ' df_matched_pre = pd.read_sql("SELECT * FROM df_matched WHERE job_number=?", conn, params=[job_number])\n'}, {'line_no': 38, 'char_start': 1896, 'char_end': 2008, 'line': ' df_dilfo_post = pd.read_sql("SELECT * FROM df_dilfo WHERE job_number=?", conn, params=[job_number])\n'}, {'line_no': 39, 'char_start': 2008, 'char_end': 2124, 'line': ' df_matched_post = pd.read_sql("SELECT * FROM df_matched WHERE job_number=?", conn, params=[job_number])\n'}]}
{'deleted': [{'char_start': 843, 'char_end': 845, 'chars': '{}'}, {'char_start': 872, 'char_end': 874, 'chars': '{}'}, {'char_start': 1012, 'char_end': 1014, 'chars': '{}'}, {'char_start': 1041, 'char_end': 1043, 'chars': '{}'}, {'char_start': 1206, 'char_end': 1214, 'chars': '.format('}, {'char_start': 1241, 'char_end': 1242, 'chars': ')'}, {'char_start': 1372, 'char_end': 1380, 'chars': '.format('}, {'char_start': 1393, 'char_end': 1394, 'chars': ')'}, {'char_start': 1477, 'char_end': 1485, 'chars': '.format('}, {'char_start': 1498, 'char_end': 1499, 'chars': ')'}, {'char_start': 1582, 'char_end': 1583, 'chars': 'f'}, {'char_start': 1624, 'char_end': 1625, 'chars': '{'}, {'char_start': 1635, 'char_end': 1643, 'chars': '}", conn'}, {'char_start': 1686, 'char_end': 1687, 'chars': 'f'}, {'char_start': 1730, 'char_end': 1731, 'chars': '{'}, {'char_start': 1741, 'char_end': 1749, 'chars': '}", conn'}, {'char_start': 1937, 'char_end': 1938, 'chars': 'f'}, {'char_start': 1979, 'char_end': 1980, 'chars': '{'}, {'char_start': 1990, 'char_end': 1998, 'chars': '}", conn'}, {'char_start': 2042, 'char_end': 2043, 'chars': 'f'}, {'char_start': 2086, 'char_end': 2087, 'chars': '{'}, {'char_start': 2097, 'char_end': 2105, 'chars': '}", conn'}], 'added': [{'char_start': 843, 'char_end': 844, 'chars': '?'}, {'char_start': 871, 'char_end': 872, 'chars': '?'}, {'char_start': 1010, 'char_end': 1011, 'chars': '?'}, {'char_start': 1038, 'char_end': 1039, 'chars': '?'}, {'char_start': 1202, 'char_end': 1205, 'chars': ', ['}, {'char_start': 1232, 'char_end': 1233, 'chars': ']'}, {'char_start': 1363, 'char_end': 1366, 'chars': ', ['}, {'char_start': 1379, 'char_end': 1380, 'chars': ']'}, {'char_start': 1463, 'char_end': 1466, 'chars': ', ['}, {'char_start': 1479, 'char_end': 1480, 'chars': ']'}, {'char_start': 1604, 'char_end': 1622, 'chars': '?", conn, params=['}, {'char_start': 1632, 'char_end': 1633, 'chars': ']'}, {'char_start': 1719, 'char_end': 1737, 'chars': '?", conn, params=['}, {'char_start': 1747, 'char_end': 1748, 'chars': ']'}, {'char_start': 1977, 'char_end': 1995, 'chars': '?", conn, params=['}, {'char_start': 2005, 'char_end': 2006, 'chars': ']'}, {'char_start': 2093, 'char_end': 2111, 'chars': '?", conn, params=['}, {'char_start': 2121, 'char_end': 2122, 'chars': ']'}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
render_page_name
@app.route('/<page_name>') def render_page_name(page_name): query = db.query("select page_content.content, page.id as page_id, page_content.id as content_id from page, page_content where page.id = page_content.page_id and page.page_name = '%s' order by page_content.id desc limit 1" % page_name) wiki_page = query.namedresult() has_content = False page_is_taken = False if len(wiki_page) < 1: content = "" else: page_is_taken = True content = wiki_page[0].content if len(content) > 0: has_content = True else: pass content = markdown.markdown(wiki_linkify(content)) return render_template( 'pageholder.html', page_is_taken = page_is_taken, page_name = page_name, markdown = markdown, wiki_linkify = wiki_linkify, has_content = has_content, content = content )
cwe-089
{'deleted': [{'line_no': 3, 'char_start': 60, 'char_end': 300, 'line': ' query = db.query("select page_content.content, page.id as page_id, page_content.id as content_id from page, page_content where page.id = page_content.page_id and page.page_name = \'%s\' order by page_content.id desc limit 1" % page_name)\n'}], 'added': [{'line_no': 3, 'char_start': 60, 'char_end': 297, 'line': ' query = db.query("select page_content.content, page.id as page_id, page_content.id as content_id from page, page_content where page.id = page_content.page_id and page.page_name = $1 order by page_content.id desc limit 1", page_name)\n'}]}
{'deleted': [{'char_start': 243, 'char_end': 247, 'chars': "'%s'"}, {'char_start': 286, 'char_end': 288, 'chars': ' %'}], 'added': [{'char_start': 243, 'char_end': 245, 'chars': '$1'}, {'char_start': 284, 'char_end': 285, 'chars': ','}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
render_page_name
@app.route('/<page_name>') def render_page_name(page_name): query = db.query("select page_content.content, page.id as page_id, page_content.id as content_id from page, page_content where page.id = page_content.page_id and page.page_name = $1 order by page_content.id desc limit 1", page_name) wiki_page = query.namedresult() has_content = False page_is_taken = False if len(wiki_page) < 1: content = "" else: page_is_taken = True content = wiki_page[0].content if len(content) > 0: has_content = True else: pass content = markdown.markdown(wiki_linkify(content)) return render_template( 'pageholder.html', page_is_taken = page_is_taken, page_name = page_name, markdown = markdown, wiki_linkify = wiki_linkify, has_content = has_content, content = content )
cwe-089
{'deleted': [{'line_no': 3, 'char_start': 60, 'char_end': 300, 'line': ' query = db.query("select page_content.content, page.id as page_id, page_content.id as content_id from page, page_content where page.id = page_content.page_id and page.page_name = \'%s\' order by page_content.id desc limit 1" % page_name)\n'}], 'added': [{'line_no': 3, 'char_start': 60, 'char_end': 297, 'line': ' query = db.query("select page_content.content, page.id as page_id, page_content.id as content_id from page, page_content where page.id = page_content.page_id and page.page_name = $1 order by page_content.id desc limit 1", page_name)\n'}]}
{'deleted': [{'char_start': 243, 'char_end': 247, 'chars': "'%s'"}, {'char_start': 286, 'char_end': 288, 'chars': ' %'}], 'added': [{'char_start': 243, 'char_end': 245, 'chars': '$1'}, {'char_start': 284, 'char_end': 285, 'chars': ','}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
tid_to_tid_num
def tid_to_tid_num(self, tid): ''' Returns tid_num, given tid. ''' q = "SELECT rowid FROM tids WHERE tid = '" + tid + "'" self.query(q) return self.c.fetchone()[0]
cwe-089
{'deleted': [{'line_no': 4, 'char_start': 80, 'char_end': 143, 'line': ' q = "SELECT rowid FROM tids WHERE tid = \'" + tid + "\'"\n'}, {'line_no': 5, 'char_start': 143, 'char_end': 165, 'line': ' self.query(q)\n'}], 'added': [{'line_no': 4, 'char_start': 80, 'char_end': 131, 'line': ' q = "SELECT rowid FROM tids WHERE tid = ?"\n'}, {'line_no': 5, 'char_start': 131, 'char_end': 158, 'line': ' self.query(q, tid)\n'}]}
{'deleted': [{'char_start': 128, 'char_end': 141, 'chars': '\'" + tid + "\''}], 'added': [{'char_start': 128, 'char_end': 129, 'chars': '?'}, {'char_start': 151, 'char_end': 156, 'chars': ', tid'}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
tid_to_tid_num
def tid_to_tid_num(self, tid): ''' Returns tid_num, given tid. ''' q = "SELECT rowid FROM tids WHERE tid = ?" self.query(q, tid) return self.c.fetchone()[0]
cwe-089
{'deleted': [{'line_no': 4, 'char_start': 80, 'char_end': 143, 'line': ' q = "SELECT rowid FROM tids WHERE tid = \'" + tid + "\'"\n'}, {'line_no': 5, 'char_start': 143, 'char_end': 165, 'line': ' self.query(q)\n'}], 'added': [{'line_no': 4, 'char_start': 80, 'char_end': 131, 'line': ' q = "SELECT rowid FROM tids WHERE tid = ?"\n'}, {'line_no': 5, 'char_start': 131, 'char_end': 158, 'line': ' self.query(q, tid)\n'}]}
{'deleted': [{'char_start': 128, 'char_end': 141, 'chars': '\'" + tid + "\''}], 'added': [{'char_start': 128, 'char_end': 129, 'chars': '?'}, {'char_start': 151, 'char_end': 156, 'chars': ', tid'}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
get_old_sourcebyinstitution_number
def get_old_sourcebyinstitution_number(conn, sqlite, sourcebyinstitution): """ Get all the old sourcebyinstitution number from the SQLite database. """ query = """ SELECT titles FROM history WHERE sourcebyinstitution = "%s" ORDER BY titles DESC LIMIT 1 """ % sourcebyinstitution sqlite.execute(query) for record in sqlite: old_sourcebyinstitution_number = record[0] return old_sourcebyinstitution_number
cwe-089
{'deleted': [{'line_no': 11, 'char_start': 261, 'char_end': 300, 'line': ' sourcebyinstitution = "%s"\n'}, {'line_no': 15, 'char_start': 357, 'char_end': 387, 'line': ' """ % sourcebyinstitution\n'}, {'line_no': 17, 'char_start': 388, 'char_end': 414, 'line': ' sqlite.execute(query)\n'}], 'added': [{'line_no': 11, 'char_start': 261, 'char_end': 297, 'line': ' sourcebyinstitution = ?\n'}, {'line_no': 15, 'char_start': 354, 'char_end': 362, 'line': ' """\n'}, {'line_no': 17, 'char_start': 363, 'char_end': 413, 'line': ' sqlite.execute(query, (sourcebyinstitution,))\n'}]}
{'deleted': [{'char_start': 295, 'char_end': 299, 'chars': '"%s"'}, {'char_start': 364, 'char_end': 386, 'chars': ' % sourcebyinstitution'}], 'added': [{'char_start': 295, 'char_end': 296, 'chars': '?'}, {'char_start': 387, 'char_end': 411, 'chars': ', (sourcebyinstitution,)'}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
get_old_sourcebyinstitution_number
def get_old_sourcebyinstitution_number(conn, sqlite, sourcebyinstitution): """ Get all the old sourcebyinstitution number from the SQLite database. """ query = """ SELECT titles FROM history WHERE sourcebyinstitution = ? ORDER BY titles DESC LIMIT 1 """ sqlite.execute(query, (sourcebyinstitution,)) for record in sqlite: old_sourcebyinstitution_number = record[0] return old_sourcebyinstitution_number
cwe-089
{'deleted': [{'line_no': 11, 'char_start': 261, 'char_end': 300, 'line': ' sourcebyinstitution = "%s"\n'}, {'line_no': 15, 'char_start': 357, 'char_end': 387, 'line': ' """ % sourcebyinstitution\n'}, {'line_no': 17, 'char_start': 388, 'char_end': 414, 'line': ' sqlite.execute(query)\n'}], 'added': [{'line_no': 11, 'char_start': 261, 'char_end': 297, 'line': ' sourcebyinstitution = ?\n'}, {'line_no': 15, 'char_start': 354, 'char_end': 362, 'line': ' """\n'}, {'line_no': 17, 'char_start': 363, 'char_end': 413, 'line': ' sqlite.execute(query, (sourcebyinstitution,))\n'}]}
{'deleted': [{'char_start': 295, 'char_end': 299, 'chars': '"%s"'}, {'char_start': 364, 'char_end': 386, 'chars': ' % sourcebyinstitution'}], 'added': [{'char_start': 295, 'char_end': 296, 'chars': '?'}, {'char_start': 387, 'char_end': 411, 'chars': ', (sourcebyinstitution,)'}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
top_karma
def top_karma(bot, trigger): """ Show karma status for the top n number of IRC users. """ try: top_limit = int(trigger.group(2).strip()) except ValueError: top_limit = 5 query = "SELECT slug, value FROM nick_values NATURAL JOIN nicknames \ WHERE key = 'karma' ORDER BY value DESC LIMIT %d" karmalist = bot.db.execute(query % top_limit).fetchall() for user in karmalist: bot.say("%s == %s" % (user[0], user[1]))
cwe-089
{'deleted': [{'line_no': 11, 'char_start': 281, 'char_end': 339, 'line': ' WHERE key = \'karma\' ORDER BY value DESC LIMIT %d"\n'}, {'line_no': 12, 'char_start': 339, 'char_end': 400, 'line': ' karmalist = bot.db.execute(query % top_limit).fetchall()\n'}], 'added': [{'line_no': 11, 'char_start': 281, 'char_end': 338, 'line': ' WHERE key = \'karma\' ORDER BY value DESC LIMIT ?"\n'}, {'line_no': 12, 'char_start': 338, 'char_end': 403, 'line': ' karmalist = bot.db.execute(query, str(top_limit)).fetchall()\n'}]}
{'deleted': [{'char_start': 335, 'char_end': 337, 'chars': '%d'}, {'char_start': 376, 'char_end': 378, 'chars': '% '}], 'added': [{'char_start': 335, 'char_end': 336, 'chars': '?'}, {'char_start': 374, 'char_end': 375, 'chars': ','}, {'char_start': 376, 'char_end': 380, 'chars': 'str('}, {'char_start': 389, 'char_end': 390, 'chars': ')'}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
top_karma
def top_karma(bot, trigger): """ Show karma status for the top n number of IRC users. """ try: top_limit = int(trigger.group(2).strip()) except ValueError: top_limit = 5 query = "SELECT slug, value FROM nick_values NATURAL JOIN nicknames \ WHERE key = 'karma' ORDER BY value DESC LIMIT ?" karmalist = bot.db.execute(query, str(top_limit)).fetchall() for user in karmalist: bot.say("%s == %s" % (user[0], user[1]))
cwe-089
{'deleted': [{'line_no': 11, 'char_start': 281, 'char_end': 339, 'line': ' WHERE key = \'karma\' ORDER BY value DESC LIMIT %d"\n'}, {'line_no': 12, 'char_start': 339, 'char_end': 400, 'line': ' karmalist = bot.db.execute(query % top_limit).fetchall()\n'}], 'added': [{'line_no': 11, 'char_start': 281, 'char_end': 338, 'line': ' WHERE key = \'karma\' ORDER BY value DESC LIMIT ?"\n'}, {'line_no': 12, 'char_start': 338, 'char_end': 403, 'line': ' karmalist = bot.db.execute(query, str(top_limit)).fetchall()\n'}]}
{'deleted': [{'char_start': 335, 'char_end': 337, 'chars': '%d'}, {'char_start': 376, 'char_end': 378, 'chars': '% '}], 'added': [{'char_start': 335, 'char_end': 336, 'chars': '?'}, {'char_start': 374, 'char_end': 375, 'chars': ','}, {'char_start': 376, 'char_end': 380, 'chars': 'str('}, {'char_start': 389, 'char_end': 390, 'chars': ')'}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
retrieve_playlist_by_id
def retrieve_playlist_by_id(id, db): db.execute( "SELECT id, name, video_position from playlist WHERE id={id};".format(id=id)) row = db.fetchone() return row
cwe-089
{'deleted': [{'line_no': 3, 'char_start': 53, 'char_end': 139, 'line': ' "SELECT id, name, video_position from playlist WHERE id={id};".format(id=id))\n'}], 'added': [{'line_no': 3, 'char_start': 53, 'char_end': 130, 'line': ' "SELECT id, name, video_position from playlist WHERE id=%s;", (id,))\n'}]}
{'deleted': [{'char_start': 117, 'char_end': 121, 'chars': '{id}'}, {'char_start': 123, 'char_end': 130, 'chars': '.format'}, {'char_start': 133, 'char_end': 136, 'chars': '=id'}], 'added': [{'char_start': 117, 'char_end': 119, 'chars': '%s'}, {'char_start': 121, 'char_end': 123, 'chars': ', '}, {'char_start': 126, 'char_end': 127, 'chars': ','}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
retrieve_playlist_by_id
def retrieve_playlist_by_id(id, db): db.execute( "SELECT id, name, video_position from playlist WHERE id=%s;", (id,)) row = db.fetchone() return row
cwe-089
{'deleted': [{'line_no': 3, 'char_start': 53, 'char_end': 139, 'line': ' "SELECT id, name, video_position from playlist WHERE id={id};".format(id=id))\n'}], 'added': [{'line_no': 3, 'char_start': 53, 'char_end': 130, 'line': ' "SELECT id, name, video_position from playlist WHERE id=%s;", (id,))\n'}]}
{'deleted': [{'char_start': 117, 'char_end': 121, 'chars': '{id}'}, {'char_start': 123, 'char_end': 130, 'chars': '.format'}, {'char_start': 133, 'char_end': 136, 'chars': '=id'}], 'added': [{'char_start': 117, 'char_end': 119, 'chars': '%s'}, {'char_start': 121, 'char_end': 123, 'chars': ', '}, {'char_start': 126, 'char_end': 127, 'chars': ','}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
get_task
@bot.message_handler(func = lambda message: get_current_state(message.chat.id) == config.States.S_GET_TASK.value) def get_task(message): settings = sqlite3.connect(os.path.abspath(os.path.dirname(__file__)) + "\\bases\\settings.db") conn = settings.cursor() conn.execute("select * from users where chat_id = '" + str(message.chat.id) + "'") name = conn.fetchone() settings.close() if name == None: bot.send_message(message.chat.id, "You should login before get tasks.") else: bases.update.update_user(name[1], name[0], name[2]) bot.send_message(message.chat.id, bases.problem.get_unsolved_problem(message.text, name[1])) set_state(message.chat.id, config.States.S_START.value)
cwe-089
{'deleted': [{'line_no': 5, 'char_start': 266, 'char_end': 353, 'line': ' conn.execute("select * from users where chat_id = \'" + str(message.chat.id) + "\'")\n'}], 'added': [{'line_no': 5, 'char_start': 266, 'char_end': 349, 'line': ' conn.execute("select * from users where chat_id = ?", (str(message.chat.id),))\n'}]}
{'deleted': [{'char_start': 320, 'char_end': 321, 'chars': "'"}, {'char_start': 322, 'char_end': 324, 'chars': ' +'}, {'char_start': 345, 'char_end': 351, 'chars': ' + "\'"'}], 'added': [{'char_start': 320, 'char_end': 321, 'chars': '?'}, {'char_start': 322, 'char_end': 323, 'chars': ','}, {'char_start': 324, 'char_end': 325, 'chars': '('}, {'char_start': 345, 'char_end': 347, 'chars': ',)'}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
get_task
@bot.message_handler(func = lambda message: get_current_state(message.chat.id) == config.States.S_GET_TASK.value) def get_task(message): settings = sqlite3.connect(os.path.abspath(os.path.dirname(__file__)) + "\\bases\\settings.db") conn = settings.cursor() conn.execute("select * from users where chat_id = ?", (str(message.chat.id),)) name = conn.fetchone() settings.close() if name == None: bot.send_message(message.chat.id, "You should login before get tasks.") else: bases.update.update_user(name[1], name[0], name[2]) bot.send_message(message.chat.id, bases.problem.get_unsolved_problem(message.text, name[1])) set_state(message.chat.id, config.States.S_START.value)
cwe-089
{'deleted': [{'line_no': 5, 'char_start': 266, 'char_end': 353, 'line': ' conn.execute("select * from users where chat_id = \'" + str(message.chat.id) + "\'")\n'}], 'added': [{'line_no': 5, 'char_start': 266, 'char_end': 349, 'line': ' conn.execute("select * from users where chat_id = ?", (str(message.chat.id),))\n'}]}
{'deleted': [{'char_start': 320, 'char_end': 321, 'chars': "'"}, {'char_start': 322, 'char_end': 324, 'chars': ' +'}, {'char_start': 345, 'char_end': 351, 'chars': ' + "\'"'}], 'added': [{'char_start': 320, 'char_end': 321, 'chars': '?'}, {'char_start': 322, 'char_end': 323, 'chars': ','}, {'char_start': 324, 'char_end': 325, 'chars': '('}, {'char_start': 345, 'char_end': 347, 'chars': ',)'}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
stats
@bot.message_handler(commands=['stats']) def stats(message): settings = sqlite3.connect(os.path.abspath(os.path.dirname(__file__)) + "\\bases\\settings.db") conn = settings.cursor() conn.execute("select * from users where chat_id = '" + str(message.chat.id) + "'") name = conn.fetchone() settings.close() if name != None: bases.update.update_user(name[1], name[0], name[2]) bases.problem.create_text_stats(name[1]) img = open(os.path.abspath(os.path.dirname(__file__)) + "\\bases\\users\\" + name[1] + ".png", "rb") bot.send_photo(message.chat.id, img) img.close() if bases.problem.create_stats_picture(name[1]): bot.send_message(message.chat.id, "Sorry, you haven't solved tasks.") return 0 img = open(os.path.abspath(os.path.dirname(__file__)) + "\\bases\\users\\" + name[1] + ".png", "rb") bot.send_photo(message.chat.id, img) img.close() else: bot.send_message(message.chat.id, "You should login before getting statistic.")
cwe-089
{'deleted': [{'line_no': 5, 'char_start': 190, 'char_end': 277, 'line': ' conn.execute("select * from users where chat_id = \'" + str(message.chat.id) + "\'")\n'}], 'added': [{'line_no': 5, 'char_start': 190, 'char_end': 273, 'line': ' conn.execute("select * from users where chat_id = ?", (str(message.chat.id),))\n'}]}
{'deleted': [{'char_start': 244, 'char_end': 245, 'chars': "'"}, {'char_start': 246, 'char_end': 248, 'chars': ' +'}, {'char_start': 269, 'char_end': 275, 'chars': ' + "\'"'}], 'added': [{'char_start': 244, 'char_end': 245, 'chars': '?'}, {'char_start': 246, 'char_end': 247, 'chars': ','}, {'char_start': 248, 'char_end': 249, 'chars': '('}, {'char_start': 269, 'char_end': 271, 'chars': ',)'}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
stats
@bot.message_handler(commands=['stats']) def stats(message): settings = sqlite3.connect(os.path.abspath(os.path.dirname(__file__)) + "\\bases\\settings.db") conn = settings.cursor() conn.execute("select * from users where chat_id = ?", (str(message.chat.id),)) name = conn.fetchone() settings.close() if name != None: bases.update.update_user(name[1], name[0], name[2]) bases.problem.create_text_stats(name[1]) img = open(os.path.abspath(os.path.dirname(__file__)) + "\\bases\\users\\" + name[1] + ".png", "rb") bot.send_photo(message.chat.id, img) img.close() if bases.problem.create_stats_picture(name[1]): bot.send_message(message.chat.id, "Sorry, you haven't solved tasks.") return 0 img = open(os.path.abspath(os.path.dirname(__file__)) + "\\bases\\users\\" + name[1] + ".png", "rb") bot.send_photo(message.chat.id, img) img.close() else: bot.send_message(message.chat.id, "You should login before getting statistic.")
cwe-089
{'deleted': [{'line_no': 5, 'char_start': 190, 'char_end': 277, 'line': ' conn.execute("select * from users where chat_id = \'" + str(message.chat.id) + "\'")\n'}], 'added': [{'line_no': 5, 'char_start': 190, 'char_end': 273, 'line': ' conn.execute("select * from users where chat_id = ?", (str(message.chat.id),))\n'}]}
{'deleted': [{'char_start': 244, 'char_end': 245, 'chars': "'"}, {'char_start': 246, 'char_end': 248, 'chars': ' +'}, {'char_start': 269, 'char_end': 275, 'chars': ' + "\'"'}], 'added': [{'char_start': 244, 'char_end': 245, 'chars': '?'}, {'char_start': 246, 'char_end': 247, 'chars': ','}, {'char_start': 248, 'char_end': 249, 'chars': '('}, {'char_start': 269, 'char_end': 271, 'chars': ',)'}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
delete
@jwt_required def delete(self, user_id): """ Deletes user with the corresponding user_id """ return database_utilities.execute_query(f"""delete from users where user_id = '{user_id}'""")
cwe-089
{'deleted': [{'line_no': 4, 'char_start': 109, 'char_end': 210, 'line': ' return database_utilities.execute_query(f"""delete from users where user_id = \'{user_id}\'""")\n'}], 'added': [{'line_no': 4, 'char_start': 109, 'char_end': 214, 'line': ' return database_utilities.execute_query(f"""delete from users where user_id = %s""", (user_id, ))\n'}]}
{'deleted': [{'char_start': 195, 'char_end': 197, 'chars': "'{"}, {'char_start': 204, 'char_end': 209, 'chars': '}\'"""'}], 'added': [{'char_start': 195, 'char_end': 203, 'chars': '%s""", ('}, {'char_start': 210, 'char_end': 213, 'chars': ', )'}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
delete
@jwt_required def delete(self, user_id): """ Deletes user with the corresponding user_id """ return database_utilities.execute_query(f"""delete from users where user_id = %s""", (user_id, ))
cwe-089
{'deleted': [{'line_no': 4, 'char_start': 109, 'char_end': 210, 'line': ' return database_utilities.execute_query(f"""delete from users where user_id = \'{user_id}\'""")\n'}], 'added': [{'line_no': 4, 'char_start': 109, 'char_end': 214, 'line': ' return database_utilities.execute_query(f"""delete from users where user_id = %s""", (user_id, ))\n'}]}
{'deleted': [{'char_start': 195, 'char_end': 197, 'chars': "'{"}, {'char_start': 204, 'char_end': 209, 'chars': '}\'"""'}], 'added': [{'char_start': 195, 'char_end': 203, 'chars': '%s""", ('}, {'char_start': 210, 'char_end': 213, 'chars': ', )'}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
verify_rno
def verify_rno(self, rno): query = "SELECT COUNT(rno) FROM rides WHERE rno = {rno}".format(rno = rno) self.cursor.execute(query) result = self.cursor.fetchone() if (int(result[0]) > 0): return True else: return False
cwe-089
{'deleted': [{'line_no': 2, 'char_start': 31, 'char_end': 114, 'line': ' query = "SELECT COUNT(rno) FROM rides WHERE rno = {rno}".format(rno = rno)\n'}, {'line_no': 3, 'char_start': 114, 'char_end': 149, 'line': ' self.cursor.execute(query)\n'}], 'added': [{'line_no': 2, 'char_start': 31, 'char_end': 122, 'line': ' self.cursor.execute("SELECT COUNT(rno) FROM rides WHERE rno = :rno", {\'rno\': rno})\n'}]}
{'deleted': [{'char_start': 39, 'char_end': 41, 'chars': 'qu'}, {'char_start': 43, 'char_end': 47, 'chars': 'y = '}, {'char_start': 89, 'char_end': 90, 'chars': '{'}, {'char_start': 93, 'char_end': 94, 'chars': '}'}, {'char_start': 95, 'char_end': 103, 'chars': '.format('}, {'char_start': 106, 'char_end': 108, 'chars': ' ='}, {'char_start': 112, 'char_end': 147, 'chars': ')\n self.cursor.execute(query'}], 'added': [{'char_start': 39, 'char_end': 55, 'chars': 'self.cursor.exec'}, {'char_start': 56, 'char_end': 57, 'chars': 't'}, {'char_start': 58, 'char_end': 59, 'chars': '('}, {'char_start': 101, 'char_end': 102, 'chars': ':'}, {'char_start': 106, 'char_end': 107, 'chars': ','}, {'char_start': 108, 'char_end': 110, 'chars': "{'"}, {'char_start': 113, 'char_end': 115, 'chars': "':"}, {'char_start': 117, 'char_end': 118, 'chars': 'n'}, {'char_start': 119, 'char_end': 120, 'chars': '}'}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
verify_rno
def verify_rno(self, rno): self.cursor.execute("SELECT COUNT(rno) FROM rides WHERE rno = :rno", {'rno': rno}) result = self.cursor.fetchone() if (int(result[0]) > 0): return True else: return False
cwe-089
{'deleted': [{'line_no': 2, 'char_start': 31, 'char_end': 114, 'line': ' query = "SELECT COUNT(rno) FROM rides WHERE rno = {rno}".format(rno = rno)\n'}, {'line_no': 3, 'char_start': 114, 'char_end': 149, 'line': ' self.cursor.execute(query)\n'}], 'added': [{'line_no': 2, 'char_start': 31, 'char_end': 122, 'line': ' self.cursor.execute("SELECT COUNT(rno) FROM rides WHERE rno = :rno", {\'rno\': rno})\n'}]}
{'deleted': [{'char_start': 39, 'char_end': 41, 'chars': 'qu'}, {'char_start': 43, 'char_end': 47, 'chars': 'y = '}, {'char_start': 89, 'char_end': 90, 'chars': '{'}, {'char_start': 93, 'char_end': 94, 'chars': '}'}, {'char_start': 95, 'char_end': 103, 'chars': '.format('}, {'char_start': 106, 'char_end': 108, 'chars': ' ='}, {'char_start': 112, 'char_end': 147, 'chars': ')\n self.cursor.execute(query'}], 'added': [{'char_start': 39, 'char_end': 55, 'chars': 'self.cursor.exec'}, {'char_start': 56, 'char_end': 57, 'chars': 't'}, {'char_start': 58, 'char_end': 59, 'chars': '('}, {'char_start': 101, 'char_end': 102, 'chars': ':'}, {'char_start': 106, 'char_end': 107, 'chars': ','}, {'char_start': 108, 'char_end': 110, 'chars': "{'"}, {'char_start': 113, 'char_end': 115, 'chars': "':"}, {'char_start': 117, 'char_end': 118, 'chars': 'n'}, {'char_start': 119, 'char_end': 120, 'chars': '}'}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
get_requested_day
def get_requested_day(self, date): data = dict() day_start, day_end = self.get_epoch_day(date) data['interval'] = {'from': self.convert_local_ts_to_utc(day_start, self.local_timezone), 'to': self.convert_local_ts_to_utc(day_end, self.local_timezone)} query = ''' SELECT TimeStamp, SUM(Power) AS Power FROM DayData WHERE TimeStamp BETWEEN %s AND %s GROUP BY TimeStamp; ''' data['data'] = list() for row in self.c.execute(query % (day_start, day_end)): data['data'].append({ 'time': row[0], 'power': row[1] }) if self.get_datetime(date).date() == datetime.today().date(): query = ''' SELECT SUM(EToday) as EToday FROM Inverters; ''' else: query = ''' SELECT SUM(DayYield) AS Power FROM MonthData WHERE TimeStamp BETWEEN %s AND %s GROUP BY TimeStamp ''' % (day_start, day_end) self.c.execute(query) row = self.c.fetchone() if row and row[0]: data['total'] = row[0] else: data['total'] = 0 query = ''' SELECT MIN(TimeStamp) as Min, MAX(TimeStamp) as Max FROM ( SELECT TimeStamp FROM DayData GROUP BY TimeStamp ); ''' self.c.execute(query) first_data, last_data = self.c.fetchone() if (first_data): data['hasPrevious'] = (first_data < day_start) else: data['hasPrevious'] = False if (last_data): data['hasNext'] = (last_data > day_end) else: data['hasNext'] = False #print(json.dumps(data, indent=4)) return data
cwe-089
{'deleted': [{'line_no': 11, 'char_start': 379, 'char_end': 426, 'line': ' WHERE TimeStamp BETWEEN %s AND %s \n'}, {'line_no': 16, 'char_start': 501, 'char_end': 566, 'line': ' for row in self.c.execute(query % (day_start, day_end)):\n'}, {'line_no': 29, 'char_start': 945, 'char_end': 995, 'line': ' WHERE TimeStamp BETWEEN %s AND %s\n'}, {'line_no': 30, 'char_start': 995, 'char_end': 1030, 'line': ' GROUP BY TimeStamp\n'}, {'line_no': 31, 'char_start': 1030, 'char_end': 1073, 'line': " ''' % (day_start, day_end)\n"}, {'line_no': 32, 'char_start': 1073, 'char_end': 1103, 'line': ' self.c.execute(query)\n'}], 'added': [{'line_no': 11, 'char_start': 379, 'char_end': 423, 'line': ' WHERE TimeStamp BETWEEN ? AND ?\n'}, {'line_no': 16, 'char_start': 498, 'char_end': 562, 'line': ' for row in self.c.execute(query, (day_start, day_end)):\n'}, {'line_no': 25, 'char_start': 824, 'char_end': 858, 'line': ' self.c.execute(query)\n'}, {'line_no': 30, 'char_start': 975, 'char_end': 1023, 'line': ' WHERE TimeStamp BETWEEN ? AND ?\n'}, {'line_no': 31, 'char_start': 1023, 'char_end': 1059, 'line': ' GROUP BY TimeStamp;\n'}, {'line_no': 32, 'char_start': 1059, 'char_end': 1079, 'line': " '''\n"}, {'line_no': 33, 'char_start': 1079, 'char_end': 1135, 'line': ' self.c.execute(query, (day_start, day_end))\n'}, {'line_no': 34, 'char_start': 1135, 'char_end': 1136, 'line': '\n'}]}
{'deleted': [{'char_start': 415, 'char_end': 417, 'chars': '%s'}, {'char_start': 422, 'char_end': 425, 'chars': '%s '}, {'char_start': 540, 'char_end': 542, 'chars': ' %'}, {'char_start': 985, 'char_end': 987, 'chars': '%s'}, {'char_start': 992, 'char_end': 994, 'chars': '%s'}, {'char_start': 1050, 'char_end': 1051, 'chars': '%'}, {'char_start': 1052, 'char_end': 1063, 'chars': '(day_start,'}, {'char_start': 1064, 'char_end': 1073, 'chars': 'day_end)\n'}], 'added': [{'char_start': 415, 'char_end': 416, 'chars': '?'}, {'char_start': 421, 'char_end': 422, 'chars': '?'}, {'char_start': 537, 'char_end': 538, 'chars': ','}, {'char_start': 824, 'char_end': 858, 'chars': ' self.c.execute(query)\n'}, {'char_start': 1015, 'char_end': 1016, 'chars': '?'}, {'char_start': 1021, 'char_end': 1022, 'chars': '?'}, {'char_start': 1057, 'char_end': 1058, 'chars': ';'}, {'char_start': 1078, 'char_end': 1079, 'chars': '\n'}, {'char_start': 1082, 'char_end': 1083, 'chars': ' '}, {'char_start': 1111, 'char_end': 1132, 'chars': ', (day_start, day_end'}, {'char_start': 1133, 'char_end': 1135, 'chars': ')\n'}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
get_requested_day
def get_requested_day(self, date): data = dict() day_start, day_end = self.get_epoch_day(date) data['interval'] = {'from': self.convert_local_ts_to_utc(day_start, self.local_timezone), 'to': self.convert_local_ts_to_utc(day_end, self.local_timezone)} query = ''' SELECT TimeStamp, SUM(Power) AS Power FROM DayData WHERE TimeStamp BETWEEN ? AND ? GROUP BY TimeStamp; ''' data['data'] = list() for row in self.c.execute(query, (day_start, day_end)): data['data'].append({ 'time': row[0], 'power': row[1] }) if self.get_datetime(date).date() == datetime.today().date(): query = ''' SELECT SUM(EToday) as EToday FROM Inverters; ''' self.c.execute(query) else: query = ''' SELECT SUM(DayYield) AS Power FROM MonthData WHERE TimeStamp BETWEEN ? AND ? GROUP BY TimeStamp; ''' self.c.execute(query, (day_start, day_end)) row = self.c.fetchone() if row and row[0]: data['total'] = row[0] else: data['total'] = 0 query = ''' SELECT MIN(TimeStamp) as Min, MAX(TimeStamp) as Max FROM ( SELECT TimeStamp FROM DayData GROUP BY TimeStamp ); ''' self.c.execute(query) first_data, last_data = self.c.fetchone() if (first_data): data['hasPrevious'] = (first_data < day_start) else: data['hasPrevious'] = False if (last_data): data['hasNext'] = (last_data > day_end) else: data['hasNext'] = False #print(json.dumps(data, indent=4)) return data
cwe-089
{'deleted': [{'line_no': 11, 'char_start': 379, 'char_end': 426, 'line': ' WHERE TimeStamp BETWEEN %s AND %s \n'}, {'line_no': 16, 'char_start': 501, 'char_end': 566, 'line': ' for row in self.c.execute(query % (day_start, day_end)):\n'}, {'line_no': 29, 'char_start': 945, 'char_end': 995, 'line': ' WHERE TimeStamp BETWEEN %s AND %s\n'}, {'line_no': 30, 'char_start': 995, 'char_end': 1030, 'line': ' GROUP BY TimeStamp\n'}, {'line_no': 31, 'char_start': 1030, 'char_end': 1073, 'line': " ''' % (day_start, day_end)\n"}, {'line_no': 32, 'char_start': 1073, 'char_end': 1103, 'line': ' self.c.execute(query)\n'}], 'added': [{'line_no': 11, 'char_start': 379, 'char_end': 423, 'line': ' WHERE TimeStamp BETWEEN ? AND ?\n'}, {'line_no': 16, 'char_start': 498, 'char_end': 562, 'line': ' for row in self.c.execute(query, (day_start, day_end)):\n'}, {'line_no': 25, 'char_start': 824, 'char_end': 858, 'line': ' self.c.execute(query)\n'}, {'line_no': 30, 'char_start': 975, 'char_end': 1023, 'line': ' WHERE TimeStamp BETWEEN ? AND ?\n'}, {'line_no': 31, 'char_start': 1023, 'char_end': 1059, 'line': ' GROUP BY TimeStamp;\n'}, {'line_no': 32, 'char_start': 1059, 'char_end': 1079, 'line': " '''\n"}, {'line_no': 33, 'char_start': 1079, 'char_end': 1135, 'line': ' self.c.execute(query, (day_start, day_end))\n'}, {'line_no': 34, 'char_start': 1135, 'char_end': 1136, 'line': '\n'}]}
{'deleted': [{'char_start': 415, 'char_end': 417, 'chars': '%s'}, {'char_start': 422, 'char_end': 425, 'chars': '%s '}, {'char_start': 540, 'char_end': 542, 'chars': ' %'}, {'char_start': 985, 'char_end': 987, 'chars': '%s'}, {'char_start': 992, 'char_end': 994, 'chars': '%s'}, {'char_start': 1050, 'char_end': 1051, 'chars': '%'}, {'char_start': 1052, 'char_end': 1063, 'chars': '(day_start,'}, {'char_start': 1064, 'char_end': 1073, 'chars': 'day_end)\n'}], 'added': [{'char_start': 415, 'char_end': 416, 'chars': '?'}, {'char_start': 421, 'char_end': 422, 'chars': '?'}, {'char_start': 537, 'char_end': 538, 'chars': ','}, {'char_start': 824, 'char_end': 858, 'chars': ' self.c.execute(query)\n'}, {'char_start': 1015, 'char_end': 1016, 'chars': '?'}, {'char_start': 1021, 'char_end': 1022, 'chars': '?'}, {'char_start': 1057, 'char_end': 1058, 'chars': ';'}, {'char_start': 1078, 'char_end': 1079, 'chars': '\n'}, {'char_start': 1082, 'char_end': 1083, 'chars': ' '}, {'char_start': 1111, 'char_end': 1132, 'chars': ', (day_start, day_end'}, {'char_start': 1133, 'char_end': 1135, 'chars': ')\n'}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
add_language
def add_language(lang): try: cur.execute(f"INSERT INTO language (name) VALUES ('{lang}')") except Exception as e: pass cur.execute(f"SELECT language_id FROM language where name='{lang}'") lang_id = cur.fetchone()[0] if conn.commit(): return lang_id return lang_id
cwe-089
{'deleted': [{'line_no': 3, 'char_start': 33, 'char_end': 103, 'line': ' cur.execute(f"INSERT INTO language (name) VALUES (\'{lang}\')")\n'}, {'line_no': 6, 'char_start': 143, 'char_end': 216, 'line': ' cur.execute(f"SELECT language_id FROM language where name=\'{lang}\'")\n'}], 'added': [{'line_no': 3, 'char_start': 33, 'char_end': 106, 'line': ' cur.execute("INSERT INTO language (name) VALUES (%s)", (lang, ))\n'}, {'line_no': 6, 'char_start': 146, 'char_end': 222, 'line': ' cur.execute("SELECT language_id FROM language where name=%s", (lang, ))\n'}]}
{'deleted': [{'char_start': 53, 'char_end': 54, 'chars': 'f'}, {'char_start': 91, 'char_end': 93, 'chars': "'{"}, {'char_start': 97, 'char_end': 99, 'chars': "}'"}, {'char_start': 100, 'char_end': 101, 'chars': '"'}, {'char_start': 159, 'char_end': 160, 'chars': 'f'}, {'char_start': 205, 'char_end': 207, 'chars': "'{"}, {'char_start': 211, 'char_end': 214, 'chars': '}\'"'}], 'added': [{'char_start': 90, 'char_end': 97, 'chars': '%s)", ('}, {'char_start': 101, 'char_end': 103, 'chars': ', '}, {'char_start': 207, 'char_end': 213, 'chars': '%s", ('}, {'char_start': 217, 'char_end': 220, 'chars': ', )'}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
add_language
def add_language(lang): try: cur.execute("INSERT INTO language (name) VALUES (%s)", (lang, )) except Exception as e: pass cur.execute("SELECT language_id FROM language where name=%s", (lang, )) lang_id = cur.fetchone()[0] if conn.commit(): return lang_id return lang_id
cwe-089
{'deleted': [{'line_no': 3, 'char_start': 33, 'char_end': 103, 'line': ' cur.execute(f"INSERT INTO language (name) VALUES (\'{lang}\')")\n'}, {'line_no': 6, 'char_start': 143, 'char_end': 216, 'line': ' cur.execute(f"SELECT language_id FROM language where name=\'{lang}\'")\n'}], 'added': [{'line_no': 3, 'char_start': 33, 'char_end': 106, 'line': ' cur.execute("INSERT INTO language (name) VALUES (%s)", (lang, ))\n'}, {'line_no': 6, 'char_start': 146, 'char_end': 222, 'line': ' cur.execute("SELECT language_id FROM language where name=%s", (lang, ))\n'}]}
{'deleted': [{'char_start': 53, 'char_end': 54, 'chars': 'f'}, {'char_start': 91, 'char_end': 93, 'chars': "'{"}, {'char_start': 97, 'char_end': 99, 'chars': "}'"}, {'char_start': 100, 'char_end': 101, 'chars': '"'}, {'char_start': 159, 'char_end': 160, 'chars': 'f'}, {'char_start': 205, 'char_end': 207, 'chars': "'{"}, {'char_start': 211, 'char_end': 214, 'chars': '}\'"'}], 'added': [{'char_start': 90, 'char_end': 97, 'chars': '%s)", ('}, {'char_start': 101, 'char_end': 103, 'chars': ', '}, {'char_start': 207, 'char_end': 213, 'chars': '%s", ('}, {'char_start': 217, 'char_end': 220, 'chars': ', )'}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
makeJudge
def makeJudge(judge): db.execute("UPDATE players SET Judge = 1 WHERE Name = '%s' COLLATE NOCASE" % (judge)) database.commit()
cwe-089
{'deleted': [{'line_no': 2, 'char_start': 22, 'char_end': 110, 'line': '\tdb.execute("UPDATE players SET Judge = 1 WHERE Name = \'%s\' COLLATE NOCASE" % (judge)) \n'}], 'added': [{'line_no': 2, 'char_start': 22, 'char_end': 104, 'line': '\tdb.execute("UPDATE players SET Judge = 1 WHERE Name = ? COLLATE NOCASE", judge) \n'}]}
{'deleted': [{'char_start': 77, 'char_end': 81, 'chars': "'%s'"}, {'char_start': 97, 'char_end': 99, 'chars': ' %'}, {'char_start': 100, 'char_end': 101, 'chars': '('}, {'char_start': 106, 'char_end': 107, 'chars': ')'}], 'added': [{'char_start': 77, 'char_end': 78, 'chars': '?'}, {'char_start': 94, 'char_end': 95, 'chars': ','}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
makeJudge
def makeJudge(judge): db.execute("UPDATE players SET Judge = 1 WHERE Name = ? COLLATE NOCASE", judge) database.commit()
cwe-089
{'deleted': [{'line_no': 2, 'char_start': 22, 'char_end': 110, 'line': '\tdb.execute("UPDATE players SET Judge = 1 WHERE Name = \'%s\' COLLATE NOCASE" % (judge)) \n'}], 'added': [{'line_no': 2, 'char_start': 22, 'char_end': 104, 'line': '\tdb.execute("UPDATE players SET Judge = 1 WHERE Name = ? COLLATE NOCASE", judge) \n'}]}
{'deleted': [{'char_start': 77, 'char_end': 81, 'chars': "'%s'"}, {'char_start': 97, 'char_end': 99, 'chars': ' %'}, {'char_start': 100, 'char_end': 101, 'chars': '('}, {'char_start': 106, 'char_end': 107, 'chars': ')'}], 'added': [{'char_start': 77, 'char_end': 78, 'chars': '?'}, {'char_start': 94, 'char_end': 95, 'chars': ','}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
isValidAdmToken
def isValidAdmToken(adm_token): conn, c = connectDB() req = "SELECT * from {} where adm_token='{}'".format(CFG("admintoken_table_name"), adm_token) answer = bool(queryOne(c, req)) closeDB(conn) return answer
cwe-089
{'deleted': [{'line_no': 3, 'char_start': 58, 'char_end': 157, 'line': ' req = "SELECT * from {} where adm_token=\'{}\'".format(CFG("admintoken_table_name"), adm_token)\n'}, {'line_no': 4, 'char_start': 157, 'char_end': 193, 'line': ' answer = bool(queryOne(c, req))\n'}], 'added': [{'line_no': 3, 'char_start': 58, 'char_end': 143, 'line': ' req = "SELECT * from {} where adm_token=?".format(CFG("admintoken_table_name"))\n'}, {'line_no': 4, 'char_start': 143, 'char_end': 193, 'line': ' answer = bool(queryOne(c, req, (adm_token,)))\n'}]}
{'deleted': [{'char_start': 103, 'char_end': 107, 'chars': "'{}'"}, {'char_start': 144, 'char_end': 155, 'chars': ', adm_token'}], 'added': [{'char_start': 103, 'char_end': 104, 'chars': '?'}, {'char_start': 176, 'char_end': 190, 'chars': ', (adm_token,)'}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
isValidAdmToken
def isValidAdmToken(adm_token): conn, c = connectDB() req = "SELECT * from {} where adm_token=?".format(CFG("admintoken_table_name")) answer = bool(queryOne(c, req, (adm_token,))) closeDB(conn) return answer
cwe-089
{'deleted': [{'line_no': 3, 'char_start': 58, 'char_end': 157, 'line': ' req = "SELECT * from {} where adm_token=\'{}\'".format(CFG("admintoken_table_name"), adm_token)\n'}, {'line_no': 4, 'char_start': 157, 'char_end': 193, 'line': ' answer = bool(queryOne(c, req))\n'}], 'added': [{'line_no': 3, 'char_start': 58, 'char_end': 143, 'line': ' req = "SELECT * from {} where adm_token=?".format(CFG("admintoken_table_name"))\n'}, {'line_no': 4, 'char_start': 143, 'char_end': 193, 'line': ' answer = bool(queryOne(c, req, (adm_token,)))\n'}]}
{'deleted': [{'char_start': 103, 'char_end': 107, 'chars': "'{}'"}, {'char_start': 144, 'char_end': 155, 'chars': ', adm_token'}], 'added': [{'char_start': 103, 'char_end': 104, 'chars': '?'}, {'char_start': 176, 'char_end': 190, 'chars': ', (adm_token,)'}]}
false
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
get_mapped_projects
@staticmethod def get_mapped_projects(user_id: int, preferred_locale: str) -> UserMappedProjectsDTO: """ Get all projects a user has mapped on """ # This query looks scary, but we're really just creating an outer join between the query that gets the # counts of all mapped tasks and the query that gets counts of all validated tasks. This is necessary to # handle cases where users have only validated tasks on a project, or only mapped on a project. sql = '''SELECT p.id, p.status, p.default_locale, c.mapped, c.validated, st_asgeojson(p.centroid) FROM projects p, (SELECT coalesce(v.project_id, m.project_id) project_id, coalesce(v.validated, 0) validated, coalesce(m.mapped, 0) mapped FROM (SELECT t.project_id, count (t.validated_by) validated FROM tasks t WHERE t.project_id IN (SELECT unnest(projects_mapped) FROM users WHERE id = {0}) AND t.validated_by = {0} GROUP BY t.project_id, t.validated_by) v FULL OUTER JOIN (SELECT t.project_id, count(t.mapped_by) mapped FROM tasks t WHERE t.project_id IN (SELECT unnest(projects_mapped) FROM users WHERE id = {0}) AND t.mapped_by = {0} GROUP BY t.project_id, t.mapped_by) m ON v.project_id = m.project_id) c WHERE p.id = c.project_id ORDER BY p.id DESC'''.format(user_id) results = db.engine.execute(sql) if results.rowcount == 0: raise NotFound() mapped_projects_dto = UserMappedProjectsDTO() for row in results: mapped_project = MappedProject() mapped_project.project_id = row[0] mapped_project.status = ProjectStatus(row[1]).name mapped_project.tasks_mapped = row[3] mapped_project.tasks_validated = row[4] mapped_project.centroid = geojson.loads(row[5]) project_info = ProjectInfo.get_dto_for_locale(row[0], preferred_locale, row[2]) mapped_project.name = project_info.name mapped_projects_dto.mapped_projects.append(mapped_project) return mapped_projects_dto
cwe-089
{'deleted': [{'line_no': 21, 'char_start': 1137, 'char_end': 1251, 'line': ' WHERE t.project_id IN (SELECT unnest(projects_mapped) FROM users WHERE id = {0})\n'}, {'line_no': 22, 'char_start': 1251, 'char_end': 1311, 'line': ' AND t.validated_by = {0}\n'}, {'line_no': 28, 'char_start': 1570, 'char_end': 1677, 'line': ' WHERE t.project_id IN (SELECT unnest(projects_mapped) FROM users WHERE id = {0})\n'}, {'line_no': 29, 'char_start': 1677, 'char_end': 1727, 'line': ' AND t.mapped_by = {0}\n'}, {'line_no': 32, 'char_start': 1850, 'char_end': 1933, 'line': " WHERE p.id = c.project_id ORDER BY p.id DESC'''.format(user_id)\n"}, {'line_no': 34, 'char_start': 1934, 'char_end': 1975, 'line': ' results = db.engine.execute(sql)\n'}], 'added': [{'line_no': 21, 'char_start': 1137, 'char_end': 1256, 'line': ' WHERE t.project_id IN (SELECT unnest(projects_mapped) FROM users WHERE id = :user_id)\n'}, {'line_no': 22, 'char_start': 1256, 'char_end': 1321, 'line': ' AND t.validated_by = :user_id\n'}, {'line_no': 28, 'char_start': 1580, 'char_end': 1692, 'line': ' WHERE t.project_id IN (SELECT unnest(projects_mapped) FROM users WHERE id = :user_id)\n'}, {'line_no': 29, 'char_start': 1692, 'char_end': 1747, 'line': ' AND t.mapped_by = :user_id\n'}, {'line_no': 32, 'char_start': 1870, 'char_end': 1937, 'line': " WHERE p.id = c.project_id ORDER BY p.id DESC'''\n"}, {'line_no': 34, 'char_start': 1938, 'char_end': 2002, 'line': ' results = db.engine.execute(text(sql), user_id=user_id)\n'}]}
{'deleted': [{'char_start': 1246, 'char_end': 1249, 'chars': '{0}'}, {'char_start': 1307, 'char_end': 1310, 'chars': '{0}'}, {'char_start': 1672, 'char_end': 1675, 'chars': '{0}'}, {'char_start': 1723, 'char_end': 1726, 'chars': '{0}'}, {'char_start': 1916, 'char_end': 1932, 'chars': '.format(user_id)'}], 'added': [{'char_start': 1246, 'char_end': 1254, 'chars': ':user_id'}, {'char_start': 1312, 'char_end': 1320, 'chars': ':user_id'}, {'char_start': 1682, 'char_end': 1690, 'chars': ':user_id'}, {'char_start': 1738, 'char_end': 1746, 'chars': ':user_id'}, {'char_start': 1974, 'char_end': 1979, 'chars': 'text('}, {'char_start': 1982, 'char_end': 2000, 'chars': '), user_id=user_id'}]}
true
Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component.
End of preview. Expand in Data Studio

Dataset Card for "sven"

More Information needed

Downloads last month
1