Repository navigation
Description
Summary
Two related defects in v3.4.1 (2ba1ad98). Both are still present on main: the three commits since the tag do not touch the OpenGrep connector or the *_enabled_rules defaults.
<language>_enabled_rulesdoes not narrow the scan. The OpenGrep connector turns the allowlist into--exclude-rule <id>flags using the rule IDs as written in the rules file. OpenGrep rewrites the ID of every rule it loads from a local config file to start with the file's directory path, and--exclude-ruleonly removes a rule whose rewritten ID is in the list. None of the flags ever matches, so every rule in the bundled file runs.- Seven rule IDs in the Action's default
*_enabled_ruleslists are not defined in any bundled rules file, and those defaults no longer match the CLI defaults inconnectors.yaml. Once (1) is fixed, Action users who never set the input would drop to a much smaller rule set than the CLI default. For JavaScript that is 6 rules, not 30.
What a run shows
GitHub Action v3.4.1 with javascript_sast_enabled: 'true' and no javascript_enabled_rules input, so the Action's 8-ID default applies. The step log:
Per-language enabled-rule filters detected: {'javascript_typescript.yml': 8}
Using bundled rules for javascript_typescript.yml from /socket-basics/socket_basics/rules/javascript_typescript.yml
Filtering rules for javascript_typescript.yml: 8 enabled IDs configured
Running OpenGrep: opengrep --json --dataflow-traces --output /tmp/... --quiet --config /socket-basics/socket_basics/rules/javascript_typescript.yml --exclude-rule js-missing-auth-check --exclude-rule ... /github/workspace
The command carries 53 --exclude-rule flags: the file's 59 rules minus the 6 default IDs that exist. The run still reported findings from rules on that list, for example js-react-dangerous-html and js-hardcoded-secret, and medium and low findings from rules outside the allowlist.
Why no exclusion matches
The image installs OpenGrep 1.26.0 (Dockerfile L11). In that version a local --config file is loaded like this:
- The file's path becomes its config ID:
config_resolver.pyL241 callsread_config_at_path, L404-L412, which setsconfig_id = str(loc). - Unless
--no-rewrite-rule-idsis passed, every rule ID is rewritten with that path:get_rules, L641-L651 and_rename_rule_ids, L671-L674 callprepend_rule_path, which callsconvert_config_id_to_prefix. convert_config_id_to_prefixrelativises the path against the working directory withsafe_relative_to, which returns the path unchanged when it is not under the working directory. The Action runs with the working directory/github/workspace, so/socket-basics/socket_basics/rules/javascript_typescript.ymlgives the prefixsocket-basics.socket_basics.rules., andjs-react-dangerous-htmlbecomessocket-basics.socket_basics.rules.js-react-dangerous-html.--exclude-rulekeeps every rule whose full ID is not in the list:exclude_rules.pyL10-L11, called fromrun_scan.pyL682.
The connector already expects prefixed IDs back. It strips everything before the last . from each result's check_id, and its comment lists socket-basics.socket_basics.rules.rule-name as one of the forms it sees (opengrep/__init__.py L395-L410). The exclusion list it builds uses the unprefixed IDs (L149-L176).
The same applies to custom rules, which are loaded from a temporary file outside the workspace, and to the CLI wherever the rules file is outside the working directory. Upgrading OpenGrep does not change it: the newer OCaml CLI keeps the same behaviour on purpose, "so an absolute config path outside the project still prefixes the rule ids with its directories" (Rule_fetching.ml L75-L86 on main).
The existing tests could not catch this because they assert the command line, not the result. tests/test_opengrep_custom_rules.py checks that --exclude-rule org.no-innerhtml appears in the arguments (L184-L185, L221-L222).
The Action defaults
The per-language *_enabled_rules defaults in action.yml are described as "high-confidence rules", but they differ from the CLI defaults in connectors.yaml, and seven of their IDs are not defined anywhere under socket_basics/rules/:
| Input | IDs in the default | IDs that exist | IDs that do not exist |
|---|---|---|---|
javascript_enabled_rules (L287-L290) |
8 | 6 | js-eval-usage, js-weak-crypto-md5 |
python_enabled_rules (L375-L378) |
11 | 8 | python-exec-used, python-bad-file-permissions, python-hardcoded-password-string |
ruby_enabled_rules (L387-L390) |
9 | 7 | ruby-rails-unsafe-constantize, ruby-xxe-vulnerability |
Every ID in the connectors.yaml defaults exists; the JavaScript list there has 30 (L182-L187). The missing IDs look like names from before the ruleset rewrite in #13, for example js-eval-usage where the file now has js-code-injection-eval, and js-weak-crypto-md5 where it has js-weak-hash-md5.
Impact
<language>_enabled_rulescannot narrow a scan, so every bundled rule for the enabled languages runs. Scans are noisier and slower than configured, and theFiltering rules ... N enabled IDs configuredlog line reports a filter that is not applied.- Fixing the filter alone would change the result for every Action user who relies on the defaults. A JavaScript scan would go from all 59 rules to 6, and the eval and MD5 checks the default names were meant to include would be gone. Users who set
all_rules_enabled: 'true'are not affected, because the connector clears the filter in that case.
Suggested fixes
- Make the filter independent of OpenGrep's ID rewriting. Either write a temporary copy of the rules file that contains only the enabled rules and pass that with
--config, or pass--no-rewrite-rule-ids(commands/scan.pyL252) so the plain IDs match. - Add an end-to-end test that runs the bundled OpenGrep binary on a small fixture and asserts that an excluded rule produces no finding. An assertion on the arguments cannot catch this class of defect.
- Derive the Action defaults from
connectors.yaml, or default the Action inputs to empty and let the connector defaults apply, and log a warning when a configured enabled or disabled ID matches no loaded rule. - Ship 1 and 3 together and note the change of scope in the changelog.
Until then, all_rules_enabled: 'true' makes the current behaviour explicit, and <language>_disabled_rules does take effect, because the normaliser marks those findings ignore after the scan.
I could not run the image locally. The cause above is read from the OpenGrep 1.26.0 source and agrees with the run's log. One note for whoever checks it: the OCaml copy of the prefix function at the 1.26.0 tag would not prefix a path outside the working directory, but the scan in that version goes through the Python CLI linked above, and the run's behaviour matches the Python code.
Activity