Skip to content

Commit 41da17a

Browse files
committed
1 parent 81aa0ca commit 41da17a

File tree

5 files changed

+72
-4
lines changed

5 files changed

+72
-4
lines changed

cmd/build_results.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func BuildResultsWithDocCheckSkip(
6060
if !silent {
6161
box := pterm.DefaultBox.WithLeftPadding(5).WithRightPadding(5)
6262
box.BoxStyle = pterm.NewStyle(pterm.FgLightRed)
63-
box.Println(pterm.LightRed("🚨 HARD MODE ENABLED 🚨"))
63+
box.Println(pterm.LightRed(HardModeEnabled))
6464
pterm.Println()
6565
}
6666
}
@@ -101,6 +101,16 @@ func BuildResultsWithDocCheckSkip(
101101
return nil, nil, rsErr
102102
}
103103
}
104+
105+
// Merge OWASP rules if hard mode is enabled
106+
if MergeOWASPRulesToRuleSet(selectedRS, hardMode) {
107+
if !silent {
108+
box := pterm.DefaultBox.WithLeftPadding(5).WithRightPadding(5)
109+
box.BoxStyle = pterm.NewStyle(pterm.FgLightRed)
110+
box.Println(pterm.LightRed(HardModeWithCustomRuleset))
111+
pterm.Println()
112+
}
113+
}
104114
}
105115

106116
pterm.Info.Printf("Linting against %d rules: %s\n", len(selectedRS.Rules), selectedRS.DocumentationURI)

cmd/lint.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func GetLintCommand() *cobra.Command {
152152
if !silent && !pipelineOutput {
153153
box := pterm.DefaultBox.WithLeftPadding(5).WithRightPadding(5)
154154
box.BoxStyle = pterm.NewStyle(pterm.FgLightRed)
155-
box.Println(pterm.LightRed("🚨 HARD MODE ENABLED 🚨"))
155+
box.Println(pterm.LightRed(HardModeEnabled))
156156
pterm.Println()
157157
}
158158
}
@@ -185,6 +185,16 @@ func GetLintCommand() *cobra.Command {
185185
pterm.Println()
186186
return rsErr
187187
}
188+
189+
// Merge OWASP rules if hard mode is enabled
190+
if MergeOWASPRulesToRuleSet(selectedRS, hardModeFlag) {
191+
if !silent && !pipelineOutput {
192+
box := pterm.DefaultBox.WithLeftPadding(5).WithRightPadding(5)
193+
box.BoxStyle = pterm.NewStyle(pterm.FgLightRed)
194+
box.Println(pterm.LightRed(HardModeWithCustomRuleset))
195+
pterm.Println()
196+
}
197+
}
188198
}
189199

190200
// Show which rules are being used (after ruleset is fully loaded)

cmd/shared_functions.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ import (
1818
"time"
1919
)
2020

21+
// Hard mode message constants
22+
const (
23+
HardModeEnabled = "🚨 HARD MODE ENABLED 🚨"
24+
HardModeWithCustomRuleset = "🚨 OWASP Rules added to custom ruleset 🚨"
25+
)
2126

2227
// BuildRuleSetFromUserSuppliedSet creates a ready to run ruleset, augmented or provided by a user
2328
// configured ruleset. This ruleset could be lifted directly from a Spectral configuration.
@@ -62,6 +67,29 @@ func BuildRuleSetFromUserSuppliedLocation(rulesetFlag string, rs rulesets.RuleSe
6267
}
6368
}
6469

70+
// MergeOWASPRulesToRuleSet merges OWASP rules into the provided ruleset when hard mode is enabled.
71+
// This fixes issue #552 where -z flag was ignored when using -r flag.
72+
// Returns true if OWASP rules were merged, false otherwise.
73+
func MergeOWASPRulesToRuleSet(selectedRS *rulesets.RuleSet, hardModeFlag bool) bool {
74+
if !hardModeFlag || selectedRS == nil {
75+
return false
76+
}
77+
78+
owaspRules := rulesets.GetAllOWASPRules()
79+
if selectedRS.Rules == nil {
80+
selectedRS.Rules = make(map[string]*model.Rule)
81+
}
82+
83+
for k, v := range owaspRules {
84+
// Add OWASP rule if it doesn't already exist in the custom ruleset
85+
if selectedRS.Rules[k] == nil {
86+
selectedRS.Rules[k] = v
87+
}
88+
}
89+
90+
return true
91+
}
92+
6593
// RenderTimeAndFiles will render out the time taken to process a specification, and the size of the file in kb.
6694
// it will also render out how many files were processed.
6795
func RenderTimeAndFiles(timeFlag bool, duration time.Duration, fileSize int64, totalFiles int) {

cmd/spectral_report.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func GetSpectralReportCommand() *cobra.Command {
145145
if !stdIn && !stdOut {
146146
box := pterm.DefaultBox.WithLeftPadding(5).WithRightPadding(5)
147147
box.BoxStyle = pterm.NewStyle(pterm.FgLightRed)
148-
box.Println(pterm.LightRed("🚨 HARD MODE ENABLED 🚨"))
148+
box.Println(pterm.LightRed(HardModeEnabled))
149149
pterm.Println()
150150
}
151151

@@ -181,6 +181,16 @@ func GetSpectralReportCommand() *cobra.Command {
181181
pterm.Println()
182182
return rsErr
183183
}
184+
185+
// Merge OWASP rules if hard mode is enabled
186+
if MergeOWASPRulesToRuleSet(selectedRS, hardModeFlag) {
187+
if !stdIn && !stdOut {
188+
box := pterm.DefaultBox.WithLeftPadding(5).WithRightPadding(5)
189+
box.BoxStyle = pterm.NewStyle(pterm.FgLightRed)
190+
box.Println(pterm.LightRed(HardModeWithCustomRuleset))
191+
pterm.Println()
192+
}
193+
}
184194
}
185195

186196
if !stdIn && !stdOut {

cmd/vacuum_report.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func GetVacuumReportCommand() *cobra.Command {
146146
if !stdIn && !stdOut {
147147
box := pterm.DefaultBox.WithLeftPadding(5).WithRightPadding(5)
148148
box.BoxStyle = pterm.NewStyle(pterm.FgLightRed)
149-
box.Println(pterm.LightRed("🚨 HARD MODE ENABLED 🚨"))
149+
box.Println(pterm.LightRed(HardModeEnabled))
150150
pterm.Println()
151151
}
152152

@@ -183,6 +183,16 @@ func GetVacuumReportCommand() *cobra.Command {
183183
pterm.Println()
184184
return rsErr
185185
}
186+
187+
// Merge OWASP rules if hard mode is enabled
188+
if MergeOWASPRulesToRuleSet(selectedRS, hardModeFlag) {
189+
if !stdIn && !stdOut {
190+
box := pterm.DefaultBox.WithLeftPadding(5).WithRightPadding(5)
191+
box.BoxStyle = pterm.NewStyle(pterm.FgLightRed)
192+
box.Println(pterm.LightRed(HardModeWithCustomRuleset))
193+
pterm.Println()
194+
}
195+
}
186196
}
187197

188198
if !stdIn && !stdOut {

0 commit comments

Comments
 (0)