@@ -39,6 +39,16 @@ private AstNode getSelectPart(Select sel, int index) {
39
39
)
40
40
}
41
41
42
+ /**
43
+ * Gets a string element that is the last part of the message, that doesn't end with a full stop.
44
+ *
45
+ * E.g.
46
+ * ```CodeQL
47
+ * select foo(), "This is a description" // <- bad
48
+ *
49
+ * select foo(), "This is a description." // <- good
50
+ * ```
51
+ */
42
52
String shouldHaveFullStop ( Select sel ) {
43
53
result =
44
54
max ( AstNode str , int i |
@@ -50,6 +60,16 @@ String shouldHaveFullStop(Select sel) {
50
60
not result .getValue ( ) .matches ( "%?" )
51
61
}
52
62
63
+ /**
64
+ * Gets a string element that is the first part of the message, that starts with a lower case letter.
65
+ *
66
+ * E.g.
67
+ * ```CodeQL
68
+ * select foo(), "this is a description." // <- bad
69
+ *
70
+ * select foo(), "This is a description." // <- good
71
+ * ```
72
+ */
53
73
String shouldStartCapital ( Select sel ) {
54
74
result =
55
75
min ( AstNode str , int i |
@@ -60,31 +80,64 @@ String shouldStartCapital(Select sel) {
60
80
result .getValue ( ) .regexpMatch ( "^[a-z].*" )
61
81
}
62
82
63
- // see https://www.w3.org/WAI/WCAG22/Understanding/link-purpose-in-context.html
83
+ /**
84
+ * Gets a string element that is used in a message that contains "here" or "this location".
85
+ *
86
+ * E.g.
87
+ * ```CodeQL
88
+ * select foo(), "XSS happens here from using a unsafe value." // <- bad
89
+ *
90
+ * select foo(), "XSS from using a unsafe value." // <- good
91
+ * ```
92
+ */
64
93
String avoidHere ( string part ) {
65
- part = [ "here" , "this location" ] and // TODO: prefer "this location" of the two.
94
+ part = [ "here" , "this location" ] and
66
95
(
67
96
result .getValue ( ) .regexpMatch ( ".*\\b" + part + "\\b.*" ) and
68
97
result = getSelectPart ( _, _)
69
98
)
70
99
}
71
100
72
- // see https://www.w3.org/WAI/WCAG22/Understanding/link-purpose-in-context.html
101
+ /**
102
+ * Avoid using an indefinite article ("a" or "an") in a link text.
103
+ *
104
+ * E.g.
105
+ * ```CodeQL
106
+ * select foo(), "XSS from $@", val, "an unsafe value." // <- bad
107
+ *
108
+ * select foo(), "XSS from a $@", val, "unsafe value." // <- good
109
+ * ```
110
+ *
111
+ * See https://www.w3.org/WAI/WCAG22/Understanding/link-purpose-in-context.html for the W3C guideline on link text. a
112
+ */
73
113
String avoidArticleInLinkText ( Select sel ) {
74
114
result = sel .getExpr ( ( any ( int i | i > 1 ) ) ) and
75
115
result = getSelectPart ( sel , _) and
76
116
result .getValue ( ) .regexpMatch ( "a|an .*" )
77
117
}
78
118
119
+ /**
120
+ * Don't quote substitutions in a message.
121
+ *
122
+ * E.g.
123
+ * ```CodeQL
124
+ * select foo(), "XSS from '$@'", val, "an unsafe value." // <- bad
125
+ *
126
+ * select foo(), "XSS from $@", val, "an unsafe value." // <- good
127
+ * ```
128
+ */
79
129
String dontQuoteSubstitutions ( Select sel ) {
80
130
result = getSelectPart ( sel , _) and
81
131
result .getValue ( ) .matches ( [ "%'$@'%" , "%\"$@\"%" ] )
82
132
}
83
133
84
- // "data" or "taint"
85
- string getQueryKind ( Select s ) {
134
+ /**
135
+ * Gets the kind of the path-query represented by `sel`.
136
+ * Either "data" for a dataflow query or "taint" for a taint-tracking query.
137
+ */
138
+ private string getQueryKind ( Select sel ) {
86
139
exists ( TypeExpr sup |
87
- sup = s .getVarDecl ( _) .getType ( ) .( ClassType ) .getDeclaration ( ) .getASuperType ( ) and
140
+ sup = sel .getVarDecl ( _) .getType ( ) .( ClassType ) .getDeclaration ( ) .getASuperType ( ) and
88
141
sup .getResolvedType ( ) .( ClassType ) .getName ( ) = "Configuration"
89
142
|
90
143
result = "data" and
@@ -95,6 +148,10 @@ string getQueryKind(Select s) {
95
148
)
96
149
}
97
150
151
+ /**
152
+ * Gets a string element from a message that uses the wrong phrase for a path query.
153
+ * A dataflow query should use "flows to" and a taint-tracking query should use "depends on".
154
+ */
98
155
String wrongFlowsPhrase ( Select sel , string kind ) {
99
156
result = getSelectPart ( sel , _) and
100
157
kind = getQueryKind ( sel ) and
0 commit comments