Skip to content

Commit

Permalink
sanitize error output for prevent XSS issues
Browse files Browse the repository at this point in the history
  • Loading branch information
msaf1980 committed Oct 26, 2022
1 parent 9db0e25 commit 4a77d43
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion webapp/graphite/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ def __str__(self):
return msg


# Replace special characters "&", "<" and ">" to HTML-safe sequences.
def escape(s):
s = s.replace("&", "&amp;") # Must be done first!
s = s.replace("<", "&lt;")
s = s.replace(">", "&gt;")

return s


# decorator which turns InputParameterExceptions into Django's HttpResponseBadRequest
def handleInputParameterError(f):
def new_f(*args, **kwargs):
Expand All @@ -102,6 +111,6 @@ def new_f(*args, **kwargs):
except InputParameterError as e:
msgStr = str(e)
log.warning('%s', msgStr)
return HttpResponseBadRequest(msgStr)
return HttpResponseBadRequest(escape(msgStr))

return new_f

0 comments on commit 4a77d43

Please sign in to comment.