Skip to content
$ shellfirm

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 checkOpen an issue with the exact command, your shell and OS, and shellfirm --version
Add a check for everyoneSend a pull request: Add a built-in check
Add a check only for you or your teamNo code change: a custom check or a project check
Fix a bug or add a featureSend a pull request: Workflow
Improve these docsOpen 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-version in shellfirm/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.

CommandWhat it runs
make testcargo test --locked --all-features
make clippyclippy with the exact CI flags
make validate-doccargo doc with RUSTDOCFLAGS="-D warnings"
make fmtcargo fmt --all -- --check
make ciAll 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-idioms

Only the check tests, which take a few seconds while you work on checks:

cargo test -p shellfirm --test checks

Some 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, rsyncfs
git / ghgit / github
kubectl, helm, velero, argocd, flux, istioctl, cilium, etcdctl, eksctlkubernetes
terraform, tofu, terragrunt, pulumi, vault, consul, nomadterraform
aws, gcloud / gsutil, azaws, gcp, azure
heroku, flyctl, vercel, netlifyheroku, flyio, vercel, netlify
dockerdocker
SQL text (DROP TABLE, DELETE FROM without WHERE)database
psql, mysql, redis-cli, mongosh flagspsql, mysql, redis, mongodb
npm, yarn, pnpmnpm
Remote code execution (curl … | sh)shell
Firewalls, interfaces, iptables, reverse shellsnetwork
Sending secrets or env files over the networkexfil
Reboot, cron, processes, services, SSH keys, fork bombsbase

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:

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 typo severty:, fails the build.
  • id is usually <group>:<name> and unique across all files; from equals the file name. Some files keep their own prefix for a family of checks (ssh:, process:, systemd: in base.yaml, helm: in kubernetes.yaml, the *-strict: catch-alls); follow the prefix of the neighbouring checks. See Id prefixes inside a group.
  • test runs on each normalised sub-command (a && b, a | b, $(…) and sudo / env / xargs wrappers 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 NotMatches with 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):

example (docs/add-new-patterns.md)
# -- 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.md

The 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 checks

Add 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.