Skip to content

Commit

Permalink
Find G303 with filepath.Join'd temp dirs (#754)
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed Jan 4, 2022
1 parent 19bda8d commit 4c1afaa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions rules/tempfiles.go
Expand Up @@ -71,6 +71,7 @@ func NewBadTempFile(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
argCalls.Add("os", "TempDir")
nestedCalls := gosec.NewCallList()
nestedCalls.Add("path", "Join")
nestedCalls.Add("path/filepath", "Join")
return &badTempFile{
calls: calls,
args: regexp.MustCompile(`^(/(usr|var))?/tmp(/.*)?$`),
Expand Down
7 changes: 6 additions & 1 deletion testutils/source.go
Expand Up @@ -1759,6 +1759,7 @@ import (
"io/ioutil"
"os"
"path"
"path/filepath"
)
func main() {
Expand Down Expand Up @@ -1796,7 +1797,11 @@ func main() {
if err != nil {
fmt.Println("Error while writing!")
}
}`}, 8, gosec.NewConfig()}}
err = os.WriteFile(filepath.Join(os.TempDir(), "demo2"), []byte("This is some data"), 0644)
if err != nil {
fmt.Println("Error while writing!")
}
}`}, 9, gosec.NewConfig()}}

// SampleCodeG304 - potential file inclusion vulnerability
SampleCodeG304 = []CodeSample{{[]string{`
Expand Down

0 comments on commit 4c1afaa

Please sign in to comment.