Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use html.escape for all output that may be user-influenced. #404

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions Tests/iaas/flavor-naming/flavor-form.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import sys
import re
import urllib.parse
import html
import importlib
fnmck = importlib.import_module("flavor-name-check")

Expand All @@ -28,10 +29,6 @@
def parse_name(fnm):
"return tuple with flavor description"
global FLAVOR_SPEC, FLAVOR_NAME, ERROR
# Sanitize
# fnm = re.sub(r"<( *script)", r"<!--\1", fnm, flags=re.I)
fnm = re.sub(r"<", r"&lt;", fnm)
fnm = re.sub(r">", r"&gt;", fnm)
FLAVOR_NAME = fnm
try:
FLAVOR_SPEC = fnmck.parsename(fnm)
Expand All @@ -46,18 +43,18 @@ def output_parse():
"output pretty description from SCS flavor name"
fnmd = importlib.import_module("flavor-name-describe")
print('\t<br/>\n\t<FORM ACTION="/cgi-bin/flavor-form.py" METHOD="GET">')
print(f'\t Flavor name: <INPUT TYPE="text" NAME="flavor" SIZE=24 VALUE="{FLAVOR_NAME}"/>')
print(f'\t Flavor name: <INPUT TYPE="text" NAME="flavor" SIZE=24 VALUE="{html.escape(FLAVOR_NAME, quote=True)}"/>')
print('\t <INPUT TYPE="submit" VALUE="Submit"/>')
# print(' <INPUT TYPE="reset" VALUE="Clear"/>\n</FORM>')
print('\t</FORM>')
if FLAVOR_NAME:
print(f"\t<br/><b>Flavor {FLAVOR_NAME}:</b>")
print(f"\t<br/><b>Flavor {html.escape(FLAVOR_NAME, quote=True)}:</b>")
if FLAVOR_SPEC:
print(f"\t{fnmd.prettyname(FLAVOR_SPEC)}")
print(f"\t{html.escape(fnmd.prettyname(FLAVOR_SPEC), quote=True)}")
else:
print("\tNot an SCS flavor")
if ERROR:
print(f"\t<br/>{ERROR})")
print(f"\t<br/>{html.escape(ERROR, quote=True)})")


def output_generate():
Expand Down