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
34 lines
938 B
Go
34 lines
938 B
Go
package rules
|
|
|
|
import (
|
|
"go/ast"
|
|
|
|
"github.com/securego/gosec/v2"
|
|
"github.com/securego/gosec/v2/issue"
|
|
)
|
|
|
|
type pprofCheck struct {
|
|
issue.MetaData
|
|
importPath string
|
|
importName string
|
|
}
|
|
|
|
// Match checks for pprof imports
|
|
func (p *pprofCheck) Match(n ast.Node, c *gosec.Context) (*issue.Issue, error) {
|
|
if node, ok := n.(*ast.ImportSpec); ok {
|
|
if p.importPath == unquote(node.Path.Value) && node.Name != nil && p.importName == node.Name.Name {
|
|
return c.NewIssue(node, p.ID(), p.What, p.Severity, p.Confidence), nil
|
|
}
|
|
}
|
|
return nil, nil
|
|
}
|
|
|
|
// NewPprofCheck detects when the profiling endpoint is automatically exposed
|
|
func NewPprofCheck(id string, _ gosec.Config) (gosec.Rule, []ast.Node) {
|
|
return &pprofCheck{
|
|
MetaData: issue.NewMetaData(id, "Profiling endpoint is automatically exposed on /debug/pprof", issue.High, issue.High),
|
|
importPath: "net/http/pprof",
|
|
importName: "_",
|
|
}, []ast.Node{(*ast.ImportSpec)(nil)}
|
|
}
|