@@ -22,17 +22,24 @@ import (
22
22
)
23
23
24
24
type readfile struct {
25
+ gas.MetaData
25
26
gas.CallList
26
27
}
27
28
29
+ // ID returns the identifier for this rule
30
+ func (r * readfile ) ID () string {
31
+ return r .MetaData .ID
32
+ }
33
+
34
+
28
35
// Match inspects AST nodes to determine if the match the methods `os.Open` or `ioutil.ReadFile`
29
36
func (r * readfile ) Match (n ast.Node , c * gas.Context ) (* gas.Issue , error ) {
30
37
if node := r .ContainsCallExpr (n , c ); node != nil {
31
38
for _ , arg := range node .Args {
32
39
if ident , ok := arg .(* ast.Ident ); ok {
33
40
obj := c .Info .ObjectOf (ident )
34
41
if _ , ok := obj .(* types.Var ); ok && ! gas .TryResolve (ident , c ) {
35
- return gas .NewIssue (c , n , "File inclusion launched with variable" , gas . Medium , gas . High ), nil
42
+ return gas .NewIssue (c , n , r . What , r . Severity , r . Confidence ), nil
36
43
}
37
44
}
38
45
}
@@ -41,8 +48,16 @@ func (r *readfile) Match(n ast.Node, c *gas.Context) (*gas.Issue, error) {
41
48
}
42
49
43
50
// NewReadFile detects cases where we read files
44
- func NewReadFile (conf gas.Config ) (gas.Rule , []ast.Node ) {
45
- rule := & readfile {gas .NewCallList ()}
51
+ func NewReadFile (id string , conf gas.Config ) (gas.Rule , []ast.Node ) {
52
+ rule := & readfile {
53
+ CallList : gas .NewCallList (),
54
+ MetaData : gas.MetaData {
55
+ ID : id ,
56
+ What : "Potential file inclusion via variable" ,
57
+ Severity : gas .Medium ,
58
+ Confidence : gas .High ,
59
+ },
60
+ }
46
61
rule .Add ("io/ioutil" , "ReadFile" )
47
62
rule .Add ("os" , "Open" )
48
63
return rule , []ast.Node {(* ast .CallExpr )(nil )}
0 commit comments