1 xss攻击
5 xss攻击(跨站脚本攻击,用户页面提交数据来盗取cookie) - 慎用safe, 和mark_safe -- 如果要用,必须要过滤 - 定义: 用户提交内容,在页面展示用html显示的时候 页面提交一些script脚本,盗取cookie # views msg = [] def xss(request): if request.method == "GET": return render(request, 'xss.html') else: tmp = request.POST.get('content') msg.append(tmp) print(tmp) return render(request, 'xss.html') def content_index(request): print(msg) return render(request, 'content_index.html', {'msg':msg}) # templates <body> <h2>评论</h2> <form action="/xss.html" method="POST"> <input type="text" placeholder="请输入评论" name="content"> <input type="submit" value="提交"> </form> </body> <body> <h2>评论</h2> {% for item in msg %} <div>{{ item }}</div> {# <div>{{ item|safe }}</div>#} {# django已经阻止xss攻击了,#} {# 如果使用item|safe,那就麻烦了:此时用户提交评论<script>alert(123)</script>,#} {# 就会弹出框123(真正的做法是获取cookie,然后别人就可以用你的账户登录网站了,那时候就麻烦)#} {% endfor %} </body>