Static analysis rules for opengrep, maintained by OpenCTEM. They are:
- permissively licensed: our own rules are MIT. Rules imported from other projects keep their MIT or Apache-2.0 licence, named in each file. Nothing here carries a non-commercial, Commons Clause or copyleft condition.
- tested: every rule has a fixture with cases that must match (
ruleid:) and cases that must not (ok:). - measured: CI reports coverage per language on pinned public benchmark repositories.
- signed: releases are reproducible bundles signed with cosign keyless, by this repository's release workflow.
The OpenCTEM sensor installs the latest release as its managed semgrep-rules content. The ci-opengrep image carries one release. Both verify the signature first.
opengrep scan --config rules/ --no-rewrite-rule-ids <path>
--no-rewrite-rule-ids keeps the rule ids as written here. OpenCTEM uses the rule id in a finding's identity.
Add --dataflow-traces to get the path from source to sink of taint rules (mode: taint). OpenCTEM shows it on the finding.
- The pack is the default SAST content. Scans on platform-operated sensors run opengrep with this pack and never fetch registry rules. Your own sensors use it unless you set a local rules path or choose registry rule sets.
- The sensor and the
ci-opengrepimage run it with--no-rewrite-rule-ids,--dataflow-tracesand--disable-nosem: an inline ignore comment does not hide a result; OpenCTEM turns it into a pending exception for a person to approve. - A finding is keyed on the rule id, the file and the flagged code. Renaming a rule id makes new findings and leaves the triage on the old ones: do not rename a released rule id.
See Known false positives and Data-flow traces.
Each tag v<major>.<minor>.<patch> publishes:
| asset | content |
|---|---|
sast-rules-<v>.tar.gz |
rules/ (rule files only, no fixtures), LICENSE, NOTICE, LICENSES/, VERSION. Reproducible: sorted, mtime 0, uid/gid 0 |
.sha256 |
its SHA-256 |
.sigstore.json |
cosign bundle: certificate, signature and transparency-log proof |
Verify:
cosign verify-blob --bundle sast-rules-<v>.tar.gz.sigstore.json \ --certificate-identity https://github.com/openctemio/sast-rules/.github/workflows/release.yml@refs/tags/v<v> \ --certificate-oidc-issuer https://token.actions.githubusercontent.com \ sast-rules-<v>.tar.gz
rules/openctem/<language>/ our rules (MIT)
rules/gitlab/ imported from GitLab sast-rules (MIT, Apache-2.0)
rules/0xdea/ imported from 0xdea/semgrep-rules (MIT)
rules/elttam/ imported from elttam/semgrep-rules (MIT)
bench/ benchmark repositories, reference locations, exclusions
scripts/ checks, coverage, bundle build, opengrep install
bench/repos.txt pins six public repositories: DVWA, pygoat, go-test-bench, gin, WebGoat and juice-shop.
- Reference locations:
bench/baseline/lists where a broad reference rule set reported results on those commits. It holds paths and lines only, no rule text. - Covered: a location counts as covered when a pack result overlaps it.
- Exclusions: locations that are not vulnerabilities are listed with a reason in
bench/baseline-excluded.txt. - CI gate: CI fails if a SAST language (php, python, javascript/typescript, java, go) drops below 80%.
| language | covered | reference | coverage |
|---|---|---|---|
| html | 159 | 163 | 97.5% |
| python | 70 | 72 | 97.2% |
| go | 37 | 39 | 94.9% |
| javascript / typescript | 52 | 55 | 94.5% |
| java | 41 | 49 | 83.7% |
| php | 36 | 43 | 83.7% |
| yaml (GitHub Actions) | 59 | 73 | 80.8% |
| dockerfile | 6 | 6 | 100% |
Terraform (17 reference locations) is not covered. Infrastructure as code is the iac capability, which runs trivy.
Run it locally: bench/run.sh /tmp/bench --min 80 --languages php,python,javascript,java,go.
-
Write
rules/openctem/<language>/<name>.yaml. It starts with# SPDX-License-Identifier: MITand# Source: https://github.com/openctemio/sast-rules, and the rule id isopenctem.<language>.<class>.<name>. -
Write a fixture next to it with the same name (
<name>.test.yamlfor YAML targets). It needs at least oneruleid: <id>case and oneok: <id>case. -
Run the checks:
python3 scripts/check_rules.py rules opengrep scan --test rules/ bench/run.sh /tmp/bench
-
Importing from another project:
- only MIT or Apache-2.0 files;
- keep the upstream header and add the SPDX and Source lines;
- run
scripts/gen_notice.py.
Imported rules whose upstream fixture has no
ok:case yet are listed intests/negative-pending.txt. That list may only shrink.
Never copy rules, messages or fixtures from sources under other licences (see NOTICE for what is allowed).