Files
gosec/testutils/g702_samples.go
T
Ravi Sastry Kadali 398ad549bb feat: Support for adding taint analysis engine (#1486)
* feat: add taint analysis engine for data flow security

Implements SSA-based taint analysis to detect security vulnerabilities:
- G701: SQL injection via string concatenation
- G702: Command injection via user input
- G703: Path traversal via user input
- G704: SSRF via user-controlled URLs
- G705: XSS via unescaped user input
- G706: Log injection via user input

Uses golang.org/x/tools for SSA/call graph analysis with CHA.
Zero external dependencies beyond existing gosec imports.
2026-02-10 15:47:11 +01:00

47 lines
698 B
Go

package testutils
import "github.com/securego/gosec/v2"
// SampleCodeG702 - Command injection via taint analysis
var SampleCodeG702 = []CodeSample{
{[]string{`
package main
import (
"net/http"
"os/exec"
)
func handler(r *http.Request) {
filename := r.URL.Query().Get("file")
cmd := exec.Command("cat", filename)
cmd.Run()
}
`}, 1, gosec.NewConfig()},
{[]string{`
package main
import (
"os"
"os/exec"
)
func dynamicCommand() {
userInput := os.Args[1]
exec.Command("sh", "-c", userInput).Run()
}
`}, 1, gosec.NewConfig()},
{[]string{`
package main
import (
"os/exec"
)
func safeCommand() {
// Safe - no user input
exec.Command("ls", "-la").Run()
}
`}, 0, gosec.NewConfig()},
}