mirror of
https://github.com/securego/gosec.git
synced 2026-06-20 00:15:59 +02:00
* Refactor rules to utilize callListRule base structure - Introduced a new base structure `callListRule` in `rules/base.go` to standardize the implementation of rules that check for specific function calls. - Updated existing rules to inherit from `callListRule`, simplifying their structure and removing redundant ID methods. - Modified the `MetaData` field to use `RuleID` instead of `ID` for consistency across rules. - Removed the `weakcryptohash.go` and `weakdepricatedcryptohash.go` files as their functionality has been integrated into the new structure. * fix(tlsconfig): correct MetaData field name in generated TLS check * refactor: standardize rule metadata and call list initialization
40 lines
1.0 KiB
Go
40 lines
1.0 KiB
Go
package rules
|
|
|
|
import (
|
|
"go/ast"
|
|
|
|
"github.com/securego/gosec/v2"
|
|
"github.com/securego/gosec/v2/issue"
|
|
)
|
|
|
|
// callListRule is a base for rules that simply check a CallList and issue on match.
|
|
// It provides the standard Match() implementation used by most call-based rules.
|
|
type callListRule struct {
|
|
issue.MetaData
|
|
calls gosec.CallList
|
|
}
|
|
|
|
func newCallListRule(id, what string, severity, confidence issue.Score) callListRule {
|
|
return callListRule{
|
|
MetaData: issue.NewMetaData(id, what, severity, confidence),
|
|
calls: gosec.NewCallList(),
|
|
}
|
|
}
|
|
|
|
func (r *callListRule) Add(selector, ident string) *callListRule {
|
|
r.calls.Add(selector, ident)
|
|
return r
|
|
}
|
|
|
|
func (r *callListRule) AddAll(selector string, idents ...string) *callListRule {
|
|
r.calls.AddAll(selector, idents...)
|
|
return r
|
|
}
|
|
|
|
func (r *callListRule) Match(n ast.Node, c *gosec.Context) (*issue.Issue, error) {
|
|
if r.calls.ContainsPkgCallExpr(n, c, false) != nil {
|
|
return c.NewIssue(n, r.ID(), r.What, r.Severity, r.Confidence), nil
|
|
}
|
|
return nil, nil
|
|
}
|