@@ -23,6 +23,7 @@ private AstNode getSelectPart(Select sel, int index) {
23
23
(
24
24
n = getASubExpression ( sel ) and loc = n .getLocation ( )
25
25
or
26
+ // TODO: Use dataflow instead.
26
27
// the strings are behind a predicate call.
27
28
exists ( Call c , Predicate target | c = getASubExpression ( sel ) and loc = c .getLocation ( ) |
28
29
c .getTarget ( ) = target and
@@ -102,11 +103,11 @@ String shouldStartCapital(Select sel) {
102
103
* select foo(), "XSS from using a unsafe value." // <- good
103
104
* ```
104
105
*/
105
- String avoidHere ( string part ) {
106
+ String avoidHere ( Select sel , string part ) {
106
107
part = [ "here" , "this location" ] and
107
108
(
108
109
result .getValue ( ) .regexpMatch ( ".*\\b" + part + "\\b.*" ) and
109
- result = getSelectPart ( _ , _)
110
+ result = getSelectPart ( sel , _)
110
111
)
111
112
}
112
113
@@ -184,17 +185,33 @@ String doubleWhitespace(Select sel) {
184
185
result .getValue ( ) .regexpMatch ( ".*\\s\\s.*" )
185
186
}
186
187
187
- from AstNode node , string msg
188
+ import codeql.GlobalValueNumbering as GVN
189
+
190
+ /**
191
+ * Gets an expression that repeats the alert-loc as a link.
192
+ */
193
+ AstNode getAlertLocLink ( Select sel ) {
194
+ exists ( GVN:: ValueNumber vn |
195
+ result = vn .getAnExpr ( ) and
196
+ sel .getExpr ( 0 ) = vn .getAnExpr ( )
197
+ ) and
198
+ exists ( int msgIndex | sel .getExpr ( msgIndex ) = sel .getMessage ( ) |
199
+ result = sel .getExpr ( any ( int i | i > msgIndex ) )
200
+ )
201
+ }
202
+
203
+ from AstNode node , string msg , Select sel
188
204
where
189
205
not node .getLocation ( ) .getFile ( ) .getAbsolutePath ( ) .matches ( "%/test/%" ) and
206
+ sel .getQueryDoc ( ) .getQueryKind ( ) = [ "problem" , "path-problem" ] and
190
207
(
191
- node = shouldHaveFullStop ( _ ) and
208
+ node = shouldHaveFullStop ( sel ) and
192
209
msg = "Alert message should end with a full stop."
193
210
or
194
- node = shouldStartCapital ( _ ) and
211
+ node = shouldStartCapital ( sel ) and
195
212
msg = "Alert message should start with a capital letter."
196
213
or
197
- exists ( string part | node = avoidHere ( part ) |
214
+ exists ( string part | node = avoidHere ( sel , part ) |
198
215
part = "here" and
199
216
msg =
200
217
"Try to use a descriptive phrase instead of \"here\". Use \"this location\" if you can't get around mentioning the current location."
@@ -203,19 +220,22 @@ where
203
220
msg = "Try to more descriptive phrase instead of \"this location\" if possible."
204
221
)
205
222
or
206
- node = avoidArticleInLinkText ( _ ) and
223
+ node = avoidArticleInLinkText ( sel ) and
207
224
msg = "Avoid starting a link text with an indefinite article."
208
225
or
209
- node = dontQuoteSubstitutions ( _ ) and
226
+ node = dontQuoteSubstitutions ( sel ) and
210
227
msg = "Don't quote substitutions in alert messages."
211
228
or
212
- node = wrongFlowsPhrase ( _ , "data" ) and
229
+ node = wrongFlowsPhrase ( sel , "data" ) and
213
230
msg = "Use \"flows to\" instead of \"depends on\" in data flow queries."
214
231
or
215
- node = wrongFlowsPhrase ( _ , "taint" ) and
232
+ node = wrongFlowsPhrase ( sel , "taint" ) and
216
233
msg = "Use \"depends on\" instead of \"flows to\" in taint tracking queries."
217
234
or
218
- node = doubleWhitespace ( _ ) and
235
+ node = doubleWhitespace ( sel ) and
219
236
msg = "Avoid using double whitespace in alert messages."
237
+ or
238
+ node = getAlertLocLink ( sel ) and
239
+ msg = "Don't repeat the alert location as a link."
220
240
)
221
241
select node , msg
0 commit comments