Skip to content

Commit 5652005

Browse files
authored
fix(detect-secrets): Include missing colon to link values (prowler-cloud#1078)
1 parent 198c7f4 commit 5652005

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

checks/check_extra742

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,42 +27,44 @@ extra742(){
2727
SECRETS_TEMP_FOLDER="$PROWLER_DIR/secrets-$ACCOUNT_NUM"
2828
if [[ ! -d $SECRETS_TEMP_FOLDER ]]; then
2929
# this folder is deleted once this check is finished
30-
mkdir $SECRETS_TEMP_FOLDER
30+
mkdir "${SECRETS_TEMP_FOLDER}"
3131
fi
3232

3333
for regx in $REGIONS; do
34-
CFN_STACKS=$($AWSCLI cloudformation describe-stacks $PROFILE_OPT --region $regx --output json 2>&1)
35-
if [[ $(echo "$CFN_STACKS" | grep -E 'AccessDenied|UnauthorizedOperation|AuthorizationError') ]]; then
34+
CFN_STACKS=$("${AWSCLI}" cloudformation describe-stacks $PROFILE_OPT --region "${regx}" --output json 2>&1)
35+
if grep -q -E 'AccessDenied|UnauthorizedOperation|AuthorizationError' <<< "$CFN_STACKS" ; then
3636
textInfo "$regx: Access Denied trying to describe stacks" "$regx"
3737
continue
38-
fi
39-
LIST_OF_CFN_STACKS=$(echo $CFN_STACKS | jq -r '.Stacks[].StackName')
38+
fi
39+
LIST_OF_CFN_STACKS=$(jq -r '.Stacks[].StackName' <<< "${CFN_STACKS}")
4040
if [[ $LIST_OF_CFN_STACKS ]];then
41-
for stack in $LIST_OF_CFN_STACKS; do
42-
CFN_OUTPUTS_FILE="$SECRETS_TEMP_FOLDER/extra742-$stack-$regx-outputs.txt"
43-
echo $CFN_STACKS | jq --arg s "$stack" -r '.Stacks[] | select( .StackName == $s ) | .Outputs[]? | "\(.OutputKey) \(.OutputValue)"' > $CFN_OUTPUTS_FILE
44-
45-
if [ -s $CFN_OUTPUTS_FILE ];then
46-
# This finds ftp or http URLs with credentials and common keywords
47-
# FINDINGS=$(egrep -i '[[:alpha:]]*://[[:alnum:]]*:[[:alnum:]]*@.*/|key|secret|token|pass' $CFN_OUTPUTS_FILE |wc -l|tr -d '\ ')
48-
# New implementation using https://github.com/Yelp/detect-secrets
49-
FINDINGS=$(secretsDetector file $CFN_OUTPUTS_FILE)
41+
for stackName in $LIST_OF_CFN_STACKS; do
42+
CFN_OUTPUTS_FILE="$SECRETS_TEMP_FOLDER/extra742-${stackName}-${regx}-outputs.txt"
43+
# OutputKey and OutputValue are separated by a colon because secrets-detector needs a way to link both values
44+
jq --arg stackName "$stackName" -r '.Stacks[] | select( .StackName == $stackName ) | .Outputs[]? | "\(.OutputKey):\(.OutputValue)"' <<< "${CFN_STACKS}" > "${CFN_OUTPUTS_FILE}"
45+
if [ -s "${CFN_OUTPUTS_FILE}" ];then
46+
FINDINGS=$(secretsDetector file "${CFN_OUTPUTS_FILE}")
5047
if [[ $FINDINGS -eq 0 ]]; then
51-
textPass "$regx: No secrets found in stack $stack Outputs" "$regx" "$stack"
52-
# delete file if nothing interesting is there
53-
rm -f $CFN_OUTPUTS_FILE
48+
textPass "$regx: No secrets found in stack ${stackName} Outputs" "$regx" "${stackName}"
49+
# Delete file if nothing interesting is there
50+
rm -f "${CFN_OUTPUTS_FILE}"
5451
else
55-
textFail "$regx: Potential secret found in stack $stack Outputs" "$regx" "$stack"
56-
# delete file to not leave trace, user must look at the CFN Stack
57-
rm -f $CFN_OUTPUTS_FILE
52+
textFail "$regx: Potential secret found in stack ${stackName} Outputs" "$regx" "${stackName}"
53+
# Delete file to not leave trace, user must look at the CFN Stack
54+
rm -f "${CFN_OUTPUTS_FILE}"
5855
fi
5956
else
60-
textInfo "$regx: CloudFormation stack $stack has no Outputs" "$regx"
57+
textInfo "$regx: CloudFormation stack ${stackName} has no Outputs" "$regx"
6158
fi
6259
done
6360
else
6461
textInfo "$regx: No CloudFormation stacks found" "$regx"
6562
fi
6663
done
67-
rm -rf $SECRETS_TEMP_FOLDER
64+
65+
# Cleanup temporary folder
66+
if [[ -d $SECRETS_TEMP_FOLDER ]]
67+
then
68+
rm -rf "${SECRETS_TEMP_FOLDER}"
69+
fi
6870
}

0 commit comments

Comments
 (0)