CodeQL 查询语法
$HOME/vscode-codeql-starter/ql/javascript/ql/test/query-tests/Security
codeql.exe database create security-test --language=javascript
基础查询语法结构
/**
*
* Query metadata
*
*/
import /* ... CodeQL libraries or modules ... */
/* ... Optional, define CodeQL classes and predicates ... */
from /* ... 变量声明 ... */
where /* ... 逻辑处理 ... */
select /* ... 表达式 ... */
元数据
import 语句
from 字句
可选,用来声明变量,所有变量必须指定类型
变量类型:https://codeql.github.com/docs/ql-language-reference/types/
from <type> <variable name>
where 字句
可选,用来对from字句中声明的变量做逻辑处理。
可以使用聚合、谓词和逻辑公式筛选出满足条件的数据集合。
CodeQL 库对特定语言和框架的常用谓词进行分组。如上所述,您还可以在查询文件的正文或您自己的自定义模块中定义您自己的谓词。
select 字句
必需,用来输出,通常放在文件的结尾。
通常至少包括两列,Element列用来返回触发规则的代码位置,String列用来描述生成该告警的描述信息。
select element, string
可以使用as关键字自定义字段名/列名
可以使用order by关键字排序
import javascript
from int x, int y
where x = 3 and y in [0 .. 2]
select x, y, x * y as product, "product: " + product
order by product desc