2010-03-05 44 views
3

我們一直在尋找HTML編碼我們的JSP頁面以對付XSS的方法。Java - XSS - HTML編碼 - 字符實體引用與數字實體引用

OWASP的網站顯示How_to_perform_HTML_entity_encoding_in_Java

約實體文章會談編碼 「大5」,即

21   {"#39", new Integer(39)}, // ' - apostrophe 
    22   {"quot", new Integer(34)}, // " - double-quote 
    23   {"amp", new Integer(38)}, // & - ampersand 
    24   {"lt", new Integer(60)}, // < - less-than 
    25   {"gt", new Integer(62)}, // > - greater-than 

<script> 

被編碼爲

&lt;script&gt; 

但包括在本文中的Java代碼示例使用數字參考編碼即

<script></script> 

被編碼爲

&#60;script&#62;&#60;&#47;script&#62; 

是否有使用過實體引用字符引用一個原因是什麼?哪個最好,爲什麼?

回答

2

它們與保護自己免受XSS的威脅一樣。唯一真正的實際差異是可讀性和大小。