-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
auth_insecure_schemes.go
53 lines (43 loc) · 1.66 KB
/
auth_insecure_schemes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2023 Princess B33f Heavy Industries / Dave Shanley
// SPDX-License-Identifier: MIT
package owasp
import (
"fmt"
"github.com/daveshanley/vacuum/model"
"github.com/daveshanley/vacuum/utils"
"github.com/pb33f/doctor/model/high/base"
"gopkg.in/yaml.v3"
"strings"
)
type AuthInsecureSchemes struct{}
// GetSchema returns a model.RuleFunctionSchema defining the schema of the DefineError rule.
func (is AuthInsecureSchemes) GetSchema() model.RuleFunctionSchema {
return model.RuleFunctionSchema{Name: "jwt_best_practice"}
}
// RunRule will execute the DefineError rule, based on supplied context and a supplied []*yaml.Node slice.
func (is AuthInsecureSchemes) RunRule(_ []*yaml.Node, context model.RuleFunctionContext) []model.RuleFunctionResult {
var results []model.RuleFunctionResult
if context.DrDocument == nil {
return results
}
ss := context.DrDocument.V3Document.Components.SecuritySchemes
for schemePairs := ss.First(); schemePairs != nil; schemePairs = schemePairs.Next() {
scheme := schemePairs.Value()
if scheme.Value.Type == "http" {
if strings.ToLower(scheme.Value.Scheme) == "negotiate" ||
strings.ToLower(scheme.Value.Scheme) == "oauth" {
node := scheme.Value.GoLow().Scheme.KeyNode
result := model.RuleFunctionResult{
Message: utils.SuppliedOrDefault(context.Rule.Message, "authentication scheme is considered outdated or insecure"),
StartNode: node,
EndNode: node,
Path: fmt.Sprintf("%s.%s", scheme.GenerateJSONPath(), "scheme"),
Rule: context.Rule,
}
scheme.AddRuleFunctionResult(base.ConvertRuleResult(&result))
results = append(results, result)
}
}
}
return results
}