github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/rules/cloud/policies/aws/cloudfront/enforce_https.go (about) 1 package cloudfront 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/providers/aws/cloudfront" 7 "github.com/khulnasoft-lab/defsec/pkg/scan" 8 "github.com/khulnasoft-lab/defsec/pkg/severity" 9 "github.com/khulnasoft-lab/defsec/pkg/state" 10 ) 11 12 var CheckEnforceHttps = rules.Register( 13 scan.Rule{ 14 AVDID: "AVD-AWS-0012", 15 Provider: providers.AWSProvider, 16 Service: "cloudfront", 17 ShortCode: "enforce-https", 18 Summary: "CloudFront distribution allows unencrypted (HTTP) communications.", 19 Impact: "CloudFront is available through an unencrypted connection", 20 Resolution: "Only allow HTTPS for CloudFront distribution communication", 21 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. 22 23 You should use HTTPS, which is HTTP over an encrypted (TLS) connection, meaning eavesdroppers cannot read your traffic.`, 24 Links: []string{ 25 "https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-https-cloudfront-to-s3-origin.html", 26 }, 27 Terraform: &scan.EngineMetadata{ 28 GoodExamples: terraformEnforceHttpsGoodExamples, 29 BadExamples: terraformEnforceHttpsBadExamples, 30 Links: terraformEnforceHttpsLinks, 31 RemediationMarkdown: terraformEnforceHttpsRemediationMarkdown, 32 }, 33 CloudFormation: &scan.EngineMetadata{ 34 GoodExamples: cloudFormationEnforceHttpsGoodExamples, 35 BadExamples: cloudFormationEnforceHttpsBadExamples, 36 Links: cloudFormationEnforceHttpsLinks, 37 RemediationMarkdown: cloudFormationEnforceHttpsRemediationMarkdown, 38 }, 39 Severity: severity.Critical, 40 }, 41 func(s *state.State) (results scan.Results) { 42 for _, dist := range s.AWS.Cloudfront.Distributions { 43 if dist.DefaultCacheBehaviour.ViewerProtocolPolicy.EqualTo(cloudfront.ViewerPolicyProtocolAllowAll) { 44 results.Add( 45 "Distribution allows unencrypted communications.", 46 dist.DefaultCacheBehaviour.ViewerProtocolPolicy, 47 ) 48 } else { 49 results.AddPassed(&dist) 50 } 51 for _, behaviour := range dist.OrdererCacheBehaviours { 52 if behaviour.ViewerProtocolPolicy.EqualTo(cloudfront.ViewerPolicyProtocolAllowAll) { 53 results.Add( 54 "Distribution allows unencrypted communications.", 55 behaviour.ViewerProtocolPolicy, 56 ) 57 } else { 58 results.AddPassed(&behaviour) 59 } 60 } 61 62 } 63 return 64 }, 65 )