-
Notifications
You must be signed in to change notification settings - Fork 17
Codeql install updates #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
06504e8
2b4d2a1
003ca49
178b0fb
fed2e65
5fba928
4a00784
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,71 @@ | |
| If you are using the CodeQL VSCode extension to write and run queries, [it can | ||
| initialize the query pack and create the `qlpack.yml` file automatically](#running-custom-queries-using-the-vscode-extension). | ||
|
|
||
| Finally, you have to create a [workspace file](https://docs.github.com/en/code-security/codeql-cli/using-the-advanced-functionality-of-the-codeql-cli/about-codeql-workspaces) for CodeQL CLI to work correctly. | ||
|
|
||
| Most probably you will write at least a few packs. Setup the following directory structure for the easiest development: | ||
GrosQuildu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
|
Check failure on line 44 in content/docs/static-analysis/codeql/10-advanced.md
|
||
| . | ||
| ├── CODEOWNERS | ||
| ├── README.md | ||
| ├── codeql-workspace.yml | ||
| ├── cpp | ||
| │ ├── lib | ||
| │ │ ├── qlpack.yml | ||
| │ │ └── scope | ||
| │ │ └── crypto | ||
| │ │ └── someLibrary.qll | ||
| │ ├── src | ||
| │ │ ├── qlpack.yml | ||
| │ │ ├── codeql-suites | ||
| │ │ │ ├── scope-cpp-code-scanning.qls | ||
| │ │ │ └── scope-cpp-security.qls | ||
| │ │ ├── crypto | ||
| │ │ │ ├── SomeCryptoAnalysis.ql | ||
| │ │ ├── security | ||
| │ │ │ ├── AppSecAnalysis | ||
| │ │ │ │ ├── AppSecAnalysis.c | ||
| │ │ │ │ ├── AppSecAnalysis.qhelp | ||
| │ │ │ │ └── AppSecAnalysis.ql | ||
| │ │ ├── docs | ||
| │ │ │ ├── crypto | ||
| │ │ │ │ ├── SomeCryptoAnalysis.md | ||
| │ │ │ └── security | ||
| │ │ │ └── AppSecAnalysis.md | ||
| │ └── test | ||
| │ ├── qlpack.yml | ||
| │ ├── include | ||
| │ │ ├── libc | ||
| │ │ │ ├── stubs.h | ||
| │ ├── library-tests | ||
| │ │ └── crypto | ||
| │ │ ├── someLibrary | ||
| │ │ │ ├── someLibrary.expected | ||
| │ │ │ ├── someLibrary.ql | ||
| │ │ │ └── someLibrary.c | ||
| │ └── query-tests | ||
| │ ├── crypto | ||
| │ │ ├── SomeCryptoAnalysis | ||
| │ │ │ ├── SomeCryptoAnalysis.expected | ||
| │ │ │ ├── SomeCryptoAnalysis.qlref | ||
| │ │ │ └── SomeCryptoAnalysis.c | ||
| │ └── security | ||
| │ └── AppSecAnalysis | ||
| │ ├── AppSecAnalysis.c | ||
| │ ├── AppSecAnalysis.expected | ||
| │ └── AppSecAnalysis.qlref | ||
| ├── go | ||
| │ ├── src | ||
| ... | ||
| ``` | ||
|
|
||
| We divide query packs per-language, but also per-type (security, cryptographic, etc.). This follows GitHub's convention. | ||
GrosQuildu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| For setting-up unit tests continue reading to [Unit testing custom queries](#unit-testing-custom-queries) section. | ||
GrosQuildu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Finally, you can use [our bash script for generating new queries](https://github.com/trailofbits/codeql-queries/tree/main/scripts/new_query.sh) when you have the structure above. | ||
GrosQuildu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
|
Check failure on line 105 in content/docs/static-analysis/codeql/10-advanced.md
|
||
| ### Adding dependencies | ||
|
|
||
| To be able to define a custom query we need to import the CodeQL standard | ||
|
|
@@ -199,6 +264,16 @@ | |
| of the version you want, you can use `"*"` which always resolves to the latest | ||
| version.) | ||
|
|
||
| ### Installing the new packs | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this step still necessary if you've properly set up your workspace with I ask because I've had some trouble between using
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure? You need codeql to known the location somehow, would it auto-pick locally cloned repo? Fell free to update this section anyway. |
||
|
|
||
| Once you have initialized the new query pack, added dependencies and some sample query, you need to run | ||
GrosQuildu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| `codeql pack install` in every directory that has a qlpack.yml file (including folders with test). | ||
|
|
||
| Then, inform the codeql CLI about your new queries by creating `~/.config/codeql/config` file with the following content: | ||
| ``` | ||
|
Check failure on line 273 in content/docs/static-analysis/codeql/10-advanced.md
|
||
| --search-path /full/path/to/your/codeql/root/directory | ||
| ``` | ||
|
|
||
| ## Writing custom queries | ||
|
|
||
| {{< hint info >}} | ||
|
|
@@ -476,8 +551,12 @@ | |
| - `MemcpyCall.expected`: A text file containing the expected output from | ||
| running the query against the source file | ||
|
|
||
| The source file must build cleanly without any external dependencies. To test | ||
| the query, run the following command: | ||
| The source file must build cleanly without any external dependencies. | ||
| This requirement is problematic mostly for C/C++ queries: you need to create | ||
| stub files with `extern` declarations for libraries you want to `#include`. | ||
| Check [our tests](https://github.com/trailofbits/codeql-queries/blob/d994c7ca05dab30fe195555ef6943f9d51ec38df/cpp/test/query-tests/security/CStrnFinder/test.c#L1) for examples. | ||
GrosQuildu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| To test the query, run the following command: | ||
|
|
||
| ```sh | ||
| codeql test run -- path/to/test/pack/root/directory | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.