Skip to content

Commit

Permalink
Merge pull request Checkmarx#6540 from Checkmarx/kics-922
Browse files Browse the repository at this point in the history
fix(query): Split One Query Policy
  • Loading branch information
asofsilva authored Jul 26, 2023
2 parents 6bf7aac + dc7f5c2 commit ccb11d8
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ CxPolicy[result] {
functions := document.functions
function := functions[fname]

common_lib.valid_key(function, "environment")
not common_lib.valid_key(function, "kmsKeyArn")
not hasKMSarnAtProvider(document)


result := {
"documentId": input.document[i].id,
Expand All @@ -23,6 +24,23 @@ CxPolicy[result] {
}
}

CxPolicy[result] {
document := input.document[i]

common_lib.valid_key(document.provider, "environment")
not hasKMSarnAtProvider(document)


result := {
"documentId": input.document[i].id,
"searchKey": "provider",
"issueType": "MissingAttribute",
"keyExpectedValue": "'kmsKeyArn' should be defined inside the provider",
"keyActualValue": "'kmsKeyArn' is not defined",
"searchLine": common_lib.build_search_line(["provider"], []),
}
}

hasKMSarnAtProvider(doc){
common_lib.valid_key(doc.provider, "kmsKeyArn")
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ service:

provider:
name: aws
kmsKeyArn: arn:aws:kms:us-east-1:XXXXXX:key/some-hash
environment:
TABLE_NAME: tableName1

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
frameworkVersion: '2'
service:
name: service-name
awsKmsKeyArn: arn:aws:kms:us-east-1:XXXXXX:key/some-hash

provider:
name: aws
environment:
TABLE_NAME: tableName1

functions:
hello: # this function will OVERWRITE the service level environment config above
handler: handler.hello
kmsKeyArn: arn:aws:kms:us-east-1:XXXXXX:key/some-hash
environment:
TABLE_NAME: tableName2
goodbye: # this function will INHERIT the service level environment config above
handler: handler.goodbye
kmsKeyArn: arn:aws:kms:us-east-1:XXXXXX:key/some-hash
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
[
{
"queryName": "Serverless Function Environment Variables Not Encrypted",
"severity": "HIGH",
"line": 6,
"fileName": "positive1.yml"
},
{
"queryName": "Serverless Function Environment Variables Not Encrypted",
"severity": "HIGH",
"line": 12,
"fileName": "positive1.yml"
},
{
"queryName": "Serverless Function Environment Variables Not Encrypted",
"severity": "HIGH",
"line": 6,
"fileName": "positive2.yml"
}
]

0 comments on commit ccb11d8

Please sign in to comment.