|  | 
| 1 | 1 | /** | 
| 2 | 2 |  * @name Missing security metadata | 
| 3 |  | - * @description Security queries should have both a `@tag security` and a `@security-severity` tag. | 
|  | 3 | + * @description Security queries should have both a `@tags security` and a `@security-severity` tag. | 
| 4 | 4 |  * @kind problem | 
| 5 | 5 |  * @problem.severity warning | 
| 6 | 6 |  * @precision very-high | 
|  | 
| 10 | 10 | 
 | 
| 11 | 11 | import ql | 
| 12 | 12 | 
 | 
| 13 |  | -predicate missingSecuritySeverity(QLDoc doc) { | 
| 14 |  | -  exists(string s | s = doc.getContents() | | 
| 15 |  | -    exists(string securityTag | securityTag = s.splitAt("@") | | 
| 16 |  | -      securityTag.matches("tags%security%") | 
| 17 |  | -    ) and | 
| 18 |  | -    exists(string precisionTag | precisionTag = s.splitAt("@") | | 
| 19 |  | -      precisionTag.matches("precision %") | 
| 20 |  | -    ) and | 
| 21 |  | -    not exists(string securitySeverity | securitySeverity = s.splitAt("@") | | 
| 22 |  | -      securitySeverity.matches("security-severity %") | 
| 23 |  | -    ) | 
| 24 |  | -  ) | 
|  | 13 | +predicate missingSecuritySeverity(QueryDoc doc) { | 
|  | 14 | +  doc.getAQueryTag() = "security" and | 
|  | 15 | +  exists(doc.getQueryPrecision()) and | 
|  | 16 | +  not exists(doc.getQuerySecuritySeverity()) | 
| 25 | 17 | } | 
| 26 | 18 | 
 | 
| 27 |  | -predicate missingSecurityTag(QLDoc doc) { | 
| 28 |  | -  exists(string s | s = doc.getContents() | | 
| 29 |  | -    exists(string securitySeverity | securitySeverity = s.splitAt("@") | | 
| 30 |  | -      securitySeverity.matches("security-severity %") | 
| 31 |  | -    ) and | 
| 32 |  | -    exists(string precisionTag | precisionTag = s.splitAt("@") | | 
| 33 |  | -      precisionTag.matches("precision %") | 
| 34 |  | -    ) and | 
| 35 |  | -    not exists(string securityTag | securityTag = s.splitAt("@") | | 
| 36 |  | -      securityTag.matches("tags%security%") | 
| 37 |  | -    ) | 
| 38 |  | -  ) | 
|  | 19 | +predicate missingSecurityTag(QueryDoc doc) { | 
|  | 20 | +  exists(doc.getQuerySecuritySeverity()) and | 
|  | 21 | +  exists(doc.getQueryPrecision()) and | 
|  | 22 | +  not doc.getAQueryTag() = "security" | 
| 39 | 23 | } | 
| 40 | 24 | 
 | 
| 41 |  | -from TopLevel t, string msg | 
|  | 25 | +from TopLevel t, QueryDoc doc, string msg | 
| 42 | 26 | where | 
| 43 |  | -  t.getLocation().getFile().getBaseName().matches("%.ql") and | 
| 44 |  | -  not t.getLocation() | 
| 45 |  | -      .getFile() | 
| 46 |  | -      .getRelativePath() | 
| 47 |  | -      .matches("%/" + ["experimental", "examples", "test"] + "/%") and | 
|  | 27 | +  doc = t.getQLDoc() and | 
|  | 28 | +  not t.getLocation().getFile() instanceof TestFile and | 
| 48 | 29 |   ( | 
| 49 |  | -    missingSecuritySeverity(t.getQLDoc()) and | 
|  | 30 | +    missingSecuritySeverity(doc) and | 
| 50 | 31 |     msg = "This query file is missing a `@security-severity` tag." | 
| 51 | 32 |     or | 
| 52 |  | -    missingSecurityTag(t.getQLDoc()) and msg = "This query file is missing a `@tag security`." | 
|  | 33 | +    missingSecurityTag(doc) and msg = "This query file is missing a `@tags security`." | 
| 53 | 34 |   ) | 
| 54 |  | -select t, msg | 
|  | 35 | +select doc, msg | 
0 commit comments