Skip to content

Commit 9536345

Browse files
committed
fix tests, and review suggestions.
1 parent 7d5bbc3 commit 9536345

File tree

13 files changed

+16
-4592
lines changed

13 files changed

+16
-4592
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Support has been added for file system access sinks in the following libraries: [net/http](https://pkg.go.dev/net/http), [Afero](https://github.com/spf13/afero), [beego](https://pkg.go.dev/github.com/astaxie/beego), [Echo](https://pkg.go.dev/github.com/labstack/echo), [Fiber](https://github.com/kataras/iris), [Gin](https://pkg.go.dev/github.com/gin-gonic/gin), [Iris](https://github.com/kataras/iris).

go/ql/lib/go.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import semmle.go.dataflow.GlobalValueNumbering
3030
import semmle.go.dataflow.SSA
3131
import semmle.go.dataflow.TaintTracking
3232
import semmle.go.dataflow.TaintTracking2
33+
import semmle.go.frameworks.Afero
3334
import semmle.go.frameworks.Beego
3435
import semmle.go.frameworks.BeegoOrm
3536
import semmle.go.frameworks.Chi
@@ -38,11 +39,13 @@ import semmle.go.frameworks.Echo
3839
import semmle.go.frameworks.ElazarlGoproxy
3940
import semmle.go.frameworks.Email
4041
import semmle.go.frameworks.Encoding
42+
import semmle.go.frameworks.Fiber
4143
import semmle.go.frameworks.Gin
4244
import semmle.go.frameworks.Glog
4345
import semmle.go.frameworks.GoMicro
4446
import semmle.go.frameworks.GoRestfulHttp
4547
import semmle.go.frameworks.Gqlgen
48+
import semmle.go.frameworks.Iris
4649
import semmle.go.frameworks.K8sIoApimachineryPkgRuntime
4750
import semmle.go.frameworks.K8sIoApiCoreV1
4851
import semmle.go.frameworks.K8sIoClientGo
@@ -64,6 +67,3 @@ import semmle.go.frameworks.XPath
6467
import semmle.go.frameworks.Yaml
6568
import semmle.go.frameworks.Zap
6669
import semmle.go.security.FlowSources
67-
import semmle.go.frameworks.Afero
68-
import semmle.go.frameworks.Iris
69-
import semmle.go.frameworks.Fiber

go/ql/lib/semmle/go/frameworks/Afero.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ module Afero {
105105
*/
106106
predicate additionalTaintStep(DataFlow::Node n1, DataFlow::Node n2) {
107107
exists(StructLit st | st.getType().hasQualifiedName(aferoPackage(), "Afero") |
108-
n1.asExpr() = st.getAChildExpr().(KeyValueExpr).getAChildExpr() and
108+
n1.asExpr() = st.getAnElement().(KeyValueExpr).getAChildExpr() and
109109
n2.asExpr() = st
110110
)
111111
}

go/ql/lib/semmle/go/frameworks/Echo.qll

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,13 @@ private module Echo {
103103
* The File system access sinks
104104
*/
105105
class FsOperations extends FileSystemAccess::Range, DataFlow::CallNode {
106-
int pathArg;
107-
108106
FsOperations() {
109107
exists(Method m |
110108
m.hasQualifiedName(packagePath(), "Context", ["Attachment", "File"]) and
111-
this = m.getACall() and
112-
pathArg = 0
109+
this = m.getACall()
113110
)
114111
}
115112

116-
override DataFlow::Node getAPathArgument() { result = this.getArgument(pathArg) }
113+
override DataFlow::Node getAPathArgument() { result = this.getArgument(0) }
117114
}
118115
}

go/ql/lib/semmle/go/frameworks/Iris.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
import go
66

7-
private module Gin {
8-
/** Gets the v1 module path `github.com/gofiber/fiber`. */
7+
private module Iris {
8+
/** Gets the v1 module path `github.com/kataras/iris`. */
99
string v1modulePath() { result = "github.com/kataras/iris" }
1010

11-
/** Gets the v12 module path `github.com/gofiber/fiber/v12` */
11+
/** Gets the v12 module path `github.com/kataras/iris/v12` */
1212
string v12modulePath() { result = "github.com/kataras/iris/v12" }
1313

1414
/** Gets the path for the context package of all versions of beego. */

go/ql/src/change-notes/2023-09-25-add-new-filesystemaccess-sinks.md

Lines changed: 0 additions & 10 deletions
This file was deleted.

go/ql/test/library-tests/semmle/go/frameworks/Afero/main.go renamed to go/ql/test/library-tests/semmle/go/frameworks/Afero/test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ func Afero(writer http.ResponseWriter, request *http.Request) {
5454

5555
// osFS ==> NOT OK
5656
fmt.Println("Afero:")
57-
afs := &afero.Afero{Fs: osFS} // $ succ=Afero pred=osFS
57+
afs := &afero.Afero{Fs: osFS} // $ succ=Afero pred=osFS
5858
afs0 := afero.Afero{Fs: osFS} // $ succ=Afero pred=osFS
59-
afs = &afs0
59+
afs = &afs0
6060
fmt.Println(afs.ReadFile(filepath)) // $ FileSystemAccess=filepath
6161

6262
// BasePathFs ==> OK
6363
fmt.Println("Afero:")
6464
newBasePathFs := afero.NewBasePathFs(osFS, "tmp")
65-
basePathFs0 := &afero.Afero{Fs: newBasePathFs}// $ succ=Afero pred=newBasePathFs
65+
basePathFs0 := &afero.Afero{Fs: newBasePathFs} // $ succ=Afero pred=newBasePathFs
6666
// following is a FP, and in a dataflow configuration if we use Afero::additionalTaintStep then we won't have following in results
6767
fmt.Println(basePathFs0.ReadFile(filepath)) // $ SPURIOUS: FileSystemAccess=filepath
6868

0 commit comments

Comments
 (0)