Skip to content

Commit 540b433

Browse files
committed
Go: Post-processing query for inline test expectations
1 parent 4561770 commit 540b433

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @kind test-postprocess
3+
*/
4+
5+
private import go
6+
private import codeql.util.test.InlineExpectationsTest as T
7+
private import internal.InlineExpectationsTestImpl
8+
import T::TestPostProcessing
9+
import T::TestPostProcessing::Make<Impl, Input>
10+
11+
private module Input implements T::TestPostProcessing::InputSig<Impl> {
12+
string getRelativeUrl(Location location) {
13+
exists(File f, int startline, int startcolumn, int endline, int endcolumn |
14+
location.hasLocationInfo(_, startline, startcolumn, endline, endcolumn) and
15+
f = location.getFile()
16+
|
17+
result =
18+
f.getRelativePath() + ":" + startline + ":" + startcolumn + ":" + endline + ":" + endcolumn
19+
)
20+
}
21+
}

go/ql/test/library-tests/semmle/go/frameworks/Gin/Gin.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ type Person struct {
2121
func FileSystemAccess() {
2222
router := gin.Default()
2323
router.POST("/FormUploads", func(c *gin.Context) {
24-
filepath := c.Query("filepath")
25-
c.File(filepath) // $ FileSystemAccess=filepath
26-
http.ServeFile(c.Writer, c.Request, filepath) // $ FileSystemAccess=filepath
27-
c.FileAttachment(filepath, "file name in response") // $ FileSystemAccess=filepath
24+
filepath := c.Query("filepath") // $ Source=filepath
25+
c.File(filepath) // $ Alert=filepath $ FileSystemAccess=filepath
26+
http.ServeFile(c.Writer, c.Request, filepath) // $ Alert=filepath $ FileSystemAccess=filepath
27+
c.FileAttachment(filepath, "file name in response") // $ Alert=filepath $ FileSystemAccess=filepath
2828
file, _ := c.FormFile("afile")
29-
_ = c.SaveUploadedFile(file, filepath) // $ FileSystemAccess=filepath
29+
_ = c.SaveUploadedFile(file, filepath) // $ Alert=filepath $ FileSystemAccess=filepath
3030
})
3131
_ = router.Run()
3232
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
query: Security/CWE-022/TaintedPath.ql
2-
postprocess: TestUtilities/PrettyPrintModels.ql
2+
postprocess:
3+
- TestUtilities/PrettyPrintModels.ql
4+
- TestUtilities/InlineExpectationsTestQuery.ql

0 commit comments

Comments
 (0)