File tree Expand file tree Collapse file tree
go/ql/lib/semmle/go/security Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -81,4 +81,33 @@ module InsecureRandomness {
8181 /** Gets a package that implements hash algorithms. */
8282 bindingset [ result ]
8383 private string getAHashPkg ( ) { result .regexpMatch ( "crypto/(md5|sha(1|256|512)|rand)" ) }
84+
85+ /**
86+ * A function that hashes input, which is considered as a taint propagator for use of
87+ * cryptographically insecure random values.
88+ */
89+ class HashAlgorithm extends TaintTracking:: FunctionModel {
90+ HashAlgorithm ( ) {
91+ exists ( Method m | this = m |
92+ m .implements ( "hash" , "Hash" , "Sum" )
93+ or
94+ m .implements ( "hash" , "Hash32" , "Sum32" )
95+ or
96+ m .implements ( "hash" , "Hash64" , "Sum64" )
97+ )
98+ or
99+ exists ( string pkg , string name | this .hasQualifiedName ( pkg , name ) |
100+ pkg = getAHashPkg ( ) and name .matches ( "Sum%" )
101+ )
102+ }
103+
104+ override predicate hasTaintFlow ( FunctionInput inp , FunctionOutput outp ) {
105+ if this instanceof Method
106+ then (
107+ inp .isReceiver ( ) and outp .isResult ( )
108+ ) else (
109+ inp .isParameter ( 0 ) and outp .isResult ( )
110+ )
111+ }
112+ }
84113}
You can’t perform that action at this time.
0 commit comments