File tree Expand file tree Collapse file tree 3 files changed +34
-0
lines changed
src/semmle/python/frameworks
test/experimental/library-tests/frameworks/stdlib Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ lgtm,codescanning
2+ * Added model of ` sqlite3 ` as SQL interface following PEP249, resulting in additional sinks for ` py/sql-injection ` .
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ private import semmle.python.dataflow.new.DataFlow
88private import semmle.python.dataflow.new.TaintTracking
99private import semmle.python.dataflow.new.RemoteFlowSources
1010private import semmle.python.Concepts
11+ private import PEP249
1112
1213/** Provides models for the Python standard library. */
1314private module Stdlib {
@@ -1080,6 +1081,29 @@ private module Stdlib {
10801081
10811082 override string getFormat ( ) { result = "JSON" }
10821083 }
1084+
1085+ // ---------------------------------------------------------------------------
1086+ // sqlite3
1087+ // ---------------------------------------------------------------------------
1088+ /** Gets a reference to the `sqlite3` module. */
1089+ private DataFlow:: Node sqlite3 ( DataFlow:: TypeTracker t ) {
1090+ t .start ( ) and
1091+ result = DataFlow:: importNode ( "sqlite3" )
1092+ or
1093+ exists ( DataFlow:: TypeTracker t2 | result = sqlite3 ( t2 ) .track ( t2 , t ) )
1094+ }
1095+
1096+ /** Gets a reference to the `sqlite3` module. */
1097+ DataFlow:: Node sqlite3 ( ) { result = sqlite3 ( DataFlow:: TypeTracker:: end ( ) ) }
1098+
1099+ /**
1100+ * sqlite3 implements PEP 249, providing ways to execute SQL statements against a database.
1101+ *
1102+ * See https://devdocs.io/python~3.9/library/sqlite3
1103+ */
1104+ class Sqlite3 extends PEP249Module {
1105+ Sqlite3 ( ) { this = sqlite3 ( ) }
1106+ }
10831107}
10841108
10851109// ---------------------------------------------------------------------------
Original file line number Diff line number Diff line change 1+ import sqlite3
2+ db = sqlite3 .connect ("example.db" )
3+
4+ # non standard
5+ db .execute ("some sql" , (42 ,)) # $ MISSING: getSql="some sql"
6+
7+ cursor = db .cursor ()
8+ cursor .execute ("some sql" , (42 ,)) # $ getSql="some sql"
You can’t perform that action at this time.
0 commit comments