Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AI code fix examples #170

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ build/
angular/coverage/
dist/
cpp-scan/compile_commands.json
ai-code-fix/python/venv/*
21 changes: 21 additions & 0 deletions ai-code-fix/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Olivier Korach

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 1 addition & 0 deletions ai-code-fix/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# ai-code-fix-examples
5 changes: 5 additions & 0 deletions ai-code-fix/python/fixme-django.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.http import HttpResponseRedirect

def redirect():
url = request.GET.get("url", "/")
return HttpResponseRedirect(url)
17 changes: 17 additions & 0 deletions ai-code-fix/python/fixme-flask.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import sqlite3
from flask import Flask, redirect

app = Flask("example")

@app.route("/redirecting")
def redirecting():
url = request.args["url"]
return redirect(url)

@app.route('/user')
def get_users():
user = request.args["user"]
sql = """SELECT user FROM users WHERE user = \'%s\'"""

conn = sqlite3.connect('example')
conn.cursor().execute(sql % (user)) # Noncompliant
7 changes: 7 additions & 0 deletions ai-code-fix/python/flask-hello.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello_world():
return "<p>Hello, World!</p>"
12 changes: 12 additions & 0 deletions ai-code-fix/python/python-sql-injection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import sqlite3
import flask

app = flask.Flask("example")

@app.route('/user')
def get_users():
user = flask.request.args["user"]
sql = "SELECT user FROM users WHERE user = ?"

conn = sqlite3.connect('example')
conn.cursor().execute(sql, (user,))
3 changes: 3 additions & 0 deletions ai-code-fix/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
django
flask
db-sqlite3
3 changes: 3 additions & 0 deletions ai-code-fix/sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sonar.projectKey=ai-code-fix
sonar.projectName=AI CodeFix examples
sonar.exclusions=venv/**/*