AngularJS App中的XSS

Bre*_*ako 3 javascript xss angularjs

We are using Angular JS in our app. I want to prevent all input fields from accepting JavaScript etc. Rather than check every single component is there a directive or something I could use out of the box which does this for me? Thanks

622*_*119 8

我不会做客户端过滤,而是将其留给服务器端组件.但是为了用户友好,客户端需要进行输入验证.

  • 这就是我所说的"但是为了方便用户,客户端需要进行输入验证." (5认同)
  • +1给出正确的答案.-1给@DaveMackintosh提供**可怕的**无知的回应. (2认同)

Fou*_*rth 5

角度1.2.0(以及一些早期版本)中的ngSanitize可以帮助您清理输入.

http://docs.angularjs.org/api/ngSanitize

或者,编写您自己的过滤器,通过正则表达式运行输入以删除所有HTML/JS /等.

作为一个注释,您仍然应该让服务器清理输入,同时考虑用户可以针对您的服务器API发出直接请求,并且您可能没有客户端验证.