消毒 url 和 html (url encode and sanitizer html )

javascript encode url 我们一般上是用

encodeURI (e.g. encode('https://www.stooges.com.my/contact') )

encodeURIComponent (这个是用在后面的 query string, e.g. encode('key')=encode('value')  要分开哦, = 不要把等于也拿去 encode 就错了)

c# 的话有很多可以用

refer http://www.secretgeek.net/uri_enconding

uri_encoding.png

出来的结果可以参考上面的

对于 js 的话是 

encodeURI = Uri.EscapeUriString

encodeURIComponent  = Uri.EscapeDataString

for html sanitizer 的话

用插件就可以了, 在 raw html 之前最好是消毒一下.  

https://github.com/mganss/HtmlSanitizer

js 的话可以用 

https://github.com/cure53/DOMPurify (暂时记入在这里, 以后要用的时候一起弄)

 
 
 

猜你喜欢

转载自www.cnblogs.com/keatkeat/p/13172501.html