fix(cli): validate --rule and reject unknown rule IDs (closes #11)#17
Open
dmchaledev wants to merge 1 commit into
Open
fix(cli): validate --rule and reject unknown rule IDs (closes #11)#17dmchaledev wants to merge 1 commit into
dmchaledev wants to merge 1 commit into
Conversation
An unknown or mistyped --rule value (e.g. NOAUTH instead of NO_AUTH) was cast straight to RuleId and passed to scan(). Because the scanner filters the rule set to the requested IDs, a value matching no real rule filtered it down to nothing: the scan produced zero findings, a perfect score, passed:true, and exit code 0 — silently turning a CI security gate green. Validate each --rule value against the RuleId enum and exit 2 on an unknown value, mirroring how --format and --fail-on already behave. Also list the valid rule IDs in --help so they are discoverable. Argument parsing is extracted into a side-effect-free src/args.ts module (no console output, no process.exit, no top-level execution) so it can be unit-tested directly; cli.ts now consumes a discriminated ParseResult and owns all I/O and exit codes. Adds src/__tests__/args.test.ts covering the unknown-rule regression plus format/fail-on/target/help parsing. Closes #11
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.
Summary
Fixes issue #11 — a false-green security gate. The CLI validated
--formatand--fail-onbut not--rule: an unknown or mistyped rule ID was cast straight toRuleIdand passed toscan(). Because the scanner filters the rule set down to the requested IDs (src/scanner.ts:33-35), a value that matches no real rule filtered it to nothing → zero findings, perfect score,passed: true, exit 0.For a tool advertised as a CI/CD security gate, a single typo silently turned the gate green:
Fix
--ruleagainst theRuleIdenum; exit2with a clear error on an unknown value, mirroring the existing--format/--fail-onhandling.--helpso they're discoverable.src/args.ts(no console output, noprocess.exit, no top-level execution) returning a discriminatedParseResult.cli.tsnow consumes it and owns all I/O and exit codes. This makes the whole arg layer unit-testable — previously impossible becausecli.tscallsmain()at import time.Behavior is otherwise unchanged: same flags, same error messages, same exit codes.
Testing
npm run build✓ ·npm run lint(0 warnings) ✓src/__tests__/args.test.ts— 16 tests covering the unknown-rule regression plus format / fail-on / target / help parsing. The test imports only../args(not../sarif), so it compiles and passes under the current Jest config.Note on CI
CI on
mainis currently red for a pre-existing, unrelated reason — thesrc/sarif.tsimport.metacompile error under ts-jest's CommonJS transform (introduced in #9, fixed by open PR #12). That breaks thescannerandsarifsuites regardless of this change. This PR adds no new failures, and the newargssuite passes in isolation. Merging #12 first turns the full suite green.Closes #11
https://claude.ai/code/session_016JMDkNCXgutHpTsKiCnD6v
Generated by Claude Code