Skip to content

Commit eb1be08

Browse files
committed
Python: split modelling
1 parent 2a739b3 commit eb1be08

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Provides classes modeling security-relevant aspects of the PyMongo bindings.
3+
*/
4+
5+
private import python
6+
private import semmle.python.dataflow.new.DataFlow
7+
private import semmle.python.Concepts
8+
private import semmle.python.ApiGraphs
9+
10+
module BSon {
11+
/**
12+
* ObjectId returns a string representing an id.
13+
* If at any time ObjectId can't parse it's input (like when a tainted dict in passed in),
14+
* then ObjectId will throw an error preventing the query from running.
15+
*/
16+
private class BsonObjectIdCall extends DataFlow::CallCfgNode, NoSqlSanitizer::Range {
17+
BsonObjectIdCall() {
18+
exists(API::Node mod |
19+
mod = API::moduleImport("bson")
20+
or
21+
mod = API::moduleImport("bson").getMember(["objectid", "json_util"])
22+
|
23+
this = mod.getMember("ObjectId").getACall()
24+
)
25+
}
26+
27+
override DataFlow::Node getAnInput() { result = this.getArg(0) }
28+
}
29+
}

python/ql/lib/semmle/python/frameworks/PyMongo.qll

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -274,25 +274,6 @@ private module PyMongo {
274274
override DataFlow::Node getAnInput() { result = this.getArg(0) }
275275
}
276276

277-
/**
278-
* ObjectId returns a string representing an id.
279-
* If at any time ObjectId can't parse it's input (like when a tainted dict in passed in),
280-
* then ObjectId will throw an error preventing the query from running.
281-
*/
282-
private class BsonObjectIdCall extends DataFlow::CallCfgNode, NoSqlSanitizer::Range {
283-
BsonObjectIdCall() {
284-
exists(API::Node mod |
285-
mod = API::moduleImport("bson")
286-
or
287-
mod = API::moduleImport("bson").getMember(["objectid", "json_util"])
288-
|
289-
this = mod.getMember("ObjectId").getACall()
290-
)
291-
}
292-
293-
override DataFlow::Node getAnInput() { result = this.getArg(0) }
294-
}
295-
296277
/**
297278
* An equality operator can protect against dictionary interpretation.
298279
* For instance, in `{'password': {"$eq": password} }`, if a dictionary is injected into

0 commit comments

Comments
 (0)