From b92f0de2c94cdcaaf3d17fe7a507af0c7cc1d66c Mon Sep 17 00:00:00 2001 From: David Cooper Date: Thu, 30 Jan 2020 13:32:45 -0500 Subject: [PATCH] Fix HTML generation This PR fixes two issues related to the generation of HTML files. First, text that is to appear in the HTML file is first passed through html_reserved() to replace reserved characters with their corresponding entity names (e.g., '>' becomes '>'). html_reserved() seems to work correctly on Ubuntu Linux, but it does not work as expected on MacOS. On MacOS, rather than converting '>' to '>', it gets converted to '\>', and the backslash is rendered by browsers. This PR appears to fix the problem. However, given that the original version of html_reserved() was not portable, this revised version should be tested on multiple platforms. I also noticed that in almost every case in which a string is passed to html_out(), it is first run through html_reserved(), but for some reason that is not the case in out() and outln(). I can't see any reason why html_reserved() is not called first in these two cases, so this PR adds in the calls. --- testssl.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/testssl.sh b/testssl.sh index 27c4a40..f4a735f 100755 --- a/testssl.sh +++ b/testssl.sh @@ -490,11 +490,11 @@ html_reserved(){ local output "$do_html" || return 0 #sed -e 's/\&/\&/g' -e 's//\>/g' -e 's/"/\"/g' -e "s/'/\'/g" <<< "$1" - output="${1//\&/\&}" - output="${output///\>}" - output="${output//\"/\"}" - output="${output//\'/\'}" + output="${1//&/&}" + output="${output///>}" + output="${output//\"/"}" + output="${output//\'/'}" tm_out "$output" return 0 } @@ -510,8 +510,8 @@ safe_echo() { printf -- "%b" "${1//%/%%}"; } tm_out() { printf -- "%b" "${1//%/%%}"; } tmln_out() { printf -- "%b" "${1//%/%%}\n"; } -out() { printf -- "%b" "${1//%/%%}"; html_out "$1"; } -outln() { printf -- "%b" "${1//%/%%}\n"; html_out "$1\n"; } +out() { printf -- "%b" "${1//%/%%}"; html_out "$(html_reserved "$1")"; } +outln() { printf -- "%b" "${1//%/%%}\n"; html_out "$(html_reserved "$1")\n"; } #TODO: Still no shell injection safe but if just run it from the cmd line: that's fine