Skip to main content

Adding a rule

Teach cryptarium about a crypto API by editing YAML. You usually do not need to change Go. What you will do: add a rule, add a positive and negative fixture, run make lint-rules.

Checklist

  • Stable id (do not rename later; SARIF baselines break)
  • Canonical primitive (or honest UNKNOWN)
  • Honest confidence (high only when the match proves the algorithm and key details)
  • Positive fixture that must match
  • Negative fixture that must not (especially comments)
  • references link to the API docs
  • make lint-rules passes
Full field list: Rule packs. Fixture layout: Fixtures. Shipped C packs (append new symbols there): rules/c/openssl.yaml, rules/c/libsodium.yaml, rules/c/mbedtls.yaml. C++-only packs: rules/cpp/cryptopp.yaml, rules/cpp/botan.yaml. Do not re-add OpenSSL under rules/cpp/; C++ files already load C packs.

Example 1: JavaScript

Append to rules/javascript/webcrypto.yaml (also covers TypeScript files):
Shipped rules in that pack already look like this:
Use medium or low when the API can pick the algorithm at runtime (for example generateKey or generateKeyPairSync). Do not guess RSA from the function name alone.
Positive fixture (testdata/rules/js.crypto.createcipheriv.aes/positive.js):
Negative fixture (must not match):

Example 2: C / OpenSSL

Append to rules/c/openssl.yaml:
C++ files also load c packs. Put a rule in rules/cpp/ only when it should not apply to plain C. Compare with a vague API in the same pack:
EVP_PKEY_keygen can create many key types. UNKNOWN is the right call. Positive fixture:
Negative fixture:

Enhance a rule

Common upgrades:
  1. Lower false positives by tightening package / symbol.
  2. Raise confidence only after you extract real parameters (or the symbol alone is unambiguous).
  3. Add static parameters only when every hit shares them (example: known AES-128 constant).

Extend the library catalog

To flag a Go module in go.mod, edit rules/libraries/catalog.yaml:
A library in the lockfile is medium confidence at most. It is not proof the code uses that crypto. See Correlation.

When not to write a rule

What happens after the match?

  1. The source detector emits a finding (where + what API).
  2. Classification assigns Broken / Weakened / Safe / Unknown.
  3. Scoring sets priority for the report.
Your YAML should describe the call site. It should not invent a migration target.

Validate