HTML-Entity escaping to prevent XSS

前端 未结 2 684
一整个雨季
一整个雨季 2021-02-02 17:44

I have some user input. Within my code, I ensure that the following symbols are escaped:

& -> & 
< -> < 
> -> >
<         


        
2条回答
  •  离开以前
    2021-02-02 18:11

    I recommend you to use Appache Common Lang library to escape strings, for exmaple to escape HTML:

    String escapedString = org.apache.commons.lang.StringEscapeUtils.escapeHtml(String str);
    

    the library has many useful methods to escape in HTML, XML, Javascript.

提交回复
热议问题