@@ -111,13 +111,24 @@ module HardcodedCredentials {
111
111
}
112
112
113
113
/**
114
- * Gets a regular expression for matching names of locations (variables, parameters, keys) that
115
- * indicate the value being held is a credential.
114
+ * An assignable whose name indicates that the value being held is a credential.
116
115
*/
117
- private string getACredentialRegex ( ) {
118
- result = "(?i).*pass(wd|word|code|phrase)(?!.*question).*" or
119
- result = "(?i).*(puid|username|userid).*" or
120
- result = "(?i).*(cert)(?!.*(format|name)).*"
116
+ private class CredentialVar extends Assignable {
117
+ pragma [ noinline]
118
+ CredentialVar ( ) {
119
+ exists ( string name | name = this .getName ( ) |
120
+ name .regexpMatch ( "(?i).*pass(wd|word|code|phrase)(?!.*question).*" )
121
+ or
122
+ name .regexpMatch ( "(?i).*(puid|username|userid).*" )
123
+ or
124
+ name .regexpMatch ( "(?i).*(cert)(?!.*(format|name)).*" )
125
+ )
126
+ }
127
+ }
128
+
129
+ private class CredentialVariableAccess extends VariableAccess {
130
+ pragma [ noinline]
131
+ CredentialVariableAccess ( ) { this .getTarget ( ) instanceof CredentialVar }
121
132
}
122
133
123
134
/**
@@ -128,11 +139,11 @@ module HardcodedCredentials {
128
139
) {
129
140
// An argument to a library call that looks like a credential
130
141
// "...flows to the [Username] parameter in [call to method CreateUser]"
131
- exists ( Call call |
142
+ exists ( Call call , CredentialVar param |
132
143
supplementaryElement = call and
133
144
description = "the $@ parameter in $@" and
134
- sink = call .getArgumentForName ( sinkName ) and
135
- sinkName . regexpMatch ( getACredentialRegex ( ) ) and
145
+ sink = call .getArgumentForParameter ( param ) and
146
+ sinkName = param . getName ( ) and
136
147
call .getTarget ( ) .fromLibrary ( )
137
148
)
138
149
or
@@ -144,22 +155,20 @@ module HardcodedCredentials {
144
155
description = "the $@ in $@" and
145
156
sink = call .getArgument ( 0 ) and
146
157
sinkName = "setter call argument" and
147
- p . getName ( ) . regexpMatch ( getACredentialRegex ( ) ) and
158
+ p instanceof CredentialVar and
148
159
p .fromLibrary ( )
149
160
)
150
161
or
151
162
// Sink compared to password variable
152
163
// "...flows to [] which is compared against [access of UserName]"
153
- exists ( ComparisonTest ct , VariableAccess credentialAccess , string varName |
164
+ exists ( ComparisonTest ct , CredentialVariableAccess credentialAccess |
154
165
sinkName = sink .toString ( ) and
155
166
supplementaryElement = credentialAccess and
156
167
description = "$@ which is compared against $@" and
157
168
ct .getAnArgument ( ) = credentialAccess and
158
169
ct .getAnArgument ( ) = sink and
159
170
ct .getComparisonKind ( ) .isEquality ( ) and
160
- not sink = credentialAccess and
161
- varName = credentialAccess .getTarget ( ) .getName ( ) and
162
- varName .regexpMatch ( getACredentialRegex ( ) )
171
+ not sink = credentialAccess
163
172
)
164
173
}
165
174
0 commit comments