Skip to content

Commit

Permalink
Merge pull request ddnet#31 from ChillerDragon/pr_meta_images
Browse files Browse the repository at this point in the history
Disallow embedded images
  • Loading branch information
Jupeyy authored Apr 2, 2023
2 parents 7368ed4 + 2931a9f commit 36f1093
Showing 1 changed file with 43 additions and 38 deletions.
81 changes: 43 additions & 38 deletions scripts/check_svg_meta.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,57 @@ arg_fix=0

for arg in "$@"
do
if [ "$arg" == "--help" ] || [ "$arg" == "-h" ] || [ "$arg" == "help" ]
then
echo "usage: $(tput bold)$(basename "$0") [OPTION]$(tput sgr0)"
echo "options:"
echo " --help|-h show this help"
echo " --fix|-f automatically fix files"
exit 0
elif [ "$arg" == "--fix" ] || [ "$arg" == "-f" ]
then
arg_fix=1
else
echo "unkown option $arg try --help"
exit 1
fi
if [ "$arg" == "--help" ] || [ "$arg" == "-h" ] || [ "$arg" == "help" ]
then
echo "usage: $(tput bold)$(basename "$0") [OPTION]$(tput sgr0)"
echo "options:"
echo " --help|-h show this help"
echo " --fix|-f automatically fix files"
exit 0
elif [ "$arg" == "--fix" ] || [ "$arg" == "-f" ]
then
arg_fix=1
else
echo "unkown option $arg try --help"
exit 1
fi
done

while IFS= read -r file
do
if [ "$arg_fix" == "1" ]
then
sed -i -r '/export-filename="([A-Z]:|\/)/d' "$file"
continue
fi
while IFS= read -r line
do
printf "[-] ERROR: absolute export path found in %s:%d\\n" \
"$file" \
"$(echo "$line" | cut -d':' -f1)"
err="$((err+1))"
done < <(grep -nE 'export-filename="([A-Z]:\\|/)' "$file")

# check if there is width and height parameter
width_found=$(grep -Eiwzo "<svg[^>]*>" "$file" | tr '\0' '\n' | grep -Eo "width=\"([0-9.]|px)*\"")
height_found=$(grep -Eiwzo "<svg[^>]*>" "$file" | tr '\0' '\n' | grep -Eo "height=\"([0-9.]|px)*\"")

if [[ "$width_found" == "" || "$height_found" == "" ]]
then
printf "[-] ERROR: no width or height parameter found in %s\\n" "$file"
err="$((err+1))"
fi
if [ "$arg_fix" == "1" ]
then
sed -i -r '/export-filename="([A-Z]:|\/)/d' "$file"
continue
fi
while IFS= read -r line
do
printf "[-] ERROR: absolute export path found in %s:%d\\n" \
"$file" \
"$(echo "$line" | cut -d':' -f1)"
err="$((err+1))"
done < <(grep -nE 'export-filename="([A-Z]:\\|/)' "$file")

# check if there is width and height parameter
width_found=$(grep -Eiwzo "<svg[^>]*>" "$file" | tr '\0' '\n' | grep -Eo "width=\"([0-9.]|px)*\"")
height_found=$(grep -Eiwzo "<svg[^>]*>" "$file" | tr '\0' '\n' | grep -Eo "height=\"([0-9.]|px)*\"")

if [[ "$width_found" == "" || "$height_found" == "" ]]
then
printf "[-] ERROR: no width or height parameter found in %s\\n" "$file"
err="$((err+1))"
fi
if grep -qF 'xlink:href="data:image/png;base64,' "$file"
then
printf "[-] ERROR: embedded image found %s\\n" "$file"
err="$((err+1))"
fi
done < <(find . -type f -name "*.svg")

if [ "$err" -ne "0" ]
then
echo "[-] failed ($err errors)"
exit 1
echo "[-] failed ($err errors)"
exit 1
fi

echo "[+] done"
Expand Down

0 comments on commit 36f1093

Please sign in to comment.