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

Fix code scanning alert no. 2: Reflected server-side cross-site scripting #4620

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
10 changes: 5 additions & 5 deletions scripts/accumulator-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import json
import paho.mqtt.client as mqtt
import threading

import html

def usage_and_exit(msg):
"""
Expand Down Expand Up @@ -353,9 +353,9 @@ def record_request(request):
params = ''
for k in request.args:
if (params == ''):
params = k + '=' + request.args[k]
params = html.escape(k) + '=' + html.escape(request.args[k])
else:
params += '&' + k + '=' + request.args[k]
params += '&' + html.escape(k) + '=' + html.escape(request.args[k])

if (params == ''):
s += '\n'
Expand All @@ -364,7 +364,7 @@ def record_request(request):

# Store headers (according to pre-defined order)
for h in sort_headers(request.headers.keys()):
s += h + ': ' + request.headers[h] + '\n'
s += h + ': ' + html.escape(request.headers[h]) + '\n'

# Store payload
if ((request.data is not None) and (len(request.data) != 0)):
Expand All @@ -377,7 +377,7 @@ def record_request(request):
except ValueError as e:
s += str(e)
else:
s += request.data.decode("utf-8")
s += html.escape(request.data.decode("utf-8"))

# Separator
s += '=======================================\n'
Expand Down
Loading