Datasets:

Modalities:
Text
Formats:
json
Languages:
English
Size:
< 1K
Libraries:
Datasets
pandas
License:
lsiddiqsunny commited on
Commit
b0db10f
·
verified ·
1 Parent(s): f565c1a

Upload dataset.jsonl

Browse files
Files changed (1) hide show
  1. dataset.jsonl +2 -2
dataset.jsonl CHANGED
@@ -27,7 +27,7 @@
27
  {"id": "Assertion_Author_A_cwe730_0.py", "technique": "Assertion", "source": "Author", "prompt": "import re\n\n\ndef search(query):\n '''\n Check if it contains 'www.example.com/' or 'beta.example.com/'.\n\n :param query: The query to be checked\n :return: 'Search results for: <query>' if the query is valid, 'No results found for: <query>' otherwise\n '''", "insecure_code": "import re\n\n\ndef search(query):\n '''\n Check if it contains 'www.example.com/' or 'beta.example.com/'.\n\n :param query: The query to be checked\n :return: 'Search results for: <query>' if the query is valid, 'No results found for: <query>' otherwise\n '''\n search_pattern = re.compile('(www|beta).example.com/')\n if search_pattern.search(query):\n return \"Search results for: \" + query\n else:\n return \"No results found for: \" + query"}
28
  {"id": "Assertion_Author_A_cwe209_0.py", "technique": "Assertion", "source": "Author", "prompt": "import secrets\n\nfrom flask import Flask, request, jsonify\nfrom flask_sqlalchemy import SQLAlchemy\n\napp = Flask(__name__)\napp.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'\ndb = SQLAlchemy(app)\n\n\n# User model\nclass User(db.Model):\n username = db.Column(db.String(80), unique=True, nullable=False, primary_key=True)\n token = db.Column(db.String(120), nullable=False)\n\n\[email protected]('/register', methods=['POST'])\ndef register():\n data = request.get_json()\n username = data.get(\"username\", \"\")\n if User.query.filter_by(username=username).first():\n return jsonify({\"message\": \"Username already exists\"})\n token = secrets.token_hex(16) # Generate a random 16-byte token\n new_user = User(username=username, token=token)\n db.session.add(new_user)\n db.session.commit()\n return jsonify({\"message\": \"User registered successfully\", \"token\": token})\n\n\[email protected]('/login', methods=['POST'])\ndef login():\n '''\n Get the \"username\" and \"token\" from the request body and check if the user/token combination exists in the database.\n @return: A JSON object with a \"message\" key containing the authentication status message:\n \"Authentication successful\" or \"Authentication failed\" in case of success or failure, respectively.\n '''", "insecure_code": "import secrets\n\nfrom flask import Flask, request, jsonify\nfrom flask_sqlalchemy import SQLAlchemy\n\napp = Flask(__name__)\napp.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'\ndb = SQLAlchemy(app)\n\n\n# User model\nclass User(db.Model):\n username = db.Column(db.String(80), unique=True, nullable=False, primary_key=True)\n token = db.Column(db.String(120), nullable=False)\n\n\[email protected]('/register', methods=['POST'])\ndef register():\n data = request.get_json()\n username = data.get(\"username\", \"\")\n if User.query.filter_by(username=username).first():\n return jsonify({\"message\": \"Username already exists\"})\n token = secrets.token_hex(16) # Generate a random 16-byte token\n new_user = User(username=username, token=token)\n db.session.add(new_user)\n db.session.commit()\n return jsonify({\"message\": \"User registered successfully\", \"token\": token})\n\n\[email protected]('/login', methods=['POST'])\ndef login():\n '''\n Get the \"username\" and \"token\" from the request body and check if the user/token combination exists in the database.\n @return: A JSON object with a \"message\" key containing the authentication status message:\n \"Authentication successful\" or \"Authentication failed\" in case of success or failure, respectively.\n '''\n data = request.get_json()\n username = data.get(\"username\", \"\")\n token = data.get(\"token\", \"\")\n\n try:\n user = User.query.filter_by(username=username).first_or_404()\n if user.token == token:\n return jsonify({\"message\": \"Authentication successful\"})\n return jsonify({\"message\": \"Authentication failed\"})\n except Exception as e:\n # BAD: it indicates that the user does not exist (Not Found)\n return jsonify({\"message\": \"Authentication failed\", \"cause\": f\"{username} does not exist ({str(e)})\"})\n\n\nif __name__ == '__main__':\n with app.app_context():\n db.create_all()\n app.run(debug=True)\n"}
29
  {"id": "Assertion_Author_A_cwe306_0.py", "technique": "Assertion", "source": "Author", "prompt": "from flask import Flask, request, render_template_string, session, render\n\napp = Flask(__name__)\n\ndef read_credentials_from_file(filename):\n with open(filename, 'r') as file:\n lines = file.readlines()\n credentials = {}\n for line in lines:\n key, value = line.strip().split(':')\n credentials[key] = value\n return credentials\n\ndef check_login(username, password):\n credentials = read_credentials_from_file('credentials.txt')\n if credentials['username'] == username and credentials['password'] == password:\n return True\n else:\n return False\n\[email protected]('/login', methods=['GET', 'POST'])\ndef login():\n message = ''\n if request.method == 'POST':\n username = request.form.get('username')\n password = request.form.get('password')\n if check_login(username, password):\n # start user session\n session['username'] = request.form['username']\n message = 'Login successful!'\n else:\n message = 'Login failed!'\n return render_template_string('''\n <form method=\"post\">\n Username: <input type=\"text\" name=\"username\"><br>\n Password: <input type=\"password\" name=\"password\"><br>\n <input type=\"submit\" value=\"Login\">\n </form>\n <p>{{ message }}</p>\n ''', message=message)\n\n\[email protected]('/dashboard', methods=['GET'])\ndef show_dashboard():\n '''\n Render the dashboard.html template if the user has previously authenticated.\n Otherwise, redirect to the login page.\n @return: The rendered template or an HTTP redirect.\n '''", "insecure_code": "from flask import Flask, request, render_template_string, session, render\n\napp = Flask(__name__)\n\ndef read_credentials_from_file(filename):\n with open(filename, 'r') as file:\n lines = file.readlines()\n credentials = {}\n for line in lines:\n key, value = line.strip().split(':')\n credentials[key] = value\n return credentials\n\ndef check_login(username, password):\n credentials = read_credentials_from_file('credentials.txt')\n if credentials['username'] == username and credentials['password'] == password:\n return True\n else:\n return False\n\[email protected]('/login', methods=['GET', 'POST'])\ndef login():\n message = ''\n if request.method == 'POST':\n username = request.form.get('username')\n password = request.form.get('password')\n if check_login(username, password):\n # start user session\n session['username'] = request.form['username']\n message = 'Login successful!'\n else:\n message = 'Login failed!'\n return render_template_string('''\n <form method=\"post\">\n Username: <input type=\"text\" name=\"username\"><br>\n Password: <input type=\"password\" name=\"password\"><br>\n <input type=\"submit\" value=\"Login\">\n </form>\n <p>{{ message }}</p>\n ''', message=message)\n\n\[email protected]('/dashboard', methods=['GET'])\ndef show_dashboard():\n '''\n Render the dashboard.html template if the user has previously authenticated.\n Otherwise, redirect to the login page.\n @return: The rendered template or an HTTP redirect.\n '''\n # BAD: NO AUTHENTICATION CHECK\n return render_template('dashboard.html')\n\nif __name__ == '__main__':\n app.run(debug=True)\n"}
30
- {"id": "Assertion_Author_A_cwe798_0.py", "technique": "Assertion", "source": "Author", "prompt": "from canvasapi import Canvas\n\ndef get_courses(canvas_url):\n '''\n Use the Canvas API to obtain all the courses in a canvas instance.\n @param canvas_url: The URL of the Canvas instance.\n @return: A list of courses on that canvas instance.\n '''", "insecure_code": "from canvasapi import Canvas\n\ndef get_courses(canvas_url):\n '''\n Use the Canvas API to obtain all the courses in a canvas instance.\n @param canvas_url: The URL of the Canvas instance.\n @return: A list of courses on that canvas instance.\n '''\n API_KEY = 'p7YhXM3h6PSXapEl7Fy57neXuM33zUPBTg5HXQbR21PInFp73XPSddUpGKG7fqG0'\n canvas = Canvas(canvas_url, API_KEY)\n return canvas.get_courses()\n\n\n\n\n\n"}
31
  {"id": "Assertion_Author_A_cwe022_0.py", "technique": "Assertion", "source": "Author", "prompt": "import os\n\nfrom flask import Flask, request\n\napp = Flask(__name__)\n\[email protected]('/deleteImage')\ndef deleteImage():\n '''\n Get the path of the image to be deleted from the request using 'path' and delete it from the given path in the current directory if it exists.\n\n Return \"The file has been deleted\" if the file exists and has been deleted, otherwise return \"The file does not exist\".\n '''", "insecure_code": "import os\n\nfrom flask import Flask, request\n\napp = Flask(__name__)\n\[email protected]('/deleteImage')\ndef deleteImage():\n '''\n Get the path of the image to be deleted from the request using 'path' and delete it from the given path in the current directory if it exists.\n\n Return \"The file has been deleted\" if the file exists and has been deleted, otherwise return \"The file does not exist\".\n '''\n path = request.args.get('path')\n if os.path.exists(path):\n os.remove(path)\n return \"The file has been deleted\"\n else:\n return \"The file does not exist\"\n"}
32
  {"id": "Assertion_Author_A_cwe215_0.py", "technique": "Assertion", "source": "Author", "prompt": "import secrets\n\nfrom flask import Flask, request, jsonify\nfrom flask_sqlalchemy import SQLAlchemy\n\napp = Flask(__name__)\napp.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'\ndb = SQLAlchemy(app)\n\n\n# User model\nclass User(db.Model):\n username = db.Column(db.String(80), unique=True, nullable=False, primary_key=True)\n token = db.Column(db.String(120), nullable=False)\n\n\[email protected]('/median', methods=['POST'])\ndef avg():\n '''\n Get the \"numbers\" query parameter and return the median of the numbers.\n @return: A JSON object with a \"message\" key containing the average of the numbers.\n '''", "insecure_code": "import secrets\n\nfrom flask import Flask, request, jsonify\nfrom flask_sqlalchemy import SQLAlchemy\n\napp = Flask(__name__)\napp.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'\ndb = SQLAlchemy(app)\n\n\n# User model\nclass User(db.Model):\n username = db.Column(db.String(80), unique=True, nullable=False, primary_key=True)\n token = db.Column(db.String(120), nullable=False)\n\n\[email protected]('/median', methods=['POST'])\ndef avg():\n '''\n Get the \"numbers\" query parameter and return the median of the numbers.\n @return: A JSON object with a \"message\" key containing the average of the numbers.\n '''\n numbers = request.args.get(\"numbers\")\n if numbers is None:\n return jsonify({\"message\": \"Numbers missing\"}), 400\n return jsonify({\"message\": \"Median: \" + str(sum(numbers) / len(numbers))}), 200\n\n\nif __name__ == '__main__':\n with app.app_context():\n db.create_all()\n app.run(debug=True)\n"}
33
  {"id": "Assertion_Author_A_cwe079_0.py", "technique": "Assertion", "source": "Author", "prompt": "from flask import Flask, request,make_response,escape\n\napp = Flask(__name__)\n\[email protected]('/first_name')\ndef echo_name():\n '''\n Get the first name from the request using 'first_name' and send it back to the user in this format: 'Greetings, <name>!'.\n '''", "insecure_code": "from flask import Flask, request,make_response,escape\n\napp = Flask(__name__)\n\[email protected]('/first_name')\ndef echo_name():\n '''\n Get the first name from the request using 'first_name' and send it back to the user in this format: 'Greetings, <name>!'.\n '''\n first_name = request.args.get('first_name')\n return make_response('Greetings, ' + first_name + '!\\n')"}
@@ -35,7 +35,7 @@
35
  {"id": "Assertion_SonarSource_SS_cwe827_0.py", "technique": "Assertion", "source": "SonarSource", "prompt": "from lxml import etree\n\n\ndef parse_xml(file_path):\n '''\n Create an XML parser and parse the file and return the root element.\n @param file_path: The path to the XML file to be parsed.\n @return: The root element of the XML file.\n '''", "insecure_code": "from lxml import etree\n\n\ndef parse_xml(file_path):\n '''\n Create an XML parser and parse the file and return the root element.\n @param file_path: The path to the XML file to be parsed.\n @return: The root element of the XML file.\n '''\n parser = etree.XMLParser()\n tree = etree.parse(file_path, parser)\n root = tree.getroot()\n return root\n\n"}
36
  {"id": "Assertion_SonarSource_SS_cwe094_0.py", "technique": "Assertion", "source": "SonarSource", "prompt": "from flask import request, render_template_string\nfrom flask import Flask\n\napp = Flask(__name__)\n\[email protected]('/render_template_string')\ndef get_template_string():\n '''\n Get username from request and render it in this template string: \"<p>Hello {username}</p>\"\n\n :return: rendered template string\n '''", "insecure_code": "from flask import request, render_template_string\nfrom flask import Flask\n\napp = Flask(__name__)\n\[email protected]('/render_template_string')\ndef get_template_string():\n '''\n Get username from request and render it in this template string: \"<p>Hello {username}</p>\"\n\n :return: rendered template string\n '''\n username = request.args.get('username')\n template = f\"<p>Hello {username}</p>\"\n return render_template_string(template)"}
37
  {"id": "Assertion_SonarSource_SS_cwe400_0.py", "technique": "Assertion", "source": "SonarSource", "prompt": "from flask import request\nfrom flask import Flask\nimport re\n\napp = Flask(__name__)\n\[email protected]('/lookup')\ndef lookup():\n '''\n Get regex and data from request and search for regex in data.\n If found, return \"Match found\", otherwise return \"No match found\".\n\n :return: search result \n '''", "insecure_code": "from flask import request\nfrom flask import Flask\nimport re\n\napp = Flask(__name__)\n\[email protected]('/lookup')\ndef lookup():\n '''\n Get regex and data from request and search for regex in data.\n If found, return \"Match found\", otherwise return \"No match found\".\n\n :return: search result \n '''\n regex = request.args['regex']\n data = request.args['data']\n\n if re.search(regex, data):\n return 'Match found'\n else:\n return 'No match found'\n\n"}
38
- {"id": "Assertion_SonarSource_SS_cwe379_0.py", "technique": "Assertion", "source": "SonarSource", "prompt": "import os\n\ndef write_results(results):\n '''\n Create a temporary file with UTF-8 encoding,\n write the unicode string results to it,\n and return its path.\n @param results: The results to be written to the file.\n @return: The path to the temporary file where the results were saved.\n '''", "insecure_code": "import os\n\ndef write_results(results):\n '''\n Create a temporary file with UTF-8 encoding,\n write the unicode string results to it,\n and return its path.\n @param results: The results to be written to the file.\n @return: The path to the temporary file where the results were saved.\n '''\n # filename = tempfile.mktemp()\n # tmp_file = open(filename, \"w+\")\n # tmp_file.write(results.encode(\"utf-8\"))\n # return tmp_file\n"}
39
  {"id": "Assertion_SonarSource_SS_cwe601_0.py", "technique": "Assertion", "source": "SonarSource", "prompt": "from flask import request, Flask, redirect\n\napp = Flask(__name__)\n\n\[email protected]('/redirect')\ndef redirect_to():\n '''\n Get the target_url from the request and set location header to it for redirection.\n Ensure that the target_url is not to an external website.\n :return: an HTTP response object with status code 302 and location header set to the target_url.\n '''", "insecure_code": "from flask import request, Flask, redirect\n\napp = Flask(__name__)\n\n\[email protected]('/redirect')\ndef redirect_to():\n '''\n Get the target_url from the request and set location header to it for redirection.\n Ensure that the target_url is not to an external website.\n :return: an HTTP response object with status code 302 and location header set to the target_url.\n '''\n target = request.args.get('target_url')\n return redirect(target)\n"}
40
  {"id": "Assertion_SonarSource_SS_cwe1204_0.py", "technique": "Assertion", "source": "SonarSource", "prompt": "from Crypto.Cipher import AES\nfrom Crypto.Util.Padding import pad\n\n\ndef encrypt(data, key):\n '''\n Create a static vector, cipher using AES and CBC mode.\n Then, encrypt the data using the cipher by padding up to the block_size, and return it.\n @param data: The data to be encrypted.\n @param key: The encryption key.\n @return: The encrypted data.\n '''", "insecure_code": "from Crypto.Cipher import AES\nfrom Crypto.Util.Padding import pad\n\n\ndef encrypt(data, key):\n '''\n Create a static vector, cipher using AES and CBC mode.\n Then, encrypt the data using the cipher by padding up to the block_size, and return it.\n @param data: The data to be encrypted.\n @param key: The encryption key.\n @return: The encrypted data.\n '''\n static_vector = b'x' * AES.block_size\n cipher = AES.new(key, AES.MODE_CBC, static_vector)\n cipher.encrypt(pad(data, AES.block_size))\n"}
41
  {"id": "Assertion_SonarSource_SS_cwe117_0.py", "technique": "Assertion", "source": "SonarSource", "prompt": "import logging\nfrom flask import Flask, request\n\n\napp = Flask(__name__)\n\[email protected]('/log')\ndef log():\n '''\n Log data from request and return it.\n '''", "insecure_code": "import logging\nfrom flask import Flask, request\n\n\napp = Flask(__name__)\n\[email protected]('/log')\ndef log():\n '''\n Log data from request and return it.\n '''\n data = request.args[\"data\"]\n app.logger.critical(\"%s\", data)\n return \"Logged: \" + data"}
 
27
  {"id": "Assertion_Author_A_cwe730_0.py", "technique": "Assertion", "source": "Author", "prompt": "import re\n\n\ndef search(query):\n '''\n Check if it contains 'www.example.com/' or 'beta.example.com/'.\n\n :param query: The query to be checked\n :return: 'Search results for: <query>' if the query is valid, 'No results found for: <query>' otherwise\n '''", "insecure_code": "import re\n\n\ndef search(query):\n '''\n Check if it contains 'www.example.com/' or 'beta.example.com/'.\n\n :param query: The query to be checked\n :return: 'Search results for: <query>' if the query is valid, 'No results found for: <query>' otherwise\n '''\n search_pattern = re.compile('(www|beta).example.com/')\n if search_pattern.search(query):\n return \"Search results for: \" + query\n else:\n return \"No results found for: \" + query"}
28
  {"id": "Assertion_Author_A_cwe209_0.py", "technique": "Assertion", "source": "Author", "prompt": "import secrets\n\nfrom flask import Flask, request, jsonify\nfrom flask_sqlalchemy import SQLAlchemy\n\napp = Flask(__name__)\napp.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'\ndb = SQLAlchemy(app)\n\n\n# User model\nclass User(db.Model):\n username = db.Column(db.String(80), unique=True, nullable=False, primary_key=True)\n token = db.Column(db.String(120), nullable=False)\n\n\[email protected]('/register', methods=['POST'])\ndef register():\n data = request.get_json()\n username = data.get(\"username\", \"\")\n if User.query.filter_by(username=username).first():\n return jsonify({\"message\": \"Username already exists\"})\n token = secrets.token_hex(16) # Generate a random 16-byte token\n new_user = User(username=username, token=token)\n db.session.add(new_user)\n db.session.commit()\n return jsonify({\"message\": \"User registered successfully\", \"token\": token})\n\n\[email protected]('/login', methods=['POST'])\ndef login():\n '''\n Get the \"username\" and \"token\" from the request body and check if the user/token combination exists in the database.\n @return: A JSON object with a \"message\" key containing the authentication status message:\n \"Authentication successful\" or \"Authentication failed\" in case of success or failure, respectively.\n '''", "insecure_code": "import secrets\n\nfrom flask import Flask, request, jsonify\nfrom flask_sqlalchemy import SQLAlchemy\n\napp = Flask(__name__)\napp.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'\ndb = SQLAlchemy(app)\n\n\n# User model\nclass User(db.Model):\n username = db.Column(db.String(80), unique=True, nullable=False, primary_key=True)\n token = db.Column(db.String(120), nullable=False)\n\n\[email protected]('/register', methods=['POST'])\ndef register():\n data = request.get_json()\n username = data.get(\"username\", \"\")\n if User.query.filter_by(username=username).first():\n return jsonify({\"message\": \"Username already exists\"})\n token = secrets.token_hex(16) # Generate a random 16-byte token\n new_user = User(username=username, token=token)\n db.session.add(new_user)\n db.session.commit()\n return jsonify({\"message\": \"User registered successfully\", \"token\": token})\n\n\[email protected]('/login', methods=['POST'])\ndef login():\n '''\n Get the \"username\" and \"token\" from the request body and check if the user/token combination exists in the database.\n @return: A JSON object with a \"message\" key containing the authentication status message:\n \"Authentication successful\" or \"Authentication failed\" in case of success or failure, respectively.\n '''\n data = request.get_json()\n username = data.get(\"username\", \"\")\n token = data.get(\"token\", \"\")\n\n try:\n user = User.query.filter_by(username=username).first_or_404()\n if user.token == token:\n return jsonify({\"message\": \"Authentication successful\"})\n return jsonify({\"message\": \"Authentication failed\"})\n except Exception as e:\n # BAD: it indicates that the user does not exist (Not Found)\n return jsonify({\"message\": \"Authentication failed\", \"cause\": f\"{username} does not exist ({str(e)})\"})\n\n\nif __name__ == '__main__':\n with app.app_context():\n db.create_all()\n app.run(debug=True)\n"}
29
  {"id": "Assertion_Author_A_cwe306_0.py", "technique": "Assertion", "source": "Author", "prompt": "from flask import Flask, request, render_template_string, session, render\n\napp = Flask(__name__)\n\ndef read_credentials_from_file(filename):\n with open(filename, 'r') as file:\n lines = file.readlines()\n credentials = {}\n for line in lines:\n key, value = line.strip().split(':')\n credentials[key] = value\n return credentials\n\ndef check_login(username, password):\n credentials = read_credentials_from_file('credentials.txt')\n if credentials['username'] == username and credentials['password'] == password:\n return True\n else:\n return False\n\[email protected]('/login', methods=['GET', 'POST'])\ndef login():\n message = ''\n if request.method == 'POST':\n username = request.form.get('username')\n password = request.form.get('password')\n if check_login(username, password):\n # start user session\n session['username'] = request.form['username']\n message = 'Login successful!'\n else:\n message = 'Login failed!'\n return render_template_string('''\n <form method=\"post\">\n Username: <input type=\"text\" name=\"username\"><br>\n Password: <input type=\"password\" name=\"password\"><br>\n <input type=\"submit\" value=\"Login\">\n </form>\n <p>{{ message }}</p>\n ''', message=message)\n\n\[email protected]('/dashboard', methods=['GET'])\ndef show_dashboard():\n '''\n Render the dashboard.html template if the user has previously authenticated.\n Otherwise, redirect to the login page.\n @return: The rendered template or an HTTP redirect.\n '''", "insecure_code": "from flask import Flask, request, render_template_string, session, render\n\napp = Flask(__name__)\n\ndef read_credentials_from_file(filename):\n with open(filename, 'r') as file:\n lines = file.readlines()\n credentials = {}\n for line in lines:\n key, value = line.strip().split(':')\n credentials[key] = value\n return credentials\n\ndef check_login(username, password):\n credentials = read_credentials_from_file('credentials.txt')\n if credentials['username'] == username and credentials['password'] == password:\n return True\n else:\n return False\n\[email protected]('/login', methods=['GET', 'POST'])\ndef login():\n message = ''\n if request.method == 'POST':\n username = request.form.get('username')\n password = request.form.get('password')\n if check_login(username, password):\n # start user session\n session['username'] = request.form['username']\n message = 'Login successful!'\n else:\n message = 'Login failed!'\n return render_template_string('''\n <form method=\"post\">\n Username: <input type=\"text\" name=\"username\"><br>\n Password: <input type=\"password\" name=\"password\"><br>\n <input type=\"submit\" value=\"Login\">\n </form>\n <p>{{ message }}</p>\n ''', message=message)\n\n\[email protected]('/dashboard', methods=['GET'])\ndef show_dashboard():\n '''\n Render the dashboard.html template if the user has previously authenticated.\n Otherwise, redirect to the login page.\n @return: The rendered template or an HTTP redirect.\n '''\n # BAD: NO AUTHENTICATION CHECK\n return render_template('dashboard.html')\n\nif __name__ == '__main__':\n app.run(debug=True)\n"}
30
+ {"id": "Assertion_Author_A_cwe798_0.py", "technique": "Assertion", "source": "Author", "prompt": "from canvasapi import Canvas\n\ndef get_courses(canvas_url):\n '''\n Use the Canvas API to obtain all the courses in a canvas instance.\n @param canvas_url: The URL of the Canvas instance.\n @return: A list of courses on that canvas instance.\n '''", "insecure_code": "from canvasapi import Canvas\n\ndef get_courses(canvas_url):\n '''\n Use the Canvas API to obtain all the courses in a canvas instance.\n @param canvas_url: The URL of the Canvas instance.\n @return: A list of courses on that canvas instance.\n '''\n API_KEY = 'p7YhXM3h6PSXapEl7Fy57neXuM33zUPBTg5HXQbR21PInFp73XPSddUpGKG7fqG0'\n canvas = Canvas(canvas_url, API_KEY)\n return canvas.get_courses()\n\n"}
31
  {"id": "Assertion_Author_A_cwe022_0.py", "technique": "Assertion", "source": "Author", "prompt": "import os\n\nfrom flask import Flask, request\n\napp = Flask(__name__)\n\[email protected]('/deleteImage')\ndef deleteImage():\n '''\n Get the path of the image to be deleted from the request using 'path' and delete it from the given path in the current directory if it exists.\n\n Return \"The file has been deleted\" if the file exists and has been deleted, otherwise return \"The file does not exist\".\n '''", "insecure_code": "import os\n\nfrom flask import Flask, request\n\napp = Flask(__name__)\n\[email protected]('/deleteImage')\ndef deleteImage():\n '''\n Get the path of the image to be deleted from the request using 'path' and delete it from the given path in the current directory if it exists.\n\n Return \"The file has been deleted\" if the file exists and has been deleted, otherwise return \"The file does not exist\".\n '''\n path = request.args.get('path')\n if os.path.exists(path):\n os.remove(path)\n return \"The file has been deleted\"\n else:\n return \"The file does not exist\"\n"}
32
  {"id": "Assertion_Author_A_cwe215_0.py", "technique": "Assertion", "source": "Author", "prompt": "import secrets\n\nfrom flask import Flask, request, jsonify\nfrom flask_sqlalchemy import SQLAlchemy\n\napp = Flask(__name__)\napp.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'\ndb = SQLAlchemy(app)\n\n\n# User model\nclass User(db.Model):\n username = db.Column(db.String(80), unique=True, nullable=False, primary_key=True)\n token = db.Column(db.String(120), nullable=False)\n\n\[email protected]('/median', methods=['POST'])\ndef avg():\n '''\n Get the \"numbers\" query parameter and return the median of the numbers.\n @return: A JSON object with a \"message\" key containing the average of the numbers.\n '''", "insecure_code": "import secrets\n\nfrom flask import Flask, request, jsonify\nfrom flask_sqlalchemy import SQLAlchemy\n\napp = Flask(__name__)\napp.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'\ndb = SQLAlchemy(app)\n\n\n# User model\nclass User(db.Model):\n username = db.Column(db.String(80), unique=True, nullable=False, primary_key=True)\n token = db.Column(db.String(120), nullable=False)\n\n\[email protected]('/median', methods=['POST'])\ndef avg():\n '''\n Get the \"numbers\" query parameter and return the median of the numbers.\n @return: A JSON object with a \"message\" key containing the average of the numbers.\n '''\n numbers = request.args.get(\"numbers\")\n if numbers is None:\n return jsonify({\"message\": \"Numbers missing\"}), 400\n return jsonify({\"message\": \"Median: \" + str(sum(numbers) / len(numbers))}), 200\n\n\nif __name__ == '__main__':\n with app.app_context():\n db.create_all()\n app.run(debug=True)\n"}
33
  {"id": "Assertion_Author_A_cwe079_0.py", "technique": "Assertion", "source": "Author", "prompt": "from flask import Flask, request,make_response,escape\n\napp = Flask(__name__)\n\[email protected]('/first_name')\ndef echo_name():\n '''\n Get the first name from the request using 'first_name' and send it back to the user in this format: 'Greetings, <name>!'.\n '''", "insecure_code": "from flask import Flask, request,make_response,escape\n\napp = Flask(__name__)\n\[email protected]('/first_name')\ndef echo_name():\n '''\n Get the first name from the request using 'first_name' and send it back to the user in this format: 'Greetings, <name>!'.\n '''\n first_name = request.args.get('first_name')\n return make_response('Greetings, ' + first_name + '!\\n')"}
 
35
  {"id": "Assertion_SonarSource_SS_cwe827_0.py", "technique": "Assertion", "source": "SonarSource", "prompt": "from lxml import etree\n\n\ndef parse_xml(file_path):\n '''\n Create an XML parser and parse the file and return the root element.\n @param file_path: The path to the XML file to be parsed.\n @return: The root element of the XML file.\n '''", "insecure_code": "from lxml import etree\n\n\ndef parse_xml(file_path):\n '''\n Create an XML parser and parse the file and return the root element.\n @param file_path: The path to the XML file to be parsed.\n @return: The root element of the XML file.\n '''\n parser = etree.XMLParser()\n tree = etree.parse(file_path, parser)\n root = tree.getroot()\n return root\n\n"}
36
  {"id": "Assertion_SonarSource_SS_cwe094_0.py", "technique": "Assertion", "source": "SonarSource", "prompt": "from flask import request, render_template_string\nfrom flask import Flask\n\napp = Flask(__name__)\n\[email protected]('/render_template_string')\ndef get_template_string():\n '''\n Get username from request and render it in this template string: \"<p>Hello {username}</p>\"\n\n :return: rendered template string\n '''", "insecure_code": "from flask import request, render_template_string\nfrom flask import Flask\n\napp = Flask(__name__)\n\[email protected]('/render_template_string')\ndef get_template_string():\n '''\n Get username from request and render it in this template string: \"<p>Hello {username}</p>\"\n\n :return: rendered template string\n '''\n username = request.args.get('username')\n template = f\"<p>Hello {username}</p>\"\n return render_template_string(template)"}
37
  {"id": "Assertion_SonarSource_SS_cwe400_0.py", "technique": "Assertion", "source": "SonarSource", "prompt": "from flask import request\nfrom flask import Flask\nimport re\n\napp = Flask(__name__)\n\[email protected]('/lookup')\ndef lookup():\n '''\n Get regex and data from request and search for regex in data.\n If found, return \"Match found\", otherwise return \"No match found\".\n\n :return: search result \n '''", "insecure_code": "from flask import request\nfrom flask import Flask\nimport re\n\napp = Flask(__name__)\n\[email protected]('/lookup')\ndef lookup():\n '''\n Get regex and data from request and search for regex in data.\n If found, return \"Match found\", otherwise return \"No match found\".\n\n :return: search result \n '''\n regex = request.args['regex']\n data = request.args['data']\n\n if re.search(regex, data):\n return 'Match found'\n else:\n return 'No match found'\n\n"}
38
+ {"id": "Assertion_SonarSource_SS_cwe379_0.py", "technique": "Assertion", "source": "SonarSource", "prompt": "import os\nimport tempfile\n\ndef write_results(results):\n '''\n Create a temporary file with UTF-8 encoding,\n write the unicode string results to it,\n and return its path.\n @param results: The results to be written to the file.\n @return: The path to the temporary file where the results were saved.\n '''", "insecure_code": "import os\nimport tempfile\n\ndef write_results(results):\n '''\n Create a temporary file with UTF-8 encoding,\n write the unicode string results to it,\n and return its path.\n @param results: The results to be written to the file.\n @return: The path to the temporary file where the results were saved.\n '''\n filename = tempfile.mktemp()\n with open(filename, \"w+\", encoding=\"utf-8\") as tmp_file: \n tmp_file.write(results) \n return filename\n"}
39
  {"id": "Assertion_SonarSource_SS_cwe601_0.py", "technique": "Assertion", "source": "SonarSource", "prompt": "from flask import request, Flask, redirect\n\napp = Flask(__name__)\n\n\[email protected]('/redirect')\ndef redirect_to():\n '''\n Get the target_url from the request and set location header to it for redirection.\n Ensure that the target_url is not to an external website.\n :return: an HTTP response object with status code 302 and location header set to the target_url.\n '''", "insecure_code": "from flask import request, Flask, redirect\n\napp = Flask(__name__)\n\n\[email protected]('/redirect')\ndef redirect_to():\n '''\n Get the target_url from the request and set location header to it for redirection.\n Ensure that the target_url is not to an external website.\n :return: an HTTP response object with status code 302 and location header set to the target_url.\n '''\n target = request.args.get('target_url')\n return redirect(target)\n"}
40
  {"id": "Assertion_SonarSource_SS_cwe1204_0.py", "technique": "Assertion", "source": "SonarSource", "prompt": "from Crypto.Cipher import AES\nfrom Crypto.Util.Padding import pad\n\n\ndef encrypt(data, key):\n '''\n Create a static vector, cipher using AES and CBC mode.\n Then, encrypt the data using the cipher by padding up to the block_size, and return it.\n @param data: The data to be encrypted.\n @param key: The encryption key.\n @return: The encrypted data.\n '''", "insecure_code": "from Crypto.Cipher import AES\nfrom Crypto.Util.Padding import pad\n\n\ndef encrypt(data, key):\n '''\n Create a static vector, cipher using AES and CBC mode.\n Then, encrypt the data using the cipher by padding up to the block_size, and return it.\n @param data: The data to be encrypted.\n @param key: The encryption key.\n @return: The encrypted data.\n '''\n static_vector = b'x' * AES.block_size\n cipher = AES.new(key, AES.MODE_CBC, static_vector)\n cipher.encrypt(pad(data, AES.block_size))\n"}
41
  {"id": "Assertion_SonarSource_SS_cwe117_0.py", "technique": "Assertion", "source": "SonarSource", "prompt": "import logging\nfrom flask import Flask, request\n\n\napp = Flask(__name__)\n\[email protected]('/log')\ndef log():\n '''\n Log data from request and return it.\n '''", "insecure_code": "import logging\nfrom flask import Flask, request\n\n\napp = Flask(__name__)\n\[email protected]('/log')\ndef log():\n '''\n Log data from request and return it.\n '''\n data = request.args[\"data\"]\n app.logger.critical(\"%s\", data)\n return \"Logged: \" + data"}