Software developers and security researchers can secure their code using CodeQL analysis. For more information about CodeQL, see About code scanning with CodeQL.
Die CodeQL CLI ist ein eigenständiges Befehlszeilentool, mit dem du Code analysieren kannst. Ihr Hauptzweck besteht darin, eine Datenbankdarstellung einer Codebasis zu generieren: eine CodeQL-Datenbank. Wenn die Datenbank bereit ist, können Sie sie interaktiv abfragen oder eine Reihe von Abfragen ausführen, um Ergebnissets im SARIF-Format zu generieren und sie auf GitHub hochzuladen.
You can use the CodeQL CLI to:
- Run CodeQL analyses using queries provided by GitHub engineers and the open source community
- Generate code scanning alerts that you can upload to display in GitHub
- Create CodeQL databases to use in the CodeQL for Visual Studio Code extension.
- Develop and test custom CodeQL queries to use in your own analyses
The CodeQL CLI can analyze:
- Dynamic languages, for example, JavaScript and Python.
- Compiled languages, for example, C/C++, C#, Go, Java, Kotlin, Rust, und Swift
- Codebases written in a mixture of languages.
For information about setting up the CodeQL CLI, see Einrichten der CodeQL-CLI.
About using the CodeQL CLI for code scanning
You can use the CodeQL CLI to run code scanning on code that you're processing in a third-party continuous integration (CI) system. Code scanning ist ein Feature, das du zum Analysieren des Codes in einem GitHub-Repository verwendest, um Sicherheitsrisiken und Codefehler zu finden. Alle von der Analyse ermittelten Probleme werden im Repository angezeigt. For an overview of using code scanning with external CI systems, see Verwenden der Codeüberprüfung mit deinem vorhandenen CI-System. For recommended specifications (RAM, CPU cores, and disk) for running CodeQL analysis, see Empfohlene Hardwareressourcen zum Ausführen von CodeQL.
Alternatively, you can use GitHub Actions or Azure DevOps pipelines to scan code using the CodeQL CLI. For more information, see Konfigurieren des Standardsetups für das Codescanning or Configure GitHub Advanced Security for Azure DevOps in Microsoft Learn.
For an overview of all the options for using CodeQL analysis for code scanning, see About code scanning with CodeQL.
Hinweis
- Die CodeQL CLI kann in öffentlichen Repositorys kostenlos eingesetzt werden. Die CodeQL CLI ist ebenfalls in privaten Repositorys im Besitz von Organisationen verfügbar, die GitHub Team oder GitHub Enterprise Cloud verwenden und über eine Lizenz für GitHub Code Security verfügen. Weitere Informationen findest du in den Geschäftsbedingungen von GitHub CodeQL und der CodeQL-CLI.
- Die CodeQL CLI ist derzeit nicht mit Nicht-Glibc-Linux-Distributionen wie (musl-basiertem) Alpine Linux kompatibel.
About generating code scanning results with the CodeQL CLI
If you choose to run the CodeQL CLI directly, you first have to install the CodeQL CLI locally. If you are planning to use the CodeQL CLI with an external CI system, you need to make the CodeQL CLI available to servers in your CI system. For more information, see Einrichten der CodeQL-CLI.
Once the CodeQL CLI is set up, you can use three different commands to generate results and upload them to GitHub:
database createto create a CodeQL database to represent the hierarchical structure of each supported programming language in the repository. For more information, see Vorbereiten des Codes für die CodeQL-Analyse.database analyzeto run queries to analyze each CodeQL database and summarize the results in a SARIF file. For more information, see Analysieren des Codes mit CodeQL-Abfragen.github upload-resultsto upload the resulting SARIF files to GitHub where the results are matched to a branch or pull request and displayed as code scanning alerts. For more information, see Hochladen von CodeQL-Analyseergebnissen auf GitHub.
Hinweis
Das Hochladen von SARIF-Daten zur Anzeige von code scanning-Ergebnissen in GitHub wird für Repositorys im Besitz von Organisationen mit aktivierter GitHub Code Security und öffentliche Repositorys auf GitHub.com unterstützt. Weitere Informationen finden Sie unter Verwalten von Sicherheits- und Analyseeinstellungen für dein Repository.
Example CI configuration for CodeQL analysis
This is an example of the full series of commands for the CodeQL CLI that you might use to analyze a codebase with two supported languages and then upload the results to GitHub.
# Create CodeQL databases for Java and Python in the 'codeql-dbs' directory
# Call the normal build script for the codebase: 'myBuildScript'
codeql database create codeql-dbs --source-root=src \
--db-cluster --language=java,python --command=./myBuildScript
# Analyze the CodeQL database for Java, 'codeql-dbs/java'
# Tag the data as 'java' results and store in: 'java-results.sarif'
codeql database analyze codeql-dbs/java java-code-scanning.qls \
--format=sarif-latest --sarif-category=java --output=java-results.sarif
# Analyze the CodeQL database for Python, 'codeql-dbs/python'
# Tag the data as 'python' results and store in: 'python-results.sarif'
codeql database analyze codeql-dbs/python python-code-scanning.qls \
--format=sarif-latest --sarif-category=python --output=python-results.sarif
# Upload the SARIF file with the Java results: 'java-results.sarif'
# The GitHub App or personal access token created for authentication
# with GitHub's REST API is available in the `GITHUB_TOKEN` environment variable.
codeql github upload-results \
--repository=my-org/example-repo \
--ref=refs/heads/main --commit=deb275d2d5fe9a522a0b7bd8b6b6a1c939552718 \
--sarif=java-results.sarif
# Upload the SARIF file with the Python results: 'python-results.sarif'
codeql github upload-results \
--repository=my-org/example-repo \
--ref=refs/heads/main --commit=deb275d2d5fe9a522a0b7bd8b6b6a1c939552718 \
--sarif=python-results.sarif
Informationen zur GitHub CodeQL-Lizenz
Lizenzhinweis: Wenn du über keine Lizenz für GitHub Code Security verfügst, stimmst du bei der Installation dieses Produkts den Geschäftsbedingungen für GitHub CodeQL zu.
Informationen zum kostenlosen Testen von GitHub Enterprise mit GitHub Advanced Security findest du in der GitHub Enterprise Cloud-Dokumentation unter Eine Testversion von GitHub Enterprise einrichten und Einrichten einer Testversion von GitHub Advanced Security.