Improve whitelisting to allow regexes and fuzzy/strict matching

This commit is contained in:
Quinn Stevens
2020-07-24 15:44:37 +01:00
parent 2186f648c8
commit 28b3604b1c
2 changed files with 21 additions and 3 deletions

View File

@@ -112,13 +112,20 @@ textFail(){
level="FAIL"
colorcode="$BAD"
while read -r i; do
ignore_check_name="${i%:*}"
ignore_value="${i#*${CHECK_NAME}:}"
ignore_check_name="${i%%:*}" # Check name is everything up to the first :
ignore_value="${i#*${CHECK_NAME}:}" # Ignore value is everything after the first :
if [[ ${ignore_value} =~ .*:f ]]; then
# Fuzzy search - if this pattern appears anywhere in the line, it matches.
resource_value=".*${ignore_value%:*}.*"
else
# Strict search - pattern has to be its own word.
resource_value="[[:space:]^]${ignore_value}[[:space:]$]"
fi
if [[ ${ignore_check_name} != "${CHECK_NAME}" ]]; then
# not for this check
continue
fi
if [[ $1 =~ .*"${ignore_value}".* ]]; then
if [[ $1 =~ ${resource_value} ]]; then
level="WARNING"
colorcode="$WARNING"
break