Contributing
How to contribute to shellfirm — add a new check to the built-in catalogue, fix a bug, improve the docs — and send your first pull request.
shellfirm is open source (Apache-2.0) and its main asset is the catalogue of checks. You can contribute new checks, fixes, documentation, bug reports and feature requests. A missing check is the most useful contribution of all: the Known limitations page lists real gaps, and each one is a good first issue.
This page summarises the repository's CONTRIBUTING.md and guide to adding checks, so you can plan your change here before you open the repository.
Found a bypass?
A way to run a risky command without the challenge, deny list or policy stopping it is a security bug. Do not open a public issue or pull request for it. Report it privately: see Security & trust.
Ways to contribute
| You want to… | Do this |
|---|---|
| Report a bug or a missing check | Open an issue with the exact command, your shell and OS, and shellfirm --version |
| Add a check for everyone | Send a pull request: Add a built-in check |
| Add a check only for you or your team | No code change: a custom check or a project check |
| Fix a bug or add a feature | Send a pull request: Workflow |
| Improve these docs | Open an issue or a pull request on the website repository |
Workflow
Fork and branch
Fork kaplanelad/shellfirm and create
a branch from main.
Make the change, with tests
Every new check needs test cases; every bug fix should come with a test that fails without it.
Run the checks
Run make ci from the repository root (see Checks to run).
Add a CHANGELOG line
Add a line under ## Unreleased in
CHANGELOG.md
for any user-visible change: a new check, a new flag, changed behaviour or a
bug fix.
Open the pull request
Open a pull request against main. The pull request template has a short
checklist.
Requirements
- Rust stable. The minimum supported Rust version (MSRV) is the
rust-versioninshellfirm/Cargo.toml: 1.88. - Optional: cargo-insta to review snapshot
changes (
cargo install cargo-insta).
Checks to run before a pull request
All commands run from the repository root. make help lists every target.
| Command | What it runs |
|---|---|
make test | cargo test --locked --all-features |
make clippy | clippy with the exact CI flags |
make validate-doc | cargo doc with RUSTDOCFLAGS="-D warnings" |
make fmt | cargo fmt --all -- --check |
make ci | All four: the Linux part of CI |
CI also runs a macOS and Windows matrix, the MSRV build and feature checks. The clippy line CI uses:
cargo clippy --locked --all-features -- -D warnings -W clippy::pedantic -W clippy::nursery -W rust-2018-idiomsOnly the check tests, which take a few seconds while you work on checks:
cargo test -p shellfirm --test checksSome tests use insta snapshots. When a snapshot changes on
purpose, review it with cargo insta test --review, or run
INSTA_UPDATE=always cargo test and review the .snap diff with git diff.
Use standard rustfmt settings (cargo fmt --all before you commit).
Add a new built-in check
Adding checks takes five steps.
Built-in checks live in
shellfirm/checks/,
one YAML file per group. The file name is the group name
(checks/terraform.yaml is the terraform group). The build validates every
file and embeds them in the binary.
1. Pick the group
| The command is run by… | Group (file) |
|---|---|
rm, dd, mkfs, chmod, find -delete, rsync | fs |
git / gh | git / github |
kubectl, helm, velero, argocd, flux, istioctl, cilium, etcdctl, eksctl | kubernetes |
terraform, tofu, terragrunt, pulumi, vault, consul, nomad | terraform |
aws, gcloud / gsutil, az | aws, gcp, azure |
heroku, flyctl, vercel, netlify | heroku, flyio, vercel, netlify |
docker | docker |
SQL text (DROP TABLE, DELETE FROM without WHERE) | database |
psql, mysql, redis-cli, mongosh flags | psql, mysql, redis, mongodb |
npm, yarn, pnpm | npm |
Remote code execution (curl … | sh) | shell |
Firewalls, interfaces, iptables, reverse shells | network |
| Sending secrets or env files over the network | exfil |
| Reboot, cron, processes, services, SSH keys, fork bombs | base |
If none fits, a new group is possible, but it needs a few more steps (it must be enabled by default or listed as opt-in). The guide to adding checks walks through them.
2. Add the entry
This is the real terraform:destroy entry from shellfirm/checks/terraform.yaml:
- from: terraform
test: (?:^|\s)(?:terraform|tofu|terragrunt)\s+(?:run-all\s+)?(?:destroy\b|apply\b.*\s-destroy(?:\s|$))
description: "This destroys managed infrastructure."
id: terraform:destroy
severity: High
filters:
# With -auto-approve the Critical checks above apply instead.
- type: NotMatches
value: '\s-?-auto-approve(?:\s|$|=)'
# `terraform destroy -help` prints the usage.
- type: NotMatches
value: '\s-?-(?:help|h)(?:\s|$)'
alternative: "terraform plan -destroy"
alternative_info: "Preview what would be destroyed before running it."- Allowed keys:
id,from,test,description,severity,challenge(rarely needed),filters,alternative,alternative_info. Any other key, such as the typoseverty:, fails the build. idis usually<group>:<name>and unique across all files;fromequals the file name. Some files keep their own prefix for a family of checks (ssh:,process:,systemd:inbase.yaml,helm:inkubernetes.yaml, the*-strict:catch-alls); follow the prefix of the neighbouring checks. See Id prefixes inside a group.testruns on each normalised sub-command (a && b,a | b,$(…)andsudo/env/xargswrappers are split first, quotes removed). Anchor the tool name with(?:^|\s)tool\s+…; a test fails for a regex that starts with a bare command name. Matching is case-sensitive; use(?i)only for case-insensitive tools such as SQL.- Prefer
NotMatcheswith a whole-token regex ('\s--dry-run(?:\s|=|$)') for flag exemptions. The filter types are listed on Custom checks.
3. Add test cases
Add cases to shellfirm/tests/checks/<group>.yaml under a # -- <id> --
comment. expect_ids is the exact set of ids that must match; an empty list
means "must not match anything". Add at least one such negative case for the
near-misses of your regex. The example from the guide to adding checks (the
real file groups these cases differently):
# -- terraform:destroy --
- test: "terraform destroy"
description: "match command"
expect_ids: ["terraform:destroy"]
- test: "terraform destroy -auto-approve"
description: "the Critical check takes over"
expect_ids: ["terraform:destroy_auto_approve"]
- test: "terraform plan -destroy"
description: "a plan is safe"
expect_ids: []A coverage test fails if a check id never appears in any expect_ids list.
4. Run the tests and regenerate the catalogue
cargo test -p shellfirm --test checks # the check tests, a few seconds
make catalogue # regenerate docs/checks/README.mdThe check catalogue
is generated from the YAML files, and a test fails when it is out of date. Run
make catalogue once, after your last change to checks/*.yaml.
5. Try it, then open the pull request
cargo run -- check -c "terraform destroy" # dry run: prints the report, runs nothing
cargo run -- check --list -g terraform # the group's active checksAdd the CHANGELOG line and open the pull request.
Test safely
Never try risky commands on your own machine. To see how the shell hooks behave,
use a disposable container or virtual machine with the hook loaded
(eval "$(shellfirm init bash)") and nothing in it you would miss.
shellfirm check -c '…' never runs the command, so it is safe anywhere.
Code of conduct
The project follows the Contributor Covenant, version 2.1. In short: be respectful and constructive, assume good intent, and keep discussions about the work. Harassment, insults and personal attacks are not accepted in issues, pull requests or any other project space. Report unacceptable behaviour privately to the maintainer (see Security & trust); reports are handled confidentially. The full text is in CODE_OF_CONDUCT.md.