Skip to content

Commit 6068f63

Browse files
committed
Add taint models for go 1.19's new fmt.Append functions
1 parent d205528 commit 6068f63

File tree

3 files changed

+92
-14
lines changed

3 files changed

+92
-14
lines changed

go/ql/lib/semmle/go/frameworks/stdlib/Fmt.qll

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

77
/** Provides models of commonly used functions in the `fmt` package. */
88
module Fmt {
9-
/** The `Sprint` function or one of its variants. */
10-
class Sprinter extends TaintTracking::FunctionModel {
11-
Sprinter() {
12-
// signature: func Sprint(a ...interface{}) string
13-
this.hasQualifiedName("fmt", "Sprint")
14-
or
15-
// signature: func Sprintf(format string, a ...interface{}) string
16-
this.hasQualifiedName("fmt", "Sprintf")
17-
or
18-
// signature: func Sprintln(a ...interface{}) string
19-
this.hasQualifiedName("fmt", "Sprintln")
20-
}
9+
/** The `Sprint` or `Append` functions or one of their variants. */
10+
class AppenderOrSprinter extends TaintTracking::FunctionModel {
11+
AppenderOrSprinter() { this.hasQualifiedName("fmt", ["Append", "Sprint"] + ["", "f", "ln"]) }
2112

2213
override predicate hasTaintFlow(FunctionInput inp, FunctionOutput outp) {
2314
inp.isParameter(_) and outp.isResult()
2415
}
2516
}
2617

18+
/** The `Sprint` function or one of its variants. */
19+
class Sprinter extends AppenderOrSprinter {
20+
Sprinter() { this.getName().matches("Sprint%") }
21+
}
22+
2723
/** The `Print` function or one of its variants. */
2824
class Printer extends Function {
2925
Printer() { this.hasQualifiedName("fmt", ["Print", "Printf", "Println"]) }

go/ql/src/Security/CWE-352/ConstantOauth2State.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class PrivateUrlFlowsToAuthCodeUrlCall extends DataFlow::Configuration {
106106
TaintTracking::referenceStep(pred, succ)
107107
or
108108
// Propagate across Sprintf and similar calls
109-
any(Fmt::Sprinter s).taintStep(pred, succ)
109+
any(Fmt::AppenderOrSprinter s).taintStep(pred, succ)
110110
}
111111

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

go/ql/test/library-tests/semmle/go/frameworks/StdlibTaintFlow/Fmt.go

Lines changed: 83 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)