Skip to content

Commit acf8fd0

Browse files
yoffRasmusWL
andauthored
Apply suggestions from code review
Co-authored-by: Rasmus Wriedt Larsen <[email protected]>
1 parent 6d72b4f commit acf8fd0

File tree

3 files changed

+16
-31
lines changed

3 files changed

+16
-31
lines changed

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import TlsLibraryModel
33

44
/**
55
* Configuration to determine the state of a context being used to create
6-
* a conection.
6+
* a conection. There is one configuration for each pair of `TlsLibrary` and `ProtocolVersion`,
7+
* such that a single configuration only tracks contexts where a specific `ProtocolVersion` is allowed.
78
*
89
* The state is in terms of whether a specific protocol is allowed. This is
910
* either true or false when the context is created and can then be modified
@@ -72,20 +73,18 @@ predicate unsafe_connection_creation_with_context(
7273
boolean specific
7374
) {
7475
// Connection created from a context allowing `insecure_version`.
75-
exists(InsecureContextConfiguration c, ProtocolUnrestriction co |
76-
c.hasFlow(co, connectionCreation)
76+
exists(InsecureContextConfiguration c |
77+
c.hasFlow(contextOrigin, connectionCreation)
7778
|
7879
insecure_version = c.getTrackedVersion() and
79-
contextOrigin = co and
80+
contextOrigin instanceof ProtocolUnrestriction and
8081
specific = false
8182
)
8283
or
8384
// Connection created from a context specifying `insecure_version`.
84-
exists(TlsLibrary l, DataFlow::CfgNode cc |
85-
cc = l.insecure_connection_creation(insecure_version)
86-
|
87-
connectionCreation = cc and
88-
contextOrigin = cc and
85+
exists(TlsLibrary l |
86+
connectionCreation = l.insecure_connection_creation(insecure_version) and
87+
contextOrigin = connectionCreation and
8988
specific = true
9089
)
9190
}
@@ -105,7 +104,6 @@ predicate unsafe_connection_creation_without_context(
105104

106105
/** Holds if `contextCreation` is creating a context ties to a specific insecure version. */
107106
predicate unsafe_context_creation(DataFlow::CallCfgNode contextCreation, string insecure_version) {
108-
exists(TlsLibrary l, ContextCreation cc | cc = l.insecure_context_creation(insecure_version) |
109-
contextCreation = cc
110-
)
107+
contextCreation instanceof ContextCreation and
108+
exists(TlsLibrary l | contextCreation = l.insecure_context_creation(insecure_version))
111109
}

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

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,17 @@ class SSLDefaultContextCreation extends ContextCreation {
2323
}
2424

2525
/** Gets a reference to an `ssl.Context` instance. */
26-
private DataFlow::LocalSourceNode sslContextInstance(DataFlow::TypeTracker t) {
27-
t.start() and
28-
result = API::moduleImport("ssl").getMember(["SSLContext", "create_default_context"]).getACall()
29-
or
30-
exists(DataFlow::TypeTracker t2 | result = sslContextInstance(t2).track(t2, t))
31-
}
32-
33-
/** Gets a reference to an `ssl.Context` instance. */
34-
DataFlow::Node sslContextInstance() {
35-
sslContextInstance(DataFlow::TypeTracker::end()).flowsTo(result)
26+
API::Node sslContextInstance() {
27+
result = API::moduleImport("ssl").getMember(["SSLContext", "create_default_context"]).getReturn()
3628
}
3729

38-
class WrapSocketCall extends ConnectionCreation {
39-
override CallNode node;
40-
30+
class WrapSocketCall extends ConnectionCreation, DataFlow::CallCfgNode {
4131
WrapSocketCall() {
42-
exists(DataFlow::AttrRead call | node.getFunction() = call.asCfgNode() |
43-
call.getAttributeName() = "wrap_socket" and
44-
call.getObject() = sslContextInstance()
45-
)
32+
this = sslContextInstance().getMember("wrap_socket").getACall()
4633
}
4734

4835
override DataFlow::CfgNode getContext() {
49-
result.getNode() = node.getFunction().(AttrNode).getObject()
36+
result = this.getFunction().(DataFlow::AttrRead).getObject()
5037
}
5138
}
5239

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ abstract class UnspecificContextCreation extends ContextCreation, ProtocolUnrest
8484
}
8585
}
8686

87-
/** A model of a TLS library. */
87+
/** A model of a SSL/TLS library. */
8888
abstract class TlsLibrary extends string {
8989
TlsLibrary() { this in ["ssl", "pyOpenSSL"] }
9090

0 commit comments

Comments
 (0)