Skip to content

fix(commands): fix rule-validate/rule-test directory traversal on Windows (closes #97)#103

Merged
Wolfvin merged 1 commit into
mainfrom
fix/issue-97-rule-validate-windows-dir
Jun 30, 2026
Merged

fix(commands): fix rule-validate/rule-test directory traversal on Windows (closes #97)#103
Wolfvin merged 1 commit into
mainfrom
fix/issue-97-rule-validate-windows-dir

Conversation

@Wolfvin

@Wolfvin Wolfvin commented Jun 30, 2026

Copy link
Copy Markdown
Owner

Problem

codelens rule-validate <directory> and codelens rule-test <directory> crash on Windows with [Errno 13] Permission denied when given a directory path. The code tries to open() the directory path itself, which Windows does not allow.

Closes #97.

Root Cause

scripts/commands/rule_validate.py::execute() resolved each user-supplied rule_path to a Path and passed it straight to validate_rule_files()validate_rule()_parse_yaml(), which calls Path.read_text(). When the path is a directory, read_text() raises:

Either way the rules inside the directory were never enumerated.

rule-test already handled directories correctly via run_tests_recursive() (it branches on path.is_file() and uses rglob), so no change was needed there.

Fix

In scripts/commands/rule_validate.py::execute(), detect directory inputs and enumerate the *.yaml/*.yml rule files inside them (recursive rglob, matching rule-test's behavior). Skip .test.yaml/.test.yml (test fixtures with a different schema) and dotfiles. File inputs are processed directly — unchanged behavior.

Cross-platform: uses pathlib only; never open()s a directory.

Verification

  • PYTHONUTF8=1 python scripts/codelens.py rule-validate scripts/plugins/owasp_top10/rules/ — no crash, PASS: 1/1 file(s) valid, 36 rule(s) checked
  • PYTHONUTF8=1 python scripts/codelens.py rule-test scripts/plugins/owasp_top10/rules/ — no crash, PASS: 0/0 rule(s)
  • Single-file path still works (unchanged): rule-validate <file>.yamlPASS: 1/1 file(s) valid, 36 rule(s) checked
  • Full test suite: 788 passed, 87 skipped (baseline identical) — no regression

Files Changed

  • scripts/commands/rule_validate.py — directory expansion in execute(), help/docstring updates

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@sonarqubecloud

Copy link
Copy Markdown

@Wolfvin Wolfvin merged commit eda4884 into main Jun 30, 2026
2 of 8 checks passed
@Wolfvin Wolfvin deleted the fix/issue-97-rule-validate-windows-dir branch July 1, 2026 06:19
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.

[BUG] rule-validate and rule-test crash on Windows — directory traversal permission error

1 participant