github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/rules/cloud/policies/aws/sam/enable_api_cache_encryption.go (about)

     1  package sam
     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 CheckEnableApiCacheEncryption = rules.Register(
    12  	scan.Rule{
    13  		AVDID:       "AVD-AWS-0110",
    14  		Provider:    providers.AWSProvider,
    15  		Service:     "sam",
    16  		ShortCode:   "enable-api-cache-encryption",
    17  		Summary:     "SAM API must have data cache enabled",
    18  		Impact:      "Data stored in the cache that is unencrypted may be vulnerable to compromise",
    19  		Resolution:  "Enable cache encryption",
    20  		Explanation: `Method cache encryption ensures that any sensitive data in the cache is not vulnerable to compromise in the event of interception`,
    21  		Links: []string{
    22  			"https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-stage-methodsetting.html#cfn-apigateway-stage-methodsetting-cachedataencrypted",
    23  		},
    24  		CloudFormation: &scan.EngineMetadata{
    25  			GoodExamples:        cloudFormationEnableApiCacheEncryptionGoodExamples,
    26  			BadExamples:         cloudFormationEnableApiCacheEncryptionBadExamples,
    27  			Links:               cloudFormationEnableApiCacheEncryptionLinks,
    28  			RemediationMarkdown: cloudFormationEnableApiCacheEncryptionRemediationMarkdown,
    29  		},
    30  		Severity: severity.Medium,
    31  	},
    32  	func(s *state.State) (results scan.Results) {
    33  		for _, api := range s.AWS.SAM.APIs {
    34  			if api.Metadata.IsUnmanaged() {
    35  				continue
    36  			}
    37  
    38  			if api.RESTMethodSettings.CacheDataEncrypted.IsFalse() {
    39  				results.Add(
    40  					"Cache data is not encrypted.",
    41  					api.RESTMethodSettings.CacheDataEncrypted,
    42  				)
    43  			} else {
    44  				results.AddPassed(&api)
    45  			}
    46  		}
    47  		return
    48  	},
    49  )