mirror of
https://github.com/github/codeql.git
synced 2026-04-28 18:25:24 +02:00
Cover a missing @tag security when @security-severity is used
This commit is contained in:
51
ql/ql/src/queries/style/MissingSecurityMetadata.ql
Normal file
51
ql/ql/src/queries/style/MissingSecurityMetadata.ql
Normal file
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* @name Missing security metadata
|
||||
* @description Security queries should have both a `@tag security` and a `@security-severity` tag.
|
||||
* @kind problem
|
||||
* @problem.severity warning
|
||||
* @precision very-high
|
||||
* @id ql/missing-security-metadata
|
||||
* @tags correctness
|
||||
*/
|
||||
|
||||
import ql
|
||||
|
||||
predicate missingSecuritySeverity(QLDoc doc) {
|
||||
exists(string s | s = doc.getContents() |
|
||||
exists(string securityTag | securityTag = s.splitAt("@") |
|
||||
securityTag.matches("tags%security%")
|
||||
) and
|
||||
exists(string precisionTag | precisionTag = s.splitAt("@") |
|
||||
precisionTag.matches("precision %")
|
||||
) and
|
||||
not exists(string securitySeverity | securitySeverity = s.splitAt("@") |
|
||||
securitySeverity.matches("security-severity %")
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
predicate missingSecurityTag(QLDoc doc) {
|
||||
exists(string s | s = doc.getContents() |
|
||||
exists(string securitySeverity | securitySeverity = s.splitAt("@") |
|
||||
securitySeverity.matches("security-severity %")
|
||||
) and
|
||||
exists(string precisionTag | precisionTag = s.splitAt("@") |
|
||||
precisionTag.matches("precision %")
|
||||
) and
|
||||
not exists(string securityTag | securityTag = s.splitAt("@") |
|
||||
securityTag.matches("tags%security%")
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
from TopLevel t, string msg
|
||||
where
|
||||
t.getLocation().getFile().getBaseName().matches("%.ql") and
|
||||
not t.getLocation().getFile().getRelativePath().matches(["%/experimental/%", "%/examples/%"]) and
|
||||
(
|
||||
missingSecuritySeverity(t.getQLDoc()) and
|
||||
msg = "This query file is missing a `@security-severity` tag."
|
||||
or
|
||||
missingSecurityTag(t.getQLDoc()) and msg = "This query file is missing a `@tag security`."
|
||||
)
|
||||
select t, msg
|
||||
@@ -1,32 +0,0 @@
|
||||
/**
|
||||
* @name Missing security-severity tag
|
||||
* @description Queries tagged as `security` should also have a `@security-severity` tag.
|
||||
* @kind problem
|
||||
* @problem.severity warning
|
||||
* @precision very-high
|
||||
* @id ql/missing-security-severity
|
||||
* @tags correctness
|
||||
*/
|
||||
|
||||
import ql
|
||||
|
||||
predicate missingSecuritySeverity(QLDoc doc) {
|
||||
exists(string s | s = doc.getContents() |
|
||||
exists(string securityTag | securityTag = s.splitAt("@") |
|
||||
securityTag.matches("tags%security%")
|
||||
) and
|
||||
exists(string precisionTag | precisionTag = s.splitAt("@") |
|
||||
precisionTag.matches("precision %")
|
||||
) and
|
||||
not exists(string securitySeverity | securitySeverity = s.splitAt("@") |
|
||||
securitySeverity.matches("security-severity %")
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
from TopLevel t
|
||||
where
|
||||
t.getLocation().getFile().getBaseName().matches("%.ql") and
|
||||
not t.getLocation().getFile().getRelativePath().matches(["%/experimental/%", "%/examples/%"]) and
|
||||
missingSecuritySeverity(t.getQLDoc())
|
||||
select t, "This query file is missing a `@security-severity` tag."
|
||||
@@ -0,0 +1,2 @@
|
||||
| testcases/BadNoSecurity.ql:1:1:15:9 | TopLevel | This query file is missing a `@tag security`. |
|
||||
| testcases/BadNoSeverity.ql:1:1:15:9 | TopLevel | This query file is missing a `@security-severity` tag. |
|
||||
@@ -0,0 +1 @@
|
||||
queries/style/MissingSecurityMetadata.ql
|
||||
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* @name Some query
|
||||
* @description Some description
|
||||
* @kind problem
|
||||
* @problem.severity warning
|
||||
* @security-severity 10.0
|
||||
* @precision very-high
|
||||
* @id ql/some-query
|
||||
* @tags quality
|
||||
*/
|
||||
|
||||
import ql
|
||||
|
||||
from Class c
|
||||
select c
|
||||
@@ -1 +0,0 @@
|
||||
| testcases/Bad.ql:1:1:15:9 | TopLevel | This query file is missing a `@security-severity` tag. |
|
||||
@@ -1 +0,0 @@
|
||||
queries/style/MissingSecuritySeverity.ql
|
||||
Reference in New Issue
Block a user