Skip to content

Commit 8b2c74a

Browse files
committed
Python: Modernise remaining Security/*.qll files
1 parent 1495734 commit 8b2c74a

File tree

4 files changed

+29
-32
lines changed

4 files changed

+29
-32
lines changed

python/ql/src/semmle/python/security/ClearText.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module ClearTextLogging {
4343
PrintSink() {
4444
exists(CallNode call |
4545
call.getAnArg() = this and
46-
thePrintFunction().(FunctionObject).getACall() = call
46+
call = Value::named("print").getACall()
4747
)
4848
}
4949
}

python/ql/src/semmle/python/security/Crypto.qll

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@ abstract class WeakCryptoSink extends TaintSink {
1212
}
1313
}
1414

15+
/** Modeling the 'pycrypto' pacakge https://github.com/dlitz/pycrypto (latest release 2013) */
1516
module Pycrypto {
1617

17-
ModuleObject cipher(string name) {
18-
exists(PackageObject crypto |
19-
crypto.getName() = "Crypto.Cipher" |
20-
crypto.submodule(name) = result
21-
)
18+
ModuleValue cipher(string name) {
19+
result = Module::named("Crypto.Cipher").attr(name) and
20+
result.isPackage()
2221
}
2322

2423
class CipherInstance extends TaintKind {
@@ -51,15 +50,15 @@ module Pycrypto {
5150
CipherInstanceSource() {
5251
exists(AttrNode attr |
5352
this.(CallNode).getFunction() = attr and
54-
attr.getObject("new").refersTo(cipher(instance.getName()))
53+
attr.getObject("new").pointsTo(cipher(instance.getName()))
5554
)
5655
}
5756

5857
override string toString() {
5958
result = "Source of " + instance
6059
}
6160

62-
override predicate isSourceOf(TaintKind kind) {
61+
override predicate isSourceOf(TaintKind kind) {
6362
kind = instance
6463
}
6564

@@ -70,12 +69,12 @@ module Pycrypto {
7069
string name;
7170

7271
PycryptoWeakCryptoSink() {
73-
exists(CallNode call, AttrNode method, CipherInstance Cipher |
72+
exists(CallNode call, AttrNode method, CipherInstance cipher |
7473
call.getAnArg() = this and
7574
call.getFunction() = method and
76-
Cipher.taints(method.getObject("encrypt")) and
77-
Cipher.isWeak() and
78-
Cipher.getName() = name
75+
cipher.taints(method.getObject("encrypt")) and
76+
cipher.isWeak() and
77+
cipher.getName() = name
7978
)
8079
}
8180

@@ -89,25 +88,25 @@ module Pycrypto {
8988

9089
module Cryptography {
9190

92-
PackageObject ciphers() {
93-
result.getName() = "cryptography.hazmat.primitives.ciphers"
91+
ModuleValue ciphers() {
92+
result = Module::named("cryptography.hazmat.primitives.ciphers") and
93+
result.isPackage()
9494
}
9595

96-
class CipherClass extends ClassObject {
96+
class CipherClass extends ClassValue {
9797
CipherClass() {
9898
ciphers().attr("Cipher") = this
9999
}
100-
101100
}
102101

103-
class AlgorithmClass extends ClassObject {
102+
class AlgorithmClass extends ClassValue {
104103

105104
AlgorithmClass() {
106-
ciphers().submodule("algorithms").attr(_) = this
105+
ciphers().attr("algorithms").attr(_) = this
107106
}
108107

109108
string getAlgorithmName() {
110-
result = this.declaredAttribute("name").(StringObject).getText()
109+
result = this.declaredAttribute("name").(StringValue).getText()
111110
}
112111

113112
predicate isWeak() {
@@ -134,7 +133,7 @@ module Cryptography {
134133
cls.isWeak()
135134
}
136135

137-
override TaintKind getTaintOfMethodResult(string name) {
136+
override TaintKind getTaintOfMethodResult(string name) {
138137
name = "encryptor" and
139138
result.(Encryptor).getAlgorithm() = this.getAlgorithm()
140139
}
@@ -144,11 +143,11 @@ module Cryptography {
144143
class CipherSource extends TaintSource {
145144

146145
CipherSource() {
147-
this.(CallNode).getFunction().refersTo(any(CipherClass cls))
146+
this.(CallNode).getFunction().pointsTo(any(CipherClass cls))
148147
}
149148

150149
override predicate isSourceOf(TaintKind kind) {
151-
this.(CallNode).getArg(0).refersTo(_, kind.(CipherInstance).getAlgorithm(), _)
150+
this.(CallNode).getArg(0).pointsTo().getClass() = kind.(CipherInstance).getAlgorithm()
152151
}
153152

154153
override string toString() {
@@ -203,5 +202,3 @@ private class CipherConfig extends TaintTracking::Configuration {
203202
}
204203

205204
}
206-
207-

python/ql/src/semmle/python/security/Exceptions.qll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ExceptionInfo extends StringKind {
2727

2828
}
2929

30-
/** A class representing sources of information about
30+
/** A class representing sources of information about
3131
* execution state exposed in tracebacks and the like.
3232
*/
3333
abstract class ErrorInfoSource extends TaintSource {}
@@ -59,9 +59,9 @@ class ExceptionKind extends TaintKind {
5959
class ExceptionSource extends ErrorInfoSource {
6060

6161
ExceptionSource() {
62-
exists(ClassObject cls |
63-
cls.isSubclassOf(theExceptionType()) and
64-
this.(ControlFlowNode).refersTo(_, cls, _)
62+
exists(ClassValue cls |
63+
cls.getASuperType() = ClassValue::baseException() and
64+
this.(ControlFlowNode).pointsTo().getClass() = cls
6565
)
6666
or
6767
this = any(ExceptStmt s).getName().getAFlowNode()
@@ -116,7 +116,7 @@ class CallToTracebackFunction extends ErrorInfoSource {
116116
}
117117
}
118118

119-
/**
119+
/**
120120
* Represents calls to functions in the `traceback` module that return a single
121121
* string of information about an exception.
122122
*/

python/ql/src/semmle/python/security/SensitiveData.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ module SensitiveData {
166166

167167
SensitiveRequestParameter() {
168168
this.(CallNode).getFunction().(AttrNode).getName() = "get" and
169-
exists(string sensitive |
170-
this.(CallNode).getAnArg().refersTo(any(StringObject s | s.getText() = sensitive)) and
171-
data = HeuristicNames::getSensitiveDataForName(sensitive)
169+
exists(StringValue sensitive |
170+
this.(CallNode).getAnArg().pointsTo(sensitive) and
171+
data = HeuristicNames::getSensitiveDataForName(sensitive.getText())
172172
)
173173
}
174174

0 commit comments

Comments
 (0)