:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Devex semgrep rules
Devex / hygiene rules for the PostHog codebase. Run by the semgrep-devex job in ci-security.yaml in three passes:
- Warnings (informational) —
semgrep --severity=WARNINGruns allseverity: WARNINGrules. Findings appear in the CI run output but the step does not fail. Use this mode when a rule has a non-zero backlog of existing violations — the list shows up in CI without blocking master while the codebase is cleaned up. - Errors (blocking) —
semgrep --severity=ERROR --errorruns allseverity: ERRORrules and fails CI on any finding. Use this mode for hard regression guards: patterns that should never appear, or migration-style rules whose backlog has been cleaned up. - New warnings (blocking, PRs only) — the WARNING rules run again with
--baseline-commitset to the PR base, plus--error. Findings that already exist on the base are grandfathered; findings the PR introduces fail the job. This stops the bleeding on backlogged rules while the backlog is worked down. Caveat: moving or renaming a file makes its grandfathered findings look new to the baseline diff — either fix them as part of the move or exempt them with# nosemgrep: <rule-id>.
Picking a severity
Pick the severity that matches the rule's intent:
- ERROR when zero violations are expected — either because the pattern is genuinely new (regression guard) or because a previously-WARNING rule has been cleaned up.
- WARNING when there's a known non-zero backlog that will be migrated over time.
A WARNING rule typically gets flipped to ERROR once its backlog hits zero. The rule stays in .semgrep/rules/devex/; only the severity changes. To flip a rule:
- Verify locally that
semgrep --config .semgrep/rules/devex/<rule>.yaml bin/ common/ docs/onboarding/ ee/ frontend/ hog/ packages/ posthog/ products/ services/ tools/returns zero findings. - Edit the rule file: change
severity: WARNINGtoseverity: ERROR. - Update the rule's
message:to drop any "informational, not blocking" phrasing — it's now blocking.
Conventions for new rules
- Decide severity by expected finding count: zero → ERROR; non-zero → WARNING.
- Include the migration playbook (or a pointer to a skill) in the rule's
message:field — that's what reviewers and authors see when the rule fires. - Scope with
paths.include:rather than relying only onpaths.exclude:— narrower scope means faster scans and clearer intent. - For legitimate exceptions, prefer
paths.exclude:for categorical cases (whole dirs/files) and# nosemgrep: <rule-id>for case-by-case exemptions at the call site.
Per-file baseline ratchets
A WARNING rule grandfathers its backlog through --baseline-commit, so the backlog has no count that a migration can lower, and a moved file looks new.
For a migration that runs over many PRs, use a per-file baseline instead:
- Give the rule
severity: INFO. The three passes above select WARNING and ERROR only, so they do not run it. - Check in a baseline file that lists
<path> <count>for each file with findings.bin/semgrep_ratchet.py --updatewrites it fromsemgrep --jsonoutput. - Add a step to the
semgrep-devexjob that runs the rule with--jsonand thenbin/semgrep_ratchet.py --findings <json> --baseline <file>.
The ratchet fails when a file has more findings than its baseline count, and also when it has fewer. So each migration PR lowers the count or removes the line.
| Rule | Baseline |
|---|---|
integration-model-through-sdk |
posthog/integrations/model_access_baseline.txt |