@@ -11,6 +11,9 @@ private import semmle.python.dataflow.new.TaintTracking
11
11
private import semmle.python.ApiGraphs
12
12
private import semmle.python.Concepts
13
13
private import experimental.semmle.python.Concepts
14
+ // This import is done like this to avoid importing the deprecated top-level things that
15
+ // would pollute the namespace
16
+ private import semmle.python.frameworks.PEP249:: PEP249 as PEP249
14
17
15
18
/**
16
19
* Provides models for the `SQLAlchemy` PyPI package.
@@ -128,6 +131,43 @@ private module SqlAlchemy {
128
131
DataFlow:: Node instance ( ) { instance ( DataFlow:: TypeTracker:: end ( ) ) .flowsTo ( result ) }
129
132
}
130
133
134
+ /**
135
+ * Provides models for the underlying DB-API Connection of a SQLAlchemy Connection.
136
+ *
137
+ * See https://docs.sqlalchemy.org/en/14/core/connections.html#dbapi-connections.
138
+ */
139
+ module DBAPIConnection {
140
+ /**
141
+ * A source of instances of DB-API Connections, extend this class to model new instances.
142
+ *
143
+ * This can include instantiations of the class, return values from function
144
+ * calls, or a special parameter that will be set when functions are called by an external
145
+ * library.
146
+ *
147
+ * Use the predicate `DBAPIConnection::instance()` to get references to instances of DB-API Connections.
148
+ */
149
+ abstract class InstanceSource extends DataFlow:: LocalSourceNode { }
150
+
151
+ private class DBAPIConnectionSources extends InstanceSource , PEP249:: Connection:: InstanceSource {
152
+ DBAPIConnectionSources ( ) {
153
+ this .( DataFlow:: MethodCallNode ) .calls ( Engine:: instance ( ) , "raw_connection" )
154
+ or
155
+ this .( DataFlow:: AttrRead ) .accesses ( Connection:: instance ( ) , "connection" )
156
+ }
157
+ }
158
+
159
+ /** Gets a reference to an instance of DB-API Connections. */
160
+ private DataFlow:: TypeTrackingNode instance ( DataFlow:: TypeTracker t ) {
161
+ t .start ( ) and
162
+ result instanceof InstanceSource
163
+ or
164
+ exists ( DataFlow:: TypeTracker t2 | result = instance ( t2 ) .track ( t2 , t ) )
165
+ }
166
+
167
+ /** Gets a reference to an instance of DB-API Connections. */
168
+ DataFlow:: Node instance ( ) { instance ( DataFlow:: TypeTracker:: end ( ) ) .flowsTo ( result ) }
169
+ }
170
+
131
171
/**
132
172
* Provides models for the `sqlalchemy.orm.Session` class
133
173
*
0 commit comments