Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bd86388

Browse files
committed
Python: Add typetracker to constrain attribute.
1 parent bf81122 commit bd86388

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

  • python/ql/src/Security/CWE-327

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,28 @@ class SSLDefaultContextCreation extends ContextCreation {
2222
override DataFlow::CfgNode getProtocol() { none() }
2323
}
2424

25+
/** 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)
36+
}
37+
2538
class WrapSocketCall extends ConnectionCreation {
2639
override CallNode node;
2740

28-
WrapSocketCall() { node.getFunction().(AttrNode).getName() = "wrap_socket" }
41+
WrapSocketCall() {
42+
exists(DataFlow::AttrRead call | node.getFunction() = call.asCfgNode() |
43+
call.getAttributeName() = "wrap_socket" and
44+
call.getObject() = sslContextInstance()
45+
)
46+
}
2947

3048
override DataFlow::CfgNode getContext() {
3149
result.getNode() = node.getFunction().(AttrNode).getObject()

0 commit comments

Comments
 (0)