Skip to content

Commit b76e890

Browse files
tx3stndaveshanley
authored andcommitted
fix disabling of non oas rulesets with individual extending
1 parent 944f2b1 commit b76e890

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

rulesets/rulesets.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,10 @@ func (rsm ruleSetsModel) GenerateRuleSetFromSuppliedRuleSetWithHTTPClient(rulese
363363
if rsm.openAPIRuleSet.Rules[k] != nil {
364364
rs.Rules[k] = rsm.openAPIRuleSet.Rules[k]
365365
} else {
366-
// Check if it's an OWASP rule when vacuum:all is used
367-
if extends[VacuumAllRulesets] == VacuumOff || extends[VacuumAllRulesets] == VacuumAll || extends[VacuumAllRulesets] == VacuumAllRulesets {
366+
// Check if it's an OWASP rule when vacuum:all or vacuum:owasp is used
367+
if extends[VacuumAllRulesets] == VacuumOff || extends[VacuumAllRulesets] == VacuumAll || extends[VacuumAllRulesets] == VacuumAllRulesets ||
368+
extends[VacuumOwasp] == VacuumOff || extends[VacuumOwasp] == VacuumAll || extends[VacuumOwasp] == VacuumRecommended ||
369+
extends[SpectralOwasp] == VacuumOff || extends[SpectralOwasp] == VacuumAll || extends[SpectralOwasp] == VacuumRecommended {
368370
allOWASPRules := GetAllOWASPRules()
369371
if allOWASPRules[k] != nil {
370372
rs.Rules[k] = allOWASPRules[k]

rulesets/rulesets_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,3 +831,22 @@ func TestRuleSet_GetExtendsLocalSpec_Multi_Chain_Loop(t *testing.T) {
831831
assert.Contains(t, logBuffer.String(), "ruleset links to its self, circular rulesets are not permitted")
832832

833833
}
834+
func TestRuleSetsModel_GenerateRuleSetFromConfig_OwaspOff_EnableSpecificRule(t *testing.T) {
835+
// This test captures the bug where extending [vacuum:owasp, off] and then
836+
// enabling a specific OWASP rule fails with "Rule does not exist, ignoring it"
837+
yaml := `extends:
838+
- [vacuum:oas, all]
839+
- [vacuum:owasp, off]
840+
rules:
841+
owasp-integer-format: true`
842+
843+
def := BuildDefaultRuleSets()
844+
rs, err := CreateRuleSetFromData([]byte(yaml))
845+
assert.NoError(t, err)
846+
847+
repl := def.GenerateRuleSetFromSuppliedRuleSet(rs)
848+
849+
assert.NotNil(t, repl.Rules["owasp-integer-format"], "owasp-integer-format rule should be available")
850+
assert.Nil(t, repl.Rules["owasp-no-numeric-ids"], "other OWASP rules should be disabled")
851+
assert.Greater(t, len(repl.Rules), 1, "should have OpenAPI rules plus the one OWASP rule")
852+
}

0 commit comments

Comments
 (0)