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

Commit ee2804d

Browse files
committed
Improve comments
1 parent ee43565 commit ee2804d

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class FlowToPrint extends DataFlow::Configuration {
5858
}
5959

6060
/** Holds if the provided CallNode's result flows to a Printer call as argument. */
61-
predicate flowsToPrinter(DataFlow::CallNode authCodeURLCall) {
61+
predicate resultFlowsToPrinter(DataFlow::CallNode authCodeURLCall) {
6262
exists(FlowToPrint cfg, DataFlow::PathNode source, DataFlow::PathNode sink |
6363
cfg.hasFlowPath(source, sink) and
6464
cfg.isSource(source.getNode(), authCodeURLCall)
@@ -78,16 +78,24 @@ predicate rootContainsCallToStdinScanner(DataFlow::CallNode authCodeURLCall) {
7878
)
7979
}
8080

81+
/**
82+
* Holds if the authCodeURLCall seems to be done within a terminal
83+
* because there are calls to a Printer (fmt.Println and similar),
84+
* and a call to a Scanner (fmt.Scan and similar),
85+
* all of which are typically done within a terminal session.
86+
*/
87+
predicate seemsLikeDoneWithinATerminal(DataFlow::CallNode authCodeURLCall) {
88+
resultFlowsToPrinter(authCodeURLCall) and
89+
rootContainsCallToStdinScanner(authCodeURLCall)
90+
}
91+
8192
from
8293
ConstantStateFlowConf cfg, DataFlow::PathNode source, DataFlow::PathNode sink,
8394
DataFlow::CallNode sinkCall
8495
where
8596
cfg.hasFlowPath(source, sink) and
8697
cfg.isSink(sink.getNode(), sinkCall) and
8798
// Exclude cases that seem to be oauth flows done from within a terminal:
88-
not (
89-
flowsToPrinter(sinkCall) and
90-
rootContainsCallToStdinScanner(sinkCall)
91-
)
99+
not seemsLikeDoneWithinATerminal(sinkCall)
92100
select sink.getNode(), source, sink, "Using a constant $@ to create oauth2 URLs.", source.getNode(),
93101
"state string"

ql/src/semmle/go/frameworks/Stdlib.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ module Fmt {
154154
class FScannerCall extends DataFlow::CallNode {
155155
FScannerCall() { this.getTarget() instanceof FScanner }
156156

157+
/**
158+
* Returns the node corresponding to the io.Reader
159+
* argument provided in the call.
160+
*/
157161
DataFlow::Node getReader() { result = this.getArgument(0) }
158162
}
159163
}

0 commit comments

Comments
 (0)