Skip to content

Commit f14f7b5

Browse files
committed
Python: Use ModuleObject::named more consistently.
1 parent c643728 commit f14f7b5

File tree

19 files changed

+28
-31
lines changed

19 files changed

+28
-31
lines changed

python/ql/src/Security/CWE-295/RequestWithoutValidation.ql

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ import semmle.python.web.Http
1515

1616

1717
FunctionObject requestFunction() {
18-
exists(ModuleObject req |
19-
req.getName() = "requests" and
20-
result = req.attr(httpVerbLower())
21-
)
18+
result = ModuleObject::named("requests").attr(httpVerbLower())
2219
}
2320

2421
/** requests treats None as the default and all other "falsey" values as False */

python/ql/src/Security/CWE-327/InsecureDefaultProtocol.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
import python
1414

1515
FunctionObject ssl_wrap_socket() {
16-
result = any(ModuleObject ssl | ssl.getName() = "ssl").attr("wrap_socket")
16+
result = ModuleObject::named("ssl").attr("wrap_socket")
1717
}
1818

1919
ClassObject ssl_Context_class() {
20-
result = any(ModuleObject ssl | ssl.getName() = "ssl").attr("SSLContext")
20+
result = ModuleObject::named("ssl").attr("SSLContext")
2121
}
2222

2323
CallNode unsafe_call(string method_name) {

python/ql/src/Security/CWE-327/InsecureProtocol.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ string insecure_version_name() {
3434
}
3535

3636
private ModuleObject the_ssl_module() {
37-
result = any(ModuleObject m | m.getName() = "ssl")
37+
result = ModuleObject::named("ssl")
3838
}
3939

4040
private ModuleObject the_pyOpenSSL_module() {
41-
result = any(ModuleObject m | m.getName() = "pyOpenSSL.SSL")
41+
result = ModuleObject::named("pyOpenSSL.SSL")
4242
}
4343

4444
/* A syntactic check for cases where points-to analysis cannot infer the presence of
@@ -76,7 +76,7 @@ predicate unsafe_ssl_wrap_socket_call(CallNode call, string method_name, string
7676
}
7777

7878
ClassObject the_pyOpenSSL_Context_class() {
79-
result = any(ModuleObject m | m.getName() = "pyOpenSSL.SSL").attr("Context")
79+
result = ModuleObject::named("pyOpenSSL.SSL").attr("Context")
8080
}
8181

8282
predicate unsafe_pyOpenSSL_Context_call(CallNode call, string insecure_version) {

python/ql/src/Security/CWE-377/InsecureTemporaryFile.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ FunctionObject temporary_name_function(string mod, string function) {
2323
function = "tempnam"
2424
)
2525
) and
26-
result = any(ModuleObject m | m.getName() = mod).getAttribute(function)
26+
result = ModuleObject::named(mod).getAttribute(function)
2727
}
2828

2929
from Call c, string mod, string function

python/ql/src/Security/CWE-732/WeakFilePermissions.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ string permissive_permission(int p) {
3535
}
3636

3737
predicate chmod_call(CallNode call, FunctionObject chmod, NumericObject num) {
38-
any(ModuleObject os | os.getName() = "os").attr("chmod") = chmod and
38+
ModuleObject::named("os").attr("chmod") = chmod and
3939
chmod.getACall() = call and call.getArg(1).refersTo(num)
4040
}
4141

4242
predicate open_call(CallNode call, FunctionObject open, NumericObject num) {
43-
any(ModuleObject os | os.getName() = "os").attr("open") = open and
43+
ModuleObject::named("os").attr("open") = open and
4444
open.getACall() = call and call.getArg(2).refersTo(num)
4545
}
4646

python/ql/src/Security/CWE-798/HardcodedCredentials.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ predicate possible_reflective_name(string name) {
4040
or
4141
any(ClassObject c).getName() = name
4242
or
43-
any(ModuleObject m).getName() = name
43+
exists(ModuleObject::named(name))
4444
or
4545
exists(Object::builtin(name))
4646
}

python/ql/src/semmle/python/security/injection/Command.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class ShellCommand extends TaintSink {
8383
or
8484
exists(CallNode call |
8585
call.getAnArg() = this and
86-
call.getFunction().refersTo(any(ModuleObject commands | commands.getName() = "commands"))
86+
call.getFunction().refersTo(ModuleObject::named("commands"))
8787
)
8888
}
8989

python/ql/src/semmle/python/security/strings/External.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private predicate json_subscript_taint(SubscriptNode sub, ControlFlowNode obj, E
9191

9292
private predicate json_load(ControlFlowNode fromnode, CallNode tonode) {
9393
exists(FunctionObject json_loads |
94-
any(ModuleObject json | json.getName() = "json").attr("loads") = json_loads and
94+
ModuleObject::named("json").attr("loads") = json_loads and
9595
json_loads.getACall() = tonode and tonode.getArg(0) = fromnode
9696
)
9797
}

python/ql/src/semmle/python/web/bottle/General.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ModuleObject theBottleModule() {
99

1010
/** The bottle.Bottle class */
1111
ClassObject theBottleClass() {
12-
result = ModuleObject::named("bottle").attr("Bottle")
12+
result = theBottleModule().attr("Bottle")
1313
}
1414

1515
/** Holds if `route` is routed to `func`

python/ql/src/semmle/python/web/django/Db.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class DjangoDbCursor extends DbCursor {
1212
}
1313

1414
private Object theDjangoConnectionObject() {
15-
any(ModuleObject m | m.getName() = "django.db").attr("connection") = result
15+
ModuleObject::named("django.db").attr("connection") = result
1616
}
1717

1818
/** A kind of taint source representing sources of django cursor objects.
@@ -38,7 +38,7 @@ class DjangoDbCursorSource extends DbConnectionSource {
3838

3939

4040
ClassObject theDjangoRawSqlClass() {
41-
result = any(ModuleObject m | m.getName() = "django.db.models.expressions").attr("RawSQL")
41+
result = ModuleObject::named("django.db.models.expressions").attr("RawSQL")
4242
}
4343

4444
/**

0 commit comments

Comments
 (0)