Skip to content

Commit d45ba51

Browse files
authored
Update docs and add publish workflow (#40)
* update readme * move queries doc. simplify instructions. update dependencies. * add publish workflow * add dependabot. add issue templates * restored deleted docs * restore iteratorinvalidation * add .qhelp files to generate markdown files * update workflow permissions and pin versions * update workflow permission. update dependencies. format python script. fix typo * update datatype annotation * fix typos. fix markdown paths. * focus bug report template. verify QUERIES is up to date. small edits to .ql and .qhelp files.
1 parent 8b2adfc commit d45ba51

55 files changed

Lines changed: 859 additions & 418 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
name: Bug report
3+
about: Report a false positive, false negative, or crash in a query
4+
title: ''
5+
labels: bug
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the bug**
11+
A clear description of what is wrong. Is this a false positive, false negative, crash, or something else?
12+
13+
**Query involved**
14+
Which query or pack is affected (for example, `trailofbits/cpp-queries` or the specific query ID reported in the alert).
15+
16+
**To reproduce**
17+
1. CodeQL CLI version (`codeql --version`):
18+
2. Language/database under analysis:
19+
3. Exact command invocation:
20+
4. Minimal code snippet or repository link that triggers the issue:
21+
22+
**Expected behavior**
23+
What you expected the query to report (or not report).
24+
25+
**Actual behavior**
26+
What the query actually reported, including alert locations and any error output.
27+
28+
**Additional context**
29+
Add any other context about the problem here.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: enhancement
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe.**
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
**Describe the solution you'd like**
14+
A clear and concise description of what you want to happen.
15+
16+
**Describe alternatives you've considered**
17+
A clear and concise description of any alternative solutions or features you've considered.
18+
19+
**Additional context**
20+
Add any other context or screenshots about the feature request here.

.github/dependabot.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: 2
2+
3+
updates:
4+
- package-ecosystem: github-actions
5+
cooldown:
6+
default-days: 7
7+
directory: /
8+
groups:
9+
actions:
10+
patterns:
11+
- "*"
12+
schedule:
13+
interval: daily

.github/workflows/publish.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Publish CodeQL packs
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
permissions: {}
8+
9+
jobs:
10+
publish:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
packages: write
15+
steps:
16+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
17+
with:
18+
persist-credentials: false
19+
- uses: trailofbits/setup-codeql@615e3864087261d42cce229e3eec419ab9b22c36 # main
20+
with:
21+
version: '2.25.1'
22+
platform: 'linux64'
23+
checksum: '4f070e6cc7009e75aec307ed109c2fcf0501e579c20a31080b893e31209523d5'
24+
- run: make test
25+
- run: make publish
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,24 @@ on:
66
branches:
77
- main
88

9+
permissions: {}
10+
911
jobs:
1012
main:
1113
runs-on: ubuntu-latest
1214
steps:
13-
- uses: actions/checkout@v6
14-
- uses: trailofbits/setup-codeql@main
15+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
16+
with:
17+
persist-credentials: false
18+
- uses: trailofbits/setup-codeql@615e3864087261d42cce229e3eec419ab9b22c36 # main
1519
with:
16-
version: '2.23.8'
20+
version: '2.25.1'
1721
platform: 'linux64'
18-
checksum: 'e61bc8aa8d86d45acd9d1c36629a12bbfb3365cd07a31666a2ebc91c6a1940b2'
22+
checksum: '4f070e6cc7009e75aec307ed109c2fcf0501e579c20a31080b893e31209523d5'
23+
- uses: astral-sh/setup-uv@cec208311dfd045dd5311c1add060b2062131d57 # v8.0.0
1924
- run: make format-check
2025
- run: make test
26+
- name: Verify doc/QUERIES.md is up to date
27+
run: |
28+
make generate-table
29+
git diff --exit-code doc/QUERIES.md

CLAUDE.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,19 @@ Test `.cpp` files include stubs via relative paths:
5353

5454
Stubs only need enough declarations for CodeQL to resolve types and function names — no implementations required.
5555

56-
## Updating README Query Tables
56+
## Updating Query Tables
5757

58-
When a query is added, removed, or its metadata changes, regenerate the README tables:
58+
When a query is added, removed, or its metadata changes, regenerate `doc/QUERIES.md`:
5959
```sh
60-
python ./scripts/queries_table_generator.py 2>/dev/null
60+
make generate-table
6161
```
6262

63-
This reads query metadata from all "full" suites and outputs markdown tables. Copy-paste the output into `README.md` under the `## Queries` section.
63+
This reads query metadata from all "full" suites and writes markdown tables to `doc/QUERIES.md`. The file is generated — do not hand-edit it.
64+
65+
The accompanying per-query markdown docs in `<lang>/src/docs/` are regenerated from each query's `.qhelp` file with:
66+
```sh
67+
make generate-help
68+
```
6469

6570
## Qlpack Versioning
6671

Makefile

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ format-check:
1010
find . \( -iname '*.ql' -o -iname '*.qll' \) -print0 | \
1111
xargs -0 codeql query format --check-only
1212

13+
download:
14+
codeql pack download trailofbits/cpp-all trailofbits/cpp-queries trailofbits/go-queries trailofbits/java-queries
15+
1316
pack-install:
1417
find . -iname "qlpack.yml" -exec \
1518
sh -c 'codeql pack install $$(dirname "$$1")' sh {} \;
@@ -18,4 +21,20 @@ pack-upgrade:
1821
find . -iname "qlpack.yml" -exec \
1922
sh -c 'codeql pack upgrade $$(dirname "$$1")' sh {} \;
2023

21-
.PHONY: test format format-check pack-install pack-upgrade
24+
generate-table:
25+
uv run --with pyyaml \
26+
python ./scripts/queries_table_generator.py > doc/QUERIES.md.tmp
27+
mv doc/QUERIES.md.tmp doc/QUERIES.md
28+
29+
generate-help:
30+
codeql generate query-help ./cpp/src/ --format=markdown --output ./cpp/src/docs
31+
codeql generate query-help ./go/src/ --format=markdown --output ./go/src/docs
32+
codeql generate query-help ./java/src/ --format=markdown --output ./java/src/docs
33+
34+
publish:
35+
codeql pack publish cpp/lib/
36+
codeql pack publish cpp/src/
37+
codeql pack publish go/src/
38+
codeql pack publish java/src/
39+
40+
.PHONY: test format format-check download pack-install pack-upgrade generate-table generate-help publish

README.md

Lines changed: 24 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -2,137 +2,54 @@
22

33
This repository contains CodeQL queries developed by Trail of Bits and made available to the public. They are part of our ongoing development efforts and are used in our security audits, vulnerability research, and internal projects. They will evolve over time as we identify new techniques.
44

5-
## Using custom CodeQL queries
5+
## Setup
66

7-
The easiest is to [download all packs](https://docs.github.com/en/code-security/codeql-cli/using-the-advanced-functionality-of-the-codeql-cli/publishing-and-using-codeql-packs#running-codeql-pack-download-scopepack) from the GitHub registry:
8-
```sh
9-
codeql pack download trailofbits/cpp-queries trailofbits/go-queries
7+
```bash
8+
make download
9+
codeql resolve packs | grep trailofbits
1010
```
1111

12-
Then verify that new queries are installed:
13-
```sh
14-
codeql resolve qlpacks | grep trailofbits
15-
```
12+
See [QUERIES.md](doc/QUERIES.md) for the full list of queries.
1613

17-
And use the queries for analysis:
18-
```sh
14+
## Usage
15+
16+
```bash
1917
codeql database analyze database.db --format=sarif-latest --output=./tob.sarif -- trailofbits/cpp-queries
20-
# or
2118
codeql database analyze database.db --format=sarif-latest --output=./tob.sarif -- trailofbits/go-queries
19+
codeql database analyze database.db --format=sarif-latest --output=./tob.sarif -- trailofbits/java-queries
2220
```
2321

24-
## Queries
25-
26-
### C and C++
27-
28-
#### Cryptography
29-
30-
| Name | Description | Severity | Precision |
31-
| --- | ----------- | :----: | :--------: |
32-
|[BN_CTX_free called before BN_CTX_end](./cpp/src/docs/crypto/BnCtxFreeBeforeEnd.md)|Detects BN_CTX_free called before BN_CTX_end, which violates the required lifecycle|error|medium|
33-
|[Unbalanced BN_CTX_start and BN_CTX_end pair](./cpp/src/docs/crypto/UnbalancedBnCtx.md)|Detects if one call in the BN_CTX_start/BN_CTX_end pair is missing|warning|medium|
34-
|[Crypto variable initialized using static key](./cpp/src/docs/crypto/StaticKeyFlow.md)|Finds crypto variables initialized using static keys|error|high|
35-
|[Crypto variable initialized using static password](./cpp/src/docs/crypto/StaticPasswordFlow.md)|Finds crypto variables initialized using static passwords|error|high|
36-
|[Crypto variable initialized using weak randomness](./cpp/src/docs/crypto/WeakRandomnessTaint.md)|Finds crypto variables initialized using weak randomness|error|high|
37-
|[Invalid key size](./cpp/src/docs/crypto/InvalidKeySize.md)|Tests if keys passed to EVP_EncryptInit and EVP_EncryptInit_ex have the same size as the key size of the cipher used|warning|medium|
38-
|[Memory leak related to custom allocator](./cpp/src/docs/crypto/CustomAllocatorLeak.md)|Finds memory leaks from custom allocated memory|warning|medium|
39-
|[Memory use after free related to custom allocator](./cpp/src/docs/crypto/CustomAllocatorUseAfterFree.md)|Finds use-after-frees related to custom allocators like `BN_new`|warning|medium|
40-
|[Missing OpenSSL engine initialization](./cpp/src/docs/crypto/MissingEngineInit.md)|Finds created OpenSSL engines that may not be properly initialized|warning|medium|
41-
|[Missing error handling](./cpp/src/docs/crypto/MissingErrorHandling.md)|Checks if returned error codes are properly checked|warning|high|
42-
|[Missing zeroization of potentially sensitive random BIGNUM](./cpp/src/docs/crypto/MissingZeroization.md)|Determines if random bignums are properly zeroized|warning|medium|
43-
|[Random buffer too small](./cpp/src/docs/crypto/RandomBufferTooSmall.md)|Finds buffer overflows in calls to CSPRNGs|warning|high|
44-
|[Use of legacy cryptographic algorithm](./cpp/src/docs/crypto/UseOfLegacyAlgorithm.md)|Detects potential instantiations of legacy cryptographic algorithms|warning|medium|
45-
46-
#### Security
47-
48-
| Name | Description | Severity | Precision |
49-
| --- | ----------- | :----: | :--------: |
50-
|[Async unsafe signal handler](./cpp/src/docs/security/AsyncUnsafeSignalHandler/AsyncUnsafeSignalHandler.md)|Async unsafe signal handler (like the one used in CVE-2024-6387)|warning|high|
51-
|[Decrementation overflow when comparing](./cpp/src/docs/security/DecOverflowWhenComparing/DecOverflowWhenComparing.md)|This query finds unsigned integer overflows resulting from unchecked decrementation during comparison.|error|high|
52-
|[Find all problematic implicit casts](./cpp/src/docs/security/UnsafeImplicitConversions/UnsafeImplicitConversions.md)|Find all implicit casts that may be problematic. That is, casts that may result in unexpected truncation, reinterpretation or widening of values.|error|high|
53-
|[Inconsistent handling of return values from a specific function](./cpp/src/docs/security/InconsistentReturnValueHandling/InconsistentReturnValueHandling.md)|Detects functions whose return values are compared inconsistently across call sites, which may indicate bugs|warning|medium|
54-
|[Invalid string size passed to string manipulation function](./cpp/src/docs/security/CStrnFinder/CStrnFinder.md)|Finds calls to functions that take as input a string and its size as separate arguments (e.g., `strncmp`, `strncat`, ...) and the size argument is wrong|error|low|
55-
|[Iterator invalidation](./cpp/src/docs/security/IteratorInvalidation/IteratorInvalidation.md)|Modifying a container while iterating over it can invalidate iterators, leading to undefined behavior.|warning|medium|
56-
|[Missing null terminator](./cpp/src/docs/security/NoNullTerminator/NoNullTerminator.md)|This query finds incorrectly initialized strings that are passed to functions expecting null-byte-terminated strings|error|high|
57-
58-
### Go
59-
60-
#### Cryptography
61-
62-
| Name | Description | Severity | Precision |
63-
| --- | ----------- | :----: | :--------: |
64-
|[Message not hashed before signature verification](./go/src/docs/crypto/MsgNotHashedBeforeSigVerfication/MsgNotHashedBeforeSigVerfication.md)|Detects calls to (EC)DSA APIs with a message that was not hashed. If the message is longer than the expected hash digest size, it is silently truncated|error|medium|
65-
66-
#### Security
67-
68-
| Name | Description | Severity | Precision |
69-
| --- | ----------- | :----: | :--------: |
70-
|[Invalid file permission parameter](./go/src/docs/security/FilePermsFlaws/FilePermsFlaws.md)|Finds non-octal (e.g., `755` vs `0o755`) and unsupported (e.g., `04666`) literals used as a filesystem permission parameter (`FileMode`)|error|medium|
71-
|[Missing MinVersion in tls.Config](./go/src/docs/security/MissingMinVersionTLS/MissingMinVersionTLS.md)|Finds uses of tls.Config where MinVersion is not set and the project's minimum Go version (from go.mod) indicates insecure defaults: Go < 1.18 for clients or Go < 1.22 for servers. Does not mark explicitly set versions (including explicitly insecure ones).|error|medium|
72-
|[Trim functions misuse](./go/src/docs/security/TrimMisuse/TrimMisuse.md)|Finds calls to `string.{Trim,TrimLeft,TrimRight}` with the 2nd argument not being a cutset but a continuous substring to be trimmed|error|low|
73-
74-
### Java-kotlin
75-
76-
#### Security
77-
78-
| Name | Description | Severity | Precision |
79-
| --- | ----------- | :----: | :--------: |
80-
|[Recursive functions](./java-kotlin/src/docs/security/Recursion/Recursion.md)|Detects possibly unbounded recursive calls|warning|low|
81-
8222
## Query suites
8323

84-
CodeQL queries are grouped into "suites". To execute queries from a specific suit add its name after a colon: `trailofbits/cpp-queries:codeql-suites/tob-cpp-full.qls`.
24+
CodeQL queries are grouped into suites. To execute queries from a specific suite add its name after a colon: `trailofbits/cpp-queries:codeql-suites/tob-cpp-full.qls`.
8525

86-
The recommended suit - `tob-cpp-code-scanning.qls` - is chosen and executed when you do not explicitly specify any suit. Other suits in this repository are:
26+
The recommended suite - `tob-cpp-code-scanning.qls` - is chosen and executed when you do not explicitly specify any suite. Other suites in this repository are:
8727

8828
* `tob-<lang>-crypto.qls` - queries targeting cryptographic vulnerabilities
8929
* `tob-<lang>-security.qls` - queries targeting standard security issues
9030
* `tob-<lang>-full.qls` - all queries, including experimental ones
9131

9232
## Development
9333

94-
#### Prepare environment
34+
### Prepare environment
35+
36+
Configure global CodeQL's search path:
9537

96-
Clone this repository and configure global CodeQL's search path:
97-
```sh
98-
git clone git@github.com:trailofbits/codeql-queries.git
38+
```bash
39+
git clone https://github.com/trailofbits/codeql-queries
9940
mkdir -p "${HOME}/.config/codeql/"
10041
echo "--search-path '$PWD/codeql-queries'" > "${HOME}/.config/codeql/config"
101-
```
102-
103-
Check that CodeQL CLI detects the new qlpacks:
104-
```sh
105-
codeql resolve packs | grep trailofbits
106-
```
10742

108-
#### Before committing
43+
cd codeql-queries/
44+
make pack-install
10945

110-
Run tests:
111-
112-
```sh
113-
make test
114-
```
115-
116-
Format queries:
117-
118-
```sh
119-
make format
120-
```
121-
122-
Install dependencies:
123-
124-
```sh
125-
make install
46+
codeql resolve packs | grep trailofbits
12647
```
12748

128-
Generate query tables and copy-paste it to README.md file
129-
```sh
130-
python ./scripts/queries_table_generator.py 2>/dev/null
131-
```
49+
### Before committing
13250

133-
Generate markdown query help files
134-
```sh
135-
codeql generate query-help ./cpp/src/ --format=markdown --output ./cpp/src/docs
136-
codeql generate query-help ./go/src/ --format=markdown --output ./go/src/docs
137-
codeql generate query-help ./java/src/ --format=markdown --output ./java/src/docs
51+
```bash
52+
make pack-upgrade
53+
make test format
54+
make generate-table generate-help
13855
```

cpp/lib/codeql-pack.lock.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@
22
lockVersion: 1.0.0
33
dependencies:
44
codeql/controlflow:
5-
version: 2.0.22
5+
version: 2.0.31
66
codeql/cpp-all:
7-
version: 6.1.3
7+
version: 9.0.0
88
codeql/dataflow:
9-
version: 2.0.22
9+
version: 2.1.3
1010
codeql/mad:
11-
version: 1.0.38
11+
version: 1.0.47
1212
codeql/quantum:
13-
version: 0.0.16
13+
version: 0.0.25
1414
codeql/rangeanalysis:
15-
version: 1.0.38
15+
version: 1.0.47
1616
codeql/ssa:
17-
version: 2.0.14
17+
version: 2.0.23
1818
codeql/tutorial:
19-
version: 1.0.38
19+
version: 1.0.47
2020
codeql/typeflow:
21-
version: 1.0.38
21+
version: 1.0.47
2222
codeql/typetracking:
23-
version: 2.0.22
23+
version: 2.0.31
2424
codeql/util:
25-
version: 2.0.25
25+
version: 2.0.34
2626
codeql/xml:
27-
version: 1.0.38
27+
version: 1.0.47
2828
compiled: false

0 commit comments

Comments
 (0)