Skip to content

Commit b6bd782

Browse files
committed
Python: Modernize via CallCfgNode
1 parent e4d74cf commit b6bd782

File tree

3 files changed

+17
-24
lines changed

3 files changed

+17
-24
lines changed

python/ql/src/Security/CWE-327/PyOpenSSL.qll

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
* Provides modeling of SSL/TLS functionality of the `OpenSSL` module from the `pyOpenSSL` PyPI package.
33
* See https://www.pyopenssl.org/en/stable/
44
*/
5+
56
private import python
67
private import semmle.python.ApiGraphs
78
import TlsLibraryModel
89

9-
class PyOpenSSLContextCreation extends ContextCreation {
10-
override CallNode node;
11-
10+
class PyOpenSSLContextCreation extends ContextCreation, DataFlow::CallCfgNode {
1211
PyOpenSSLContextCreation() {
1312
this = API::moduleImport("OpenSSL").getMember("SSL").getMember("Context").getACall()
1413
}
@@ -22,9 +21,7 @@ class PyOpenSSLContextCreation extends ContextCreation {
2221
}
2322
}
2423

25-
class ConnectionCall extends ConnectionCreation {
26-
override CallNode node;
27-
24+
class ConnectionCall extends ConnectionCreation, DataFlow::CallCfgNode {
2825
ConnectionCall() {
2926
this = API::moduleImport("OpenSSL").getMember("SSL").getMember("Connection").getACall()
3027
}
@@ -36,9 +33,7 @@ class ConnectionCall extends ConnectionCreation {
3633

3734
// This cannot be used to unrestrict,
3835
// see https://www.pyopenssl.org/en/stable/api/ssl.html#OpenSSL.SSL.Context.set_options
39-
class SetOptionsCall extends ProtocolRestriction {
40-
override CallNode node;
41-
36+
class SetOptionsCall extends ProtocolRestriction, DataFlow::CallCfgNode {
4237
SetOptionsCall() { node.getFunction().(AttrNode).getName() = "set_options" }
4338

4439
override DataFlow::CfgNode getContext() {

python/ql/src/Security/CWE-327/Ssl.qll

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
* Provides modeling of SSL/TLS functionality of the `ssl` module from the standard library.
33
* See https://docs.python.org/3.9/library/ssl.html
44
*/
5+
56
private import python
67
private import semmle.python.ApiGraphs
78
import TlsLibraryModel
89

9-
class SSLContextCreation extends ContextCreation {
10-
override CallNode node;
11-
10+
class SSLContextCreation extends ContextCreation, DataFlow::CallCfgNode {
1211
SSLContextCreation() { this = API::moduleImport("ssl").getMember("SSLContext").getACall() }
1312

1413
override string getProtocol() {
@@ -46,7 +45,7 @@ class WrapSocketCall extends ConnectionCreation, DataFlow::CallCfgNode {
4645
}
4746
}
4847

49-
class OptionsAugOr extends ProtocolRestriction {
48+
class OptionsAugOr extends ProtocolRestriction, DataFlow::CallCfgNode {
5049
ProtocolVersion restriction;
5150

5251
OptionsAugOr() {
@@ -69,7 +68,7 @@ class OptionsAugOr extends ProtocolRestriction {
6968
override ProtocolVersion getRestriction() { result = restriction }
7069
}
7170

72-
class OptionsAugAndNot extends ProtocolUnrestriction {
71+
class OptionsAugAndNot extends ProtocolUnrestriction, DataFlow::CallCfgNode {
7372
ProtocolVersion restriction;
7473

7574
OptionsAugAndNot() {
@@ -127,7 +126,7 @@ predicate impliesBitSet(BinaryExpr whole, Expr part, boolean partHasBitSet, bool
127126
)
128127
}
129128

130-
class ContextSetVersion extends ProtocolRestriction, ProtocolUnrestriction {
129+
class ContextSetVersion extends ProtocolRestriction, ProtocolUnrestriction, DataFlow::CallCfgNode {
131130
ProtocolVersion restriction;
132131

133132
ContextSetVersion() {
@@ -189,8 +188,7 @@ class Ssl extends TlsLibrary {
189188

190189
override DataFlow::CfgNode insecure_connection_creation(ProtocolVersion version) {
191190
result = API::moduleImport("ssl").getMember("wrap_socket").getACall() and
192-
this.specific_version(version) =
193-
result.(DataFlow::CallCfgNode).getArgByName("ssl_version") and
191+
this.specific_version(version) = result.(DataFlow::CallCfgNode).getArgByName("ssl_version") and
194192
version.isInsecure()
195193
}
196194

python/ql/src/Security/CWE-327/TlsLibraryModel.qll

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,30 @@ class ProtocolFamily extends string {
3030
}
3131

3232
/** The creation of a context. */
33-
abstract class ContextCreation extends DataFlow::CfgNode {
33+
abstract class ContextCreation extends DataFlow::Node {
3434
/** Gets the protocol version or family for this context. */
3535
abstract string getProtocol();
3636
}
3737

3838
/** The creation of a connection from a context. */
39-
abstract class ConnectionCreation extends DataFlow::CfgNode {
39+
abstract class ConnectionCreation extends DataFlow::Node {
4040
/** Gets the context used to create the connection. */
41-
abstract DataFlow::CfgNode getContext();
41+
abstract DataFlow::Node getContext();
4242
}
4343

4444
/** A context is being restricted on which protocols it can accepts. */
45-
abstract class ProtocolRestriction extends DataFlow::CfgNode {
45+
abstract class ProtocolRestriction extends DataFlow::Node {
4646
/** Gets the context being restricted. */
47-
abstract DataFlow::CfgNode getContext();
47+
abstract DataFlow::Node getContext();
4848

4949
/** Gets the protocol version being disallowed. */
5050
abstract ProtocolVersion getRestriction();
5151
}
5252

5353
/** A context is being relaxed on which protocols it can accepts. */
54-
abstract class ProtocolUnrestriction extends DataFlow::CfgNode {
54+
abstract class ProtocolUnrestriction extends DataFlow::Node {
5555
/** Gets the context being relaxed. */
56-
abstract DataFlow::CfgNode getContext();
56+
abstract DataFlow::Node getContext();
5757

5858
/** Gets the protocol version being allowed. */
5959
abstract ProtocolVersion getUnrestriction();

0 commit comments

Comments
 (0)