-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db0a008
commit d394942
Showing
3 changed files
with
252 additions
and
17 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
src/core_codemods/docs/pixee_python_sql-parameterization.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
This codemod refactors SQL statements to be parameterized, rather than built by hand. | ||
|
||
Without parameterization, developers must remember to escape string inputs using the rules for that column type and database. This usually results in bugs -- and sometimes vulnerability. Although it's not clear if this code is exploitable today, this change will make the code more robust in case the conditions which prevent exploitation today ever go away. | ||
|
||
Our changes look something like this: | ||
|
||
```diff | ||
import sqlite3 | ||
|
||
name = input() | ||
connection = sqlite3.connect("my_db.db") | ||
cursor = connection.cursor() | ||
- cursor.execute("SELECT * from USERS WHERE name ='" + name + "'") | ||
+ cursor.execute("SELECT * from USERS WHERE name =?", (name, )) | ||
``` | ||
|
||
If you have feedback on this codemod, [please let us know](mailto:[email protected])! | ||
|
||
## F.A.Q. | ||
|
||
### Why is this codemod marked as Merge With Cursory Review | ||
|
||
Python has a wealth of database drivers that all use the same interface. Different drivers may require different string tokens used for parameterization, and Python's dynamic typing makes it quite hard, and sometimes impossible, to detect which driver is being used just by looking at the code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters