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

Commit 3d877fc

Browse files
committed
Oauth2 state: note bufio.NewScanner is also a sign of probable terminal-interactive use
1 parent 6fee4f3 commit 3d877fc

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,27 @@ predicate resultFlowsToPrinter(DataFlow::CallNode authCodeURLCall) {
6565
)
6666
}
6767

68+
/** Gets dataflow nodes that read the value of os.Stdin */
69+
DataFlow::Node getAStdinNode() {
70+
result = any(ValueEntity v | v.hasQualifiedName("os", "Stdin")).getARead()
71+
}
72+
73+
/**
74+
* Gets a call to a scanner function that reads from os.Stdin, or which creates a scanner
75+
* instance wrapping os.Stdin.
76+
*/
77+
DataFlow::CallNode getAScannerCall() {
78+
result instanceof Fmt::ScannerCall or
79+
result.(Fmt::FScannerCall).getReader() = getAStdinNode() or
80+
result.(Bufio::NewScannerCall).getReader() = getAStdinNode()
81+
}
82+
6883
/**
6984
* Holds if the provided CallNode is within the same root as a call
7085
* to a scanner that reads from os.Stdin.
7186
*/
72-
predicate rootContainsCallToStdinScanner(DataFlow::CallNode authCodeURLCall) {
73-
exists(Fmt::ScannerCall scannerCall | scannerCall.getRoot() = authCodeURLCall.getRoot())
74-
or
75-
exists(Fmt::FScannerCall fScannerCall |
76-
fScannerCall.getReader() = any(ValueEntity v | v.hasQualifiedName("os", "Stdin")).getARead() and
77-
fScannerCall.getRoot() = authCodeURLCall.getRoot()
78-
)
87+
predicate containsCallToStdinScanner(FuncDef funcDef) {
88+
exists(DataFlow::CallNode call | call = getAScannerCall() | call.getRoot() = funcDef)
7989
}
8090

8191
/**
@@ -86,7 +96,7 @@ predicate rootContainsCallToStdinScanner(DataFlow::CallNode authCodeURLCall) {
8696
*/
8797
predicate seemsLikeDoneWithinATerminal(DataFlow::CallNode authCodeURLCall) {
8898
resultFlowsToPrinter(authCodeURLCall) and
89-
rootContainsCallToStdinScanner(authCodeURLCall)
99+
containsCallToStdinScanner(authCodeURLCall.getRoot())
90100
}
91101

92102
from

ql/src/semmle/go/frameworks/stdlib/Bufio.qll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,26 @@ import go
66

77
/** Provides models of commonly used functions in the `bufio` package. */
88
module Bufio {
9+
/**
10+
* The function bufio.NewScanner.
11+
*/
12+
class NewScanner extends Function {
13+
NewScanner() { this.hasQualifiedName("bufio", "NewScanner") }
14+
}
15+
16+
/**
17+
* A call to bufio.NewScanner.
18+
*/
19+
class NewScannerCall extends DataFlow::CallNode {
20+
NewScannerCall() { this.getTarget() instanceof NewScanner }
21+
22+
/**
23+
* Returns the node corresponding to the io.Reader
24+
* argument provided in the call.
25+
*/
26+
DataFlow::Node getReader() { result = this.getArgument(0) }
27+
}
28+
929
private class FunctionModels extends TaintTracking::FunctionModel {
1030
FunctionInput inp;
1131
FunctionOutput outp;

0 commit comments

Comments
 (0)