Skip to content

Commit 4c1afaa

Browse files
authored
Find G303 with filepath.Join'd temp dirs (#754)
1 parent 19bda8d commit 4c1afaa

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

rules/tempfiles.go

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func NewBadTempFile(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
7171
argCalls.Add("os", "TempDir")
7272
nestedCalls := gosec.NewCallList()
7373
nestedCalls.Add("path", "Join")
74+
nestedCalls.Add("path/filepath", "Join")
7475
return &badTempFile{
7576
calls: calls,
7677
args: regexp.MustCompile(`^(/(usr|var))?/tmp(/.*)?$`),

testutils/source.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -1759,6 +1759,7 @@ import (
17591759
"io/ioutil"
17601760
"os"
17611761
"path"
1762+
"path/filepath"
17621763
)
17631764
17641765
func main() {
@@ -1796,7 +1797,11 @@ func main() {
17961797
if err != nil {
17971798
fmt.Println("Error while writing!")
17981799
}
1799-
}`}, 8, gosec.NewConfig()}}
1800+
err = os.WriteFile(filepath.Join(os.TempDir(), "demo2"), []byte("This is some data"), 0644)
1801+
if err != nil {
1802+
fmt.Println("Error while writing!")
1803+
}
1804+
}`}, 9, gosec.NewConfig()}}
18001805

18011806
// SampleCodeG304 - potential file inclusion vulnerability
18021807
SampleCodeG304 = []CodeSample{{[]string{`

0 commit comments

Comments
 (0)