Skip to content

Commit 03f3535

Browse files
committed
Added MissingSecuritySeverity query
1 parent bcdbfef commit 03f3535

File tree

10 files changed

+79
-0
lines changed

10 files changed

+79
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* @name Missing security-severity tag
3+
* @description Queries tagged as `security` should also have a `@security-severity` tag.
4+
* @kind problem
5+
* @problem.severity warning
6+
* @precision very-high
7+
* @id ql/missing-security-severity
8+
* @tags correctness
9+
*/
10+
11+
import ql
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+
not exists(string securitySeverity | securitySeverity = s.splitAt("@") |
19+
securitySeverity.matches("security-severity %")
20+
)
21+
)
22+
}
23+
24+
from TopLevel t
25+
where
26+
t.getLocation().getFile().getBaseName().matches("%.ql") and
27+
not t.getLocation().getFile().getRelativePath().matches("%/experimental/%") and
28+
missingSecuritySeverity(t.getQLDoc())
29+
select t, "This query file is missing a `@security-severity` tag."
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| testcases/Bad.ql:1:1:15:9 | TopLevel | This query file is missing a `@security-severity` tag. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
queries/style/MissingSecuritySeverity.ql

ql/ql/test/queries/style/MissingSecuritySeverity/testcases/Bad.expected

Whitespace-only changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @name Some query
3+
* @description Some description
4+
* @kind problem
5+
* @problem.severity warning
6+
* @precision very-high
7+
* @id ql/some-query
8+
* @tags quality
9+
* security
10+
*/
11+
12+
import ql
13+
14+
from Class c
15+
select c

ql/ql/test/queries/style/MissingSecuritySeverity/testcases/Good.expected

Whitespace-only changes.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @name Some query
3+
* @description Some description
4+
* @kind problem
5+
* @problem.severity warning
6+
* @security-severity 10.0
7+
* @precision very-high
8+
* @id ql/some-query
9+
* @tags quality
10+
* security
11+
*/
12+
13+
import ql
14+
15+
from Class c
16+
select c

ql/ql/test/queries/style/MissingSecuritySeverity/testcases/NoSecurity.expected

Whitespace-only changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @name Some query
3+
* @description Some description
4+
* @kind problem
5+
* @problem.severity warning
6+
* @precision very-high
7+
* @id ql/some-query
8+
* @tags quality
9+
*/
10+
11+
import ql
12+
13+
from Class c
14+
select c
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import ql
2+
3+
FieldDecl getAField(Class c) { result = c.getAField() }

0 commit comments

Comments
 (0)