fix(commands): fix rule-validate/rule-test directory traversal on Windows (closes #97)#103
Merged
Merged
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
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
codelens rule-validate <directory>andcodelens rule-test <directory>crash on Windows with[Errno 13] Permission deniedwhen given a directory path. The code tries toopen()the directory path itself, which Windows does not allow.Closes #97.
Root Cause
scripts/commands/rule_validate.py::execute()resolved each user-suppliedrule_pathto aPathand passed it straight tovalidate_rule_files()→validate_rule()→_parse_yaml(), which callsPath.read_text(). When the path is a directory,read_text()raises:IsADirectoryErroron Linux/macOS (caught by theOSErrorhandler and reported as a spurious "Cannot read file" error instead of validating the rules inside), andPermissionErroron Windows (issue [BUG] rule-validate and rule-test crash on Windows — directory traversal permission error #97 — the Windows crash).Either way the rules inside the directory were never enumerated.
rule-testalready handled directories correctly viarun_tests_recursive()(it branches onpath.is_file()and usesrglob), so no change was needed there.Fix
In
scripts/commands/rule_validate.py::execute(), detect directory inputs and enumerate the*.yaml/*.ymlrule files inside them (recursiverglob, matchingrule-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
pathlibonly; neveropen()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) checkedPYTHONUTF8=1 python scripts/codelens.py rule-test scripts/plugins/owasp_top10/rules/— no crash,PASS: 0/0 rule(s)rule-validate <file>.yaml→PASS: 1/1 file(s) valid, 36 rule(s) checkedFiles Changed
scripts/commands/rule_validate.py— directory expansion inexecute(), help/docstring updates