我是CodeQL新手,因此我很抱歉,如果我的问题是显而易见的,然而,我无法理解一些简单的概念。
首先,我可以使用配置如下的yml文件轻松地使用github操作配置公共回购:
on:
push:
branches: [ master ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master ]
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [ 'java' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
steps:
- name: Checkout repository
uses: actions/checkout@v3
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
queries: +security-extended
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
# ℹ️ Command-line programs to run using the OS shell.
# See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2如yaml文件所示,我使用Java作为语言。然后,我要做的是用一个简单的代码触发一个失败/警报,比如Java中的这个代码。
public class Main {
public static void main(String[] args) {
// Example code for https://cwe.mitre.org/data/definitions/476.html
String cmd = System.getProperty("cmd");
cmd = cmd.trim();
}
}这个简单的代码是公共弱点枚举(CWE) 416中的一个例子,在其中我试图取消引用一个尚未定义的变量。
如果我转到“安全->代码扫描警报”,它将显示已执行扫描,但未找到警报。
基本上,我想知道是否需要在yaml文件的initialize步骤下使用特定的CWE初始化CodeQL。

发布于 2022-05-27 20:31:43
CodeQL只有一个特定的查询集,它不包括所有可能的CWEs。这份清单显示了当前覆盖的用于Java的CWEs。
据我所知,目前还没有发现您在问题中显示的特定问题的查询(但是有null)。这样做的原因很可能是很难防止出现假阳性。例如,如果您的应用程序是用-Dcmd启动的,那么系统属性将不是null。类似地,在应用程序的不同部分可以调用System.setProperty,该部分将系统属性设置为非null值。
此外,您已经配置了queries: +security-extended,但是您正在寻找的查询类型(假设它存在)很可能在security-and-quality中,因为它与安全无关。
您还可以尝试写你自己的查询,然后是将它们包含在代码扫描工作流中。。CodeQL的一些概念一开始可能有点陌生,但它们为入门提供了很好的示例和教程。但是,您可能应该首先检查所提供的查询是否足以满足您的用例。
https://stackoverflow.com/questions/72384905
复制相似问题