我有一个基于Django的API。在用CheckMarx扫描我的应用程序之后,如果显示我已经在这里反映了XSS的可移植性:
user_input_data = json.loads(request.GET.get('user_input_data'))我已经尝试过的是:
django.utils.html.escpae
django.utils.html.strip_tags
html.escape
escapejson软件包每次我运行扫描时,它都会在这个位置找到存储的XSS。
发布于 2021-09-18 00:26:00
您所尝试的是正确和可接受的,但是Checkmarx对Django的支持是有限的,这就是它不承认您使用的任何功能的原因。您需要与您的安全团队争论这一点,并让他们认识到这是防止XSS的正确方法之一。
通过使用替换函数和替换“<”和'>‘字符来清除输入的基本方法.不是一种强有力的方法,但这正是Checkmarx所认识到的。
def escape(s, quote=None):
'''Replace special characters "&", "<" and ">" to HTML-safe sequences.
If the optional flag quote is true, the quotation mark character (")
is also translated.'''
s = s.replace("&", "&") # Must be done first!
s = s.replace("<", "<")
s = s.replace(">", ">")
if quote:
s = s.replace('"', """)
return s来自此代码段post的信用
https://stackoverflow.com/questions/69049419
复制相似问题