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

未關閉
#135 0 則留言 0 個 reaction 已指派 1 人 在 GitHub 檢視

維護者通常 3 天內回覆

@lelia 已經在處理了。

開始於 2026年11月12日。

  • #141 來自 @lelia —— 未關閉

評估

難度
4/5
預估耗時
3-5 天
新手友好度
48/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
python
領域
security, testing

研究方向

Start with socket_basics/core/connector/opengrep/__init__.py around lines 149–176 and 395–410, then compare the defaults in action.yml with socket_basics/connectors.yaml and the bundled rules. Reproduce the mismatch using tests/test_opengrep_custom_rules.py and the OpenGrep behavior described in the issue. Done means enabled rule filters match loaded rule IDs, Action defaults reference existing rules and stay aligned with CLI defaults, and a test verifies excluded rules produce no findings.

由索引模型根據 Issue 內容生成。

描述

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.

  1. <language>_enabled_rules does 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-rule only removes a rule whose rewritten ID is in the list. None of the flags ever matches, so every rule in the bundled file runs.
  2. Seven rule IDs in the Action's default *_enabled_rules lists are not defined in any bundled rules file, and those defaults no longer match the CLI defaults in connectors.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 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_rules cannot narrow a scan, so every bundled rule for the enabled languages runs. Scans are noisier and slower than configured, and the Filtering rules ... N enabled IDs configured log 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

  1. 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.py L252) so the plain IDs match.
  2. 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.
  3. 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.
  4. 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.

主要語言
Python
星號
14
分支
8
平均合併
4 天 22 小時
30 天內合併 PR
8

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

SocketDev/socket-basics 的其他 Issue

查看 SocketDev/socket-basics 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。