Skip to content

Commit 7bf285a

Browse files
committed
Python: Alter disablesCertificateValidation to fit our needs
For the snippet below, our current query is able to show _why_ we consider `var` to be a falsey value that would disable SSL/TLS verification. I'm not sure we're going to need the part that Ruby did, for being able to specify _where_ the verification was removed, but we'll see. ``` requests.get(url, verify=var) ```
1 parent 08f6d1a commit 7bf285a

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

python/ql/lib/semmle/python/Concepts.qll

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -837,10 +837,14 @@ module HTTP {
837837
/**
838838
* Holds if this request is made using a mode that disables SSL/TLS
839839
* certificate validation, where `disablingNode` represents the point at
840-
* which the validation was disabled.
840+
* which the validation was disabled, and `argumentOrigin` represents the origin
841+
* of the argument that disabled the validation (which could be the same node as
842+
* `disablingNode`).
841843
*/
842-
predicate disablesCertificateValidation(DataFlow::Node disablingNode) {
843-
super.disablesCertificateValidation(disablingNode)
844+
predicate disablesCertificateValidation(
845+
DataFlow::Node disablingNode, DataFlow::Node argumentOrigin
846+
) {
847+
super.disablesCertificateValidation(disablingNode, argumentOrigin)
844848
}
845849
}
846850

@@ -868,9 +872,13 @@ module HTTP {
868872
/**
869873
* Holds if this request is made using a mode that disables SSL/TLS
870874
* certificate validation, where `disablingNode` represents the point at
871-
* which the validation was disabled.
875+
* which the validation was disabled, and `argumentOrigin` represents the origin
876+
* of the argument that disabled the validation (which could be the same node as
877+
* `disablingNode`).
872878
*/
873-
abstract predicate disablesCertificateValidation(DataFlow::Node disablingNode);
879+
abstract predicate disablesCertificateValidation(
880+
DataFlow::Node disablingNode, DataFlow::Node argumentOrigin
881+
);
874882
}
875883
}
876884

python/ql/test/experimental/meta/ConceptsTest.qll

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,9 @@ class CryptographicOperationTest extends InlineExpectationsTest {
479479
class HttpClientRequestTest extends InlineExpectationsTest {
480480
HttpClientRequestTest() { this = "HttpClientRequestTest" }
481481

482-
override string getARelevantTag() { result = "clientRequestUrl" }
482+
override string getARelevantTag() {
483+
result in ["clientRequestUrl", "clientRequestDisablesCertValidation"]
484+
}
483485

484486
override predicate hasActualResult(Location location, string element, string tag, string value) {
485487
exists(location.getFile().getRelativePath()) and
@@ -490,5 +492,14 @@ class HttpClientRequestTest extends InlineExpectationsTest {
490492
value = prettyNodeForInlineTest(url) and
491493
tag = "clientRequestUrl"
492494
)
495+
or
496+
exists(location.getFile().getRelativePath()) and
497+
exists(HTTP::Client::Request req, DataFlow::Node disablingNode |
498+
req.disablesCertificateValidation(disablingNode, _) and
499+
location = disablingNode.getLocation() and
500+
element = disablingNode.toString() and
501+
value = prettyNodeForInlineTest(disablingNode) and
502+
tag = "clientRequestDisablesCertValidation"
503+
)
493504
}
494505
}

0 commit comments

Comments
 (0)