防止非持久性XSS办法如下:
Web 页面渲染的所有内容或者渲染的数据都必须来自于服务端;
尽量不要从 URL,document.referrer,document.forms 等这种 DOM API 中获取数据直接渲染;
尽量不要使用 eval, new Function(),document.write(),document.writeln(),window.setInterval(),window.setTimeout(),innerHTML,document.createElement() 等可执行字符串的方法;
前端渲染的时候对任何的字段都需要做 escape 转义编码。
防止非持久性XSS办法如下:
Web页面渲染的所有内容或者渲染的数据都必须来自于服务端;
尽量不要从URL,document.referrer,document.forms等这种DOMAPI中获取数据直接渲染;
尽量不要使用eval,newFunction(),document.write(),document.writeln(),window.setInterval(),window.setTimeout(),innerHTML,document.createElement()等可执行字符串的方法;
前端渲染的时候对任何的字段都需要做escape转义编码。
推荐文章