github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/rules/cloud/policies/digitalocean/compute/enforce_https.go (about)

     1  package compute
     2  
     3  import (
     4  	"github.com/khulnasoft-lab/defsec/internal/rules"
     5  	"github.com/khulnasoft-lab/defsec/pkg/providers"
     6  	"github.com/khulnasoft-lab/defsec/pkg/scan"
     7  	"github.com/khulnasoft-lab/defsec/pkg/severity"
     8  	"github.com/khulnasoft-lab/defsec/pkg/state"
     9  )
    10  
    11  var CheckEnforceHttps = rules.Register(
    12  	scan.Rule{
    13  		AVDID:      "AVD-DIG-0002",
    14  		Provider:   providers.DigitalOceanProvider,
    15  		Service:    "compute",
    16  		ShortCode:  "enforce-https",
    17  		Summary:    "The load balancer forwarding rule is using an insecure protocol as an entrypoint",
    18  		Impact:     "Your inbound traffic is not protected",
    19  		Resolution: "Switch to HTTPS to benefit from TLS security features",
    20  		Explanation: `Plain HTTP is unencrypted and human-readable. This means that if a malicious actor was to eavesdrop on your connection, they would be able to see all of your data flowing back and forth.
    21  
    22  You should use HTTPS, which is HTTP over an encrypted (TLS) connection, meaning eavesdroppers cannot read your traffic.`,
    23  		Links: []string{
    24  			"https://docs.digitalocean.com/products/networking/load-balancers/",
    25  		},
    26  		Terraform: &scan.EngineMetadata{
    27  			GoodExamples:        terraformEnforceHttpsGoodExamples,
    28  			BadExamples:         terraformEnforceHttpsBadExamples,
    29  			Links:               terraformEnforceHttpsLinks,
    30  			RemediationMarkdown: terraformEnforceHttpsRemediationMarkdown,
    31  		},
    32  		Severity: severity.Critical,
    33  	},
    34  	func(s *state.State) (results scan.Results) {
    35  		for _, lb := range s.DigitalOcean.Compute.LoadBalancers {
    36  			for _, rule := range lb.ForwardingRules {
    37  				if rule.EntryProtocol.EqualTo("http") {
    38  					results.Add(
    39  						"Load balancer has aforwarding rule which uses HTTP instead of HTTPS.",
    40  						rule.EntryProtocol,
    41  					)
    42  				} else {
    43  					results.AddPassed(&rule)
    44  				}
    45  			}
    46  		}
    47  		return
    48  	},
    49  )