Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find G303 with filepath.Join'd temp dirs #754

Merged
merged 1 commit into from Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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