Fix Opengrep differential scan re-reporting pre-existing findings as new (SEC-1975) - #26
Merged
Conversation
Opengrep's --baseline-commit classifies a finding as new/old via a location- and content-sensitive fingerprint of the matched range. Whole-file "absence" rules (e.g. missing-permissions, which matches a whole job) span a large range, so editing any line inside it (such as pinning an action SHA) changes the fingerprint and the pre-existing finding is mis-reported as new. This blocked the SHA-pinning campaign and any workflow edit on repos lacking an explicit permissions: block (SEC-1975). Replace --baseline-commit with a stable-identity diff: full-scan both the head tree and the base tree (checked out in a git worktree) with the same ruleset, then in opengrep-report.sh treat a finding as new only when its (rule, file) key gained findings — new count = max(0, head_count - baseline_count), never keyed on line number or matched text. Edits inside a pre-existing match no longer re-report it; a genuinely new gap (added job/file/line) still is, and still blocks. A missing/failed baseline scan conservatively treats every head finding as new so a baseline problem never hides a finding. Add report-diff-test.sh (hermetic bash+jq unit tests for the diff) and a CI workflow to run it.
There was a problem hiding this comment.
Pull request overview
This PR fixes false “new finding” reports from the sast/opengrep differential scan by replacing --baseline-commit with a stable-identity diff: full-scan both base and head, then compute “new” based on per (rule, file) finding-count deltas, avoiding fingerprint instability for whole-block absence rules.
Changes:
- Update the composite action to run full scans for both PR head and baseline (via
git worktree) and pass both JSONs to the report script. - Add stable-identity diff logic to
opengrep-report.shto compute new findings from baseline/head scans. - Add hermetic bash+jq unit tests plus a dedicated workflow to run them on PRs.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
sast/opengrep/tests/report-diff-test.sh |
Adds unit tests for the new baseline/head diff logic. |
sast/opengrep/scripts/opengrep-report.sh |
Implements stable-identity diffing and updates reporting inputs accordingly. |
sast/opengrep/README.md |
Updates documentation to reflect the new baseline/head full-scan diff approach. |
sast/opengrep/action.yml |
Switches from --baseline-commit to dual full-scan + report-time diff, adding baseline worktree scanning. |
.github/workflows/test-opengrep-action.yml |
Adds CI workflow to run the new diff unit tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Remove the new-findings temp file via an EXIT trap (path baked into the trap so it survives the local going out of scope under set -u). - Add a regression test asserting same-(rule,file) findings interleaved with another key still group correctly (jq group_by sorts internally, so it is order-independent; this guards that guarantee).
keeravani
reviewed
Jun 25, 2026
keeravani
previously approved these changes
Jun 25, 2026
A failed/errored baseline scan left baseline-findings.json.tmp behind. It's under RUNNER_TEMP (cleaned at job end) and unused by the report step, so it's harmless, but remove it for tidiness.
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
The
sast/opengrepaction is meant to be differential — report only findings a PR newly introduces. But PRs that merely edit a workflow (e.g. pinning auses:ref to a SHA) were failingopengrep/scanwithmissing-explicit-permissionsfindings on workflows whose missing-permissions:gap is pre-existing on the base branch.Root cause: opengrep's
--baseline-commitclassifies findings new/old by a location- and content-sensitive fingerprint of the matched range. Whole-file "absence" rules (missing-permissions matches a whole job) span a large range, so editing any line inside it changes the fingerprint and the pre-existing finding is mis-classified as new. Confirmed empirically: editing auses:line inside the job block leaves the finding's start/end lines unchanged but changes its fingerprint.This blocked the SHA-pinning campaign and any unrelated workflow edit, and a high false-positive rate erodes trust in the required gate.
Fix
Replace
--baseline-commitwith a stable-identity diff:git worktreeatbase.sha, scanned from its own root so paths are repo-relative and comparable) with the same ruleset.opengrep-report.sh, a finding is new only if its(rule, file)key gained findings:new = max(0, head_count − baseline_count). Never keyed on line number or matched text — both shift when a line inside a whole-block match is edited.Behavior
uses:SHAs in a workflow with a pre-existing missing-permissions:gap → no new finding for that pre-existing issue.permissions:) → still reported and still blocks.Tests
sast/opengrep/tests/report-diff-test.sh— hermetic bash+jq unit tests for the diff (edit-in-block, line shift, added gap, second same-rule finding, empty baseline, no change, removed finding), run by the newOpengrep action testsworkflow. Also validated end-to-end against realopengrep/semgrepoutput for the actual permissions rule.