Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 6fee4f3

Browse files
committed
Constant-oauth2-state: exclude strings returned alongside an error value
For example, getState() { ... return "", someError } is commonly seen in the wild.
1 parent aac303c commit 6fee4f3

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

ql/src/Security/CWE-327/InsecureTLS.ql

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,6 @@ int getASecureTlsVersion() {
5050
*/
5151
int getATlsVersion() { result = getASecureTlsVersion() or isInsecureTlsVersion(result, _, _) }
5252

53-
/**
54-
* Holds if `node` refers to a value returned alongside a non-nil error value.
55-
*
56-
* For example, `0` in `func tryGetInt() (int, error) { return 0, errors.New("no good") }`
57-
*/
58-
predicate isReturnedWithError(DataFlow::Node node) {
59-
exists(ReturnStmt ret |
60-
ret.getExpr(0) = node.asExpr() and
61-
ret.getNumExpr() = 2 and
62-
ret.getExpr(1).getType() instanceof ErrorType
63-
// That last condition implies ret.getExpr(1) is non-nil, since nil doesn't implement `error`
64-
)
65-
}
66-
6753
/**
6854
* Flow of TLS versions into a `tls.Config` struct, to the `MinVersion` and `MaxVersion` fields.
6955
*/
@@ -76,7 +62,7 @@ class TlsVersionFlowConfig extends TaintTracking::Configuration {
7662
predicate isSource(DataFlow::Node source, int val) {
7763
val = source.getIntValue() and
7864
val = getATlsVersion() and
79-
not isReturnedWithError(source)
65+
not DataFlow::isReturnedWithError(source)
8066
}
8167

8268
/**

ql/src/experimental/CWE-352/ConstantOauth2State.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ConstantStateFlowConf extends DataFlow::Configuration {
2828
ConstantStateFlowConf() { this = "ConstantStateFlowConf" }
2929

3030
predicate isSource(DataFlow::Node source, Literal state) {
31-
state.isConst() and source.asExpr() = state
31+
state.isConst() and source.asExpr() = state and not DataFlow::isReturnedWithError(source)
3232
}
3333

3434
predicate isSink(DataFlow::Node sink, DataFlow::CallNode call) {

ql/src/semmle/go/dataflow/internal/DataFlowUtil.qll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,20 @@ Node extractTupleElement(Node t, int i) {
875875
)
876876
}
877877

878+
/**
879+
* Holds if `node` refers to a value returned alongside a non-nil error value.
880+
*
881+
* For example, `0` in `func tryGetInt() (int, error) { return 0, errors.New("no good") }`
882+
*/
883+
predicate isReturnedWithError(Node node) {
884+
exists(ReturnStmt ret |
885+
ret.getExpr(0) = node.asExpr() and
886+
ret.getNumExpr() = 2 and
887+
ret.getExpr(1).getType() instanceof ErrorType
888+
// That last condition implies ret.getExpr(1) is non-nil, since nil doesn't implement `error`
889+
)
890+
}
891+
878892
/**
879893
* Holds if data flows from `nodeFrom` to `nodeTo` in exactly one local
880894
* (intra-procedural) step.

0 commit comments

Comments
 (0)