Skip to content

Commit afc9903

Browse files
authored
Fix use rule IDs to retrieve the rule config
1 parent 82eaa12 commit afc9903

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

rules/directory-traversal.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (r *traversal) matchCallExpr(assign *ast.CallExpr, ctx *gosec.Context) (*go
4343
// NewDirectoryTraversal attempts to find the use of http.Dir("/")
4444
func NewDirectoryTraversal(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
4545
pattern := `http\.Dir\("\/"\)|http\.Dir\('\/'\)`
46-
if val, ok := conf["G101"]; ok {
46+
if val, ok := conf[id]; ok {
4747
conf := val.(map[string]interface{})
4848
if configPattern, ok := conf["pattern"]; ok {
4949
if cfgPattern, ok := configPattern.(string); ok {

rules/errors.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func NewNoErrorCheck(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
8989
whitelist.Add("hash.Hash", "Write")
9090
whitelist.Add("os", "Unsetenv")
9191

92-
if configured, ok := conf["G104"]; ok {
92+
if configured, ok := conf[id]; ok {
9393
if whitelisted, ok := configured.(map[string]interface{}); ok {
9494
for pkg, funcs := range whitelisted {
9595
if funcs, ok := funcs.([]interface{}); ok {

rules/fileperms.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (r *filePermissions) Match(n ast.Node, c *gosec.Context) (*gosec.Issue, err
6464

6565
// NewWritePerms creates a rule to detect file Writes with bad permissions.
6666
func NewWritePerms(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
67-
mode := getConfiguredMode(conf, "G306", 0o600)
67+
mode := getConfiguredMode(conf, id, 0o600)
6868
return &filePermissions{
6969
mode: mode,
7070
pkgs: []string{"io/ioutil", "os"},
@@ -81,7 +81,7 @@ func NewWritePerms(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
8181
// NewFilePerms creates a rule to detect file creation with a more permissive than configured
8282
// permission mask.
8383
func NewFilePerms(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
84-
mode := getConfiguredMode(conf, "G302", 0o600)
84+
mode := getConfiguredMode(conf, id, 0o600)
8585
return &filePermissions{
8686
mode: mode,
8787
pkgs: []string{"os"},
@@ -98,7 +98,7 @@ func NewFilePerms(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
9898
// NewMkdirPerms creates a rule to detect directory creation with more permissive than
9999
// configured permission mask.
100100
func NewMkdirPerms(id string, conf gosec.Config) (gosec.Rule, []ast.Node) {
101-
mode := getConfiguredMode(conf, "G301", 0o750)
101+
mode := getConfiguredMode(conf, id, 0o750)
102102
return &filePermissions{
103103
mode: mode,
104104
pkgs: []string{"os"},

rules/hardcoded_credentials.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func NewHardcodedCredentials(id string, conf gosec.Config) (gosec.Rule, []ast.No
122122
perCharThreshold := 3.0
123123
ignoreEntropy := false
124124
truncateString := 16
125-
if val, ok := conf["G101"]; ok {
125+
if val, ok := conf[id]; ok {
126126
conf := val.(map[string]interface{})
127127
if configPattern, ok := conf["pattern"]; ok {
128128
if cfgPattern, ok := configPattern.(string); ok {

0 commit comments

Comments
 (0)