Skip to content

Commit

Permalink
Added NoRequestBody to recommended ruleset
Browse files Browse the repository at this point in the history
  • Loading branch information
Calvin Lobo committed Nov 25, 2024
1 parent 468c28d commit 0cda491
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions rulesets/rule_fixes.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ const (
schemaTypeFix string = "Make sure each schema has a value type defined. Without a type, the schema is useless"

postSuccessResponseFix string = "Make sure your POST operations return a 'success' response via 2xx or 3xx response code. "

noRequestBodyResponseFix string = "Remove 'requestBody' from HTTP GET and DELETE methods"
)

const (
Expand Down
22 changes: 21 additions & 1 deletion rulesets/ruleset_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,26 @@ func GetPostSuccessResponseRule() *model.Rule {
Function: "postResponseSuccess",
FunctionOptions: opts,
},
HowToFix: oas3HostNotExampleFix,
HowToFix: postSuccessResponseFix,
}
}

// GetNoRequestBodyRule will check that HTTP GET and DELETE do not accept request bodies
func GetNoRequestBodyRule() *model.Rule {
return &model.Rule{
Name: "Check GET and DELETE methods do not accept request bodies",
Id: NoRequestBody,
Formats: model.OAS3AllFormat,
Description: "HTTP GET and DELETE should not accept request bodies",
Given: "$",
Resolved: false,
RuleCategory: model.RuleCategories[model.CategoryOperations],
Recommended: true,
Type: Style,
Severity: model.SeverityWarn,
Then: model.RuleAction{
Function: "noRequestBody",
},
HowToFix: noRequestBodyResponseFix,
}
}
2 changes: 2 additions & 0 deletions rulesets/rulesets.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ const (
OwaspConstrainedAdditionalProperties = "owasp-constrained-additionalProperties"
OwaspSecurityHostsHttpsOAS3 = "owasp-security-hosts-https-oas3"
PostResponseSuccess = "post-response-success"
NoRequestBody = "no-request-body"
SpectralOpenAPI = "spectral:oas"
SpectralOwasp = "spectral:owasp"
VacuumOwasp = "vacuum:owasp"
Expand Down Expand Up @@ -439,6 +440,7 @@ func GetAllBuiltInRules() map[string]*model.Rule {
rules[Oas3ExampleExternalCheck] = GetOAS3ExamplesExternalCheck()
rules[OasSchemaCheck] = GetSchemaTypeCheckRule()
rules[PostResponseSuccess] = GetPostSuccessResponseRule()
rules[NoRequestBody] = GetNoRequestBodyRule()

// dead.
//rules[Oas2ValidSchemaExample] = GetOAS2ExamplesRule()
Expand Down

0 comments on commit 0cda491

Please sign in to comment.