Skip to content

fix(scanner): Honor SAST rule allowlists and preserve fingerprints - #141

Open
lelia wants to merge 7 commits into
mainfrom
lelia/language-_enabled_rules-has-no-effect-bare-ids-p
Open

lelia wants to merge 7 commits into
mainfrom
lelia/language-_enabled_rules-has-no-effect-bare-ids-p

Conversation

@lelia

@lelia lelia commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

<language>_enabled_rules now limits which rules OpenGrep runs. OpenGrep namespaces local rule IDs by their configuration path, so the previous bare-ID exclusions did not match. Empty defaults in the Action and CLI keep the full ruleset available for every enabled language. Existing explicit lists take effect on upgrade.

  • Filtered scans stage rules in a writable temporary directory and preserve the original IDs for bundled rules, including when the installed rules directory is read-only.
  • C and C++ apply independent allowlists. C# and .NET share an analyzer and combine their explicit lists. String flags such as "false" are interpreted as booleans.
  • Unknown rule IDs generate a warning. A list containing only unknown IDs runs the full ruleset for that language.
  • All-languages scans skip unsupported Erlang and Objective-C rule files. The scanner removes temporary rule configs after each run.

Verification

  • Full Python suite with OpenGrep v1.33.1 required. 539 passed and 1 was skipped.
  • OpenGrep v1.33.1 end-to-end tests cover allowlist selection, stable fingerprints across repeated scans with read-only rules, and independent C/C++ selection.
  • Configuration tests cover empty defaults, unknown IDs, aliases, and temporary-file cleanup.
  • The locked dependency and release documentation checks passed.

Fixes #135
Fixes CE-496

OpenGrep prefixes the ID of every rule it loads from a --config path
with the path's directories, so the --exclude-rule flags built from bare
rule IDs never matched and every bundled rule ran regardless of
<language>_enabled_rules. The scanner now passes OpenGrep a temporary
copy of the rules file holding only the enabled rules. Enabled IDs that
match no rule are logged as a warning, and an allowlist that matches
nothing runs every rule for the language.

The <language>_enabled_rules defaults are now empty in action.yml and
connectors.yaml, so every bundled rule runs by default, as scans already
did. The Action defaults had drifted from the CLI defaults and named
seven rule IDs that no longer exist. A test now rejects default lists
that name unknown rule IDs.

Also:
- Skip erlang.yml and objective-c.yml in every all-languages expansion;
  OpenGrep supports neither language.
- Remove the temporary custom-rule and filtered-rule directories when
  the scan ends.
- Add an end-to-end test that runs the real OpenGrep binary.

Fixes #135
@lelia
lelia marked this pull request as ready for review November 14, 2026 03:32
@lelia
lelia requested a review from a team as a code owner November 14, 2026 03:32
@lelia

lelia commented Nov 14, 2026

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor

cursor Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
SAST scan breadth and allowlist behavior change on upgrade—empty defaults now run the full bundled ruleset, and any explicit allowlist finally limits findings, which can shift CI gates and baselines.

Overview
<language>_enabled_rules is enforced end-to-end. OpenGrep namespaces rule IDs by config path, so the old --exclude-rule approach could not narrow scans reliably. Filtered runs now build reduced rule YAML, stage it in a writable temp directory, prefix IDs to match the bundled path namespace, and pass --no-rewrite-rule-ids so fingerprints stay stable—even when the installed rules directory is read-only.

Defaults and config semantics change on upgrade. GitHub Action inputs and CLI defaults for <language>_enabled_rules go from long “high-confidence” lists to empty, which means every bundled rule for an enabled language. Non-empty lists are true allowlists (custom IDs included); unknown IDs log a warning, and a list of only unknown IDs falls back to the full language ruleset. all_rules_enabled still disables allowlist filtering. C and C++ allowlists apply independently; C# and .NET share dotnet.yml and merge their lists.

Related SAST fixes: all-languages scans skip erlang.yml and objective-c.yml; boolean SAST flags use coerce_bool; temporary custom/filtered rule dirs are always cleaned up after a scan. Docs and changelog describe the upgrade impact.

Reviewed by Cursor Bugbot for commit 6b804c0. Configure here.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

OpenGrep computes a finding's fingerprint from its rule ID, and by
default it prefixes that ID with the directories of the rule file's
--config path. Filtered and custom rule files live in a new temporary
directory on every run, so unchanged findings got a new fingerprint
each scan, which breaks deduplication in the JSON and Microsoft
Sentinel outputs. Pass --no-rewrite-rule-ids so the fingerprint depends
only on the rule and the code.

Also test that temporary rule directories are removed when OpenGrep is
missing, when the scan raises, and when building custom rules fails.
@lelia lelia changed the title fix(scanner): Make per-language enabled-rule allowlists take effect fix(scanner): Make per-language enabled_rules allowlists take effect Nov 14, 2026
Socket keys an injected SAST alert on its full props, including the
OpenGrep fingerprint, and stores triage against that key. The fingerprint
comes from a rule ID that OpenGrep prefixes with the rules file's
directories, not its file name. Passing --no-rewrite-rule-ids would have
given every SAST alert a new key once, dropping its triage.

Drop that flag and write each filtered copy next to the file it was made
from, under a hidden .yaml name that the *.yml rule globs skip. Kept
findings report the same fingerprint as an unfiltered scan. When the
rules directory is not writable, the copy falls back to a temporary
directory and the log warns that fingerprints will differ.

C and C++ share c_cpp.yml, and C# and .NET share dotnet.yml. When both
languages in a pair are enabled and either has an empty list, the shared
file now runs every rule instead of applying the other language's list.
Resolve docs/github-action.md against the 3.5.0 version bump, and move this branch's changelog entries from the released 3.5.0 section to Unreleased.
@lelia

lelia commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread socket_basics/core/config.py Resolved
lelia added 2 commits December 5, 2026 02:08
Stage rule configs with their original OpenGrep IDs so filtering also works with read-only rules directories. Scope C and C++ allowlists by analyzer and combine explicit lists for the C# and .NET aliases.

Coerce string flags, test empty defaults, and document the fallback for lists with only unknown rule IDs.
@lelia lelia changed the title fix(scanner): Make per-language enabled_rules allowlists take effect fix(scanner): Honor SAST rule allowlists and preserve fingerprints Dec 5, 2026
@lelia

lelia commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 6b804c0. Configure here.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

<language>_enabled_rules has no effect (bare IDs passed to --exclude-rule), and 7 Action default rule IDs no longer exist

1 participant