Repository navigation
Fix the compliance flags' arity, and gate the class - #842
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Both compliance flags were registered as StringVar, so pflag REQUIRED a value — while the mode was decided by Changed() and the value was never read. --nist-800-171 has nothing to supply, so it ate the next token: `spawn validate --nist-800-171 -o json` consumed "-o" as the flag's value and "json" as a positional, then printed a human table and exited 0. The documented JSON path silently produced the wrong format. Three of the tool's own words failed as a result: the Example `spawn validate --nist-800-171`, the same invocation in its -o json Example, and the remedy its error message prints. --nist-800-171 is a bool now. --nist-800-53 keeps its baseline and gains NoOptDefVal = "low", so a bare --nist-800-53 means what the handler already assumed when the value was empty. An invalid baseline is rejected at the flag naming the accepted values, instead of surfacing twelve frames down as "unknown compliance mode: nist-800-53-nonsense". Passing both frameworks is refused rather than 800-171 silently winning. TestExampleFlagsCanBeWrittenAsDocumented gates the class: a flag a command documents without a value must accept being written that way. an argument the example omits. Its first version asked "was a value supplied?" by checking whether any later flag appeared anywhere on the line, which reported `--stack my-stack --region x` as giving --stack no value — about forty false positives. The question is only ever about the next token. TestNoTwoLiveFlagsShareOneVariable covers what hid this from #807's unread-flag gate: both flags bound to one variable, so its reference count of three looked like it was read. Aliases are exempt by the code's own declaration rather than a hand list — deprecated, or a usage saying "Alias for --x". The first version exempted only deprecated flags and reported `launch --print-config`, a deliberate LIVE alias of --dry-run. TestValidateCallsTheBaselineCheck exists because testing a validator is not testing that anything validates: TestNIST53BaselineValidation kept passing against a revert to `if !isNIST53Baseline(val) && false`, which left the function correct and the handler unguarded. Closes #808
scttfrdmn
force-pushed
the
fix/808-compliance-flag-arity
branch
from
October 11, 2026 20:29
99963dd to
a68a99e
Compare
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.
Closes #808.
Correctness audit 2026-10. Last of Phase 3.The defect
Both compliance flags were registered as
StringVar, so pflag required a value —while the mode was decided by
Changed()and the value was never read:--nist-800-171has nothing to supply, so it ate the next token:-obecame the flag's value andjsona positional, so the documented JSON pathsilently produced the wrong format. Three of the tool's own words failed: the Example
spawn validate --nist-800-171, the same invocation in its-o jsonExample, and theremedy its error message prints.
After
--nist-800-171is a bool.--nist-800-53keeps its baseline and gainsNoOptDefVal = "low". The invalid baseline is rejected at the flag, naming theaccepted values, instead of surfacing twelve frames down as
unknown compliance mode: nist-800-53-nonsense— an internal string rather than the flagthe user typed. And both frameworks at once is refused rather than 800-171 silently
winning: a caller who passed both asked for something this command cannot do, and quietly
doing half of it is the failure mode this whole issue is about.
Gates, and why #807's didn't catch this
TestExampleFlagsCanBeWrittenAsDocumented— every flag a command documents without avalue must accept being written that way. #806's gate checks a named flag exists; it
cannot tell that the flag demands an argument the example omits. This resolves against
pflag's own notion of arity, which is the only authority on it.
TestNoTwoLiveFlagsShareOneVariable— this is precisely what hid #808 from #807'sunread-flag gate. Both flags bound to
validateComplianceMode, so it had a declarationand two registrations: a reference count of three, which looked read. Shared variables
also clobber each other, whichever parses last winning.
TestValidateCallsTheBaselineCheck— because testing a validator is not testing thatanything validates.
TestNIST53BaselineValidationexercisesisNIST53Baselinedirectlyand kept passing against a revert to
if !isNIST53Baseline(val) && false, which left thefunction correct and the handler unguarded.
Two gate bugs found by running them
Both worth recording, because each would have made the gate useless in a different
direction:
value supplied?" from whether any later flag appeared anywhere on the line, so
--stack my-stack --region xlooked like--stackhad no value. The question is onlyever about the immediately following token; it walks tokens now instead of regex
positions.
launch --print-config— a deliberate live alias of--dry-run, declared as such in itsusage string. The exemption now comes from the code's own statement of intent
(deprecated, or a usage matching "Alias for --x"), the same way Two inert flags:
pipeline launch --waitnever waits, andlogs --regionis dropped while shadowing the global --region #807's exemption comesfrom
MarkDeprecated, rather than from a list I maintain.Verification
make check,make check-docswithdocs-gen/validate.mdregenerated, changelog gate,semgrep0 findings, Tier 0 e2e with-count=1.Five compiling reverts:
--nist-800-171back to aStringVar(caught by the generalExample gate, reported against the command's own documented examples),
NoOptDefValdropped, the baseline check disabled, and two live flags on one variable. The
StringVarrevert needed two attempts — the first did not compile, so it proved nothing.