ci: pin semgrep registry rules as snapshots with scheduled update PRs - #66
Open
feliperalmeida wants to merge 6 commits into
Open
ci: pin semgrep registry rules as snapshots with scheduled update PRs#66feliperalmeida wants to merge 6 commits into
feliperalmeida wants to merge 6 commits into
Conversation
PR overviewAll previously flagged issues have been addressed. No open security concerns remain on this pull request. Security reviewNo open security issues remain on this pull request. Fixed/addressed: 2 · PR risk: 0/10 |
Piccirello
reviewed
Aug 6, 2026
Piccirello
reviewed
Aug 6, 2026
| # `p/...` registry configs, so a registry-side rule change can never break CI | ||
| # on unrelated PRs. This workflow re-fetches the packs on a schedule; when the | ||
| # registry has added/removed/changed rules it: | ||
| # 1. dry-runs the added/changed rules against PostHog/posthog to measure the |
Member
There was a problem hiding this comment.
This currently only checks against PostHog/posthog. In the past when we've had failures from new rules they often effected multiple repos. Maybe PostHog/posthog is a good sentinel for all of those? (meaning it's unlikely another repo will fail if PostHog/posthog isn't also failing) Otherwise we may want a list of "critical" repos to include in this scan, which would probably include a bunch of SDK repos.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Our semgrep workflows pass live registry configs (
--config p/owasp-top-ten, etc.), which resolve at scan time. When the registry adds or modifies a rule, CI starts failing org-wide on unrelated PRs with no code change on our side — worst inPostHog/posthog, where engineers get blocked. The--exclude-rulelists in our workflows are the accumulated manual responses to this. Registry changes also break CI a second way: rules that fail to parse/analyze under--strict(see the comment insemgrep.yml), which no finding-level mitigation can catch.Approach: pin the rules, update deliberately
.semgrep/registry/now vendors the resolved YAML of every registry pack used org-wide (~1,270 rules, 3 MB), fetched anonymously fromsemgrep.dev/c/<id>— exactly what CI fetched before, but frozen.sources.jsonmaps snapshot files to registry ids.semgrep.yml,semgrep-package-managers.yml,ci-security.yml) point at the snapshots instead ofp/.... Likeflags-boards.json, snapshots load frommainat runtime, so callers never re-pin.semgrep-registry-update.yml(weekday cron) re-fetches the packs, diffs per rule id, dry-runs only the added/changed rules againstPostHog/posthogto measure blast radius (finding counts + analysis errors, never failing), opens/updates a single rolling snapshot-bump PR with the full report, and notifies Slack. Merging that PR is the moment new rules start being enforced — occurrences can be fixed (or exclusions added) first..github/scripts/semgrep_registry.pyimplements sync/diff/report; unit-tested via the existingsemgrep-tests.ymldiscover step.A registry-side change can no longer break CI on unrelated PRs — including the parse-error failure mode, since a rule that errors under
--strictfails the snapshot PR's own CI before it can reachmain.Verification
p/packs vs. snapshots on this repo produce identical findings (the snapshot fetch is anonymous, same as CI's).syncis idempotent (re-run produces zero diffs); all snapshots passsemgrep --validate.semgrep --test .semgrep/rules/4/4.persist-credentials: falseon read-only checkouts).Setup required before the updater is useful
SEMGREP_REGISTRY_BOT_APP_ID/SEMGREP_REGISTRY_BOT_PRIVATE_KEYsecrets — GitHub App with Contents + Pull requests write on this repo (App token so the bot's PRs trigger CI).SEMGREP_REGISTRY_SLACK_BOT_TOKENsecret +SEMGREP_REGISTRY_SLACK_CHANNEL_IDrepo variable (the Slack step skips itself until set).Follow-up
PostHog/posthogPR switching the eight semgrep jobs inci-security.yamlto these snapshots (must land after this merges — snapshots are fetched frommainat runtime). All packs posthog needs are already vendored here..semgrep/registry/README.md.