ASahu202858 (Community Member) asked a question.

How to fix Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS) (CWE ID 80) in below line, after adding StringEscapeUtils :
StringEscapeUtils.unescapeHtml(Encode.forHtmlContent(requestString)).getBytes()

Providing more code snippet for better understanding :

//import used

import org.apache.commons.lang.StringEscapeUtils;

import org.owasp.encoder.Encode;

 

 

DataOutputStream dtOpStrm = new DataOutputStream(XXXXXXXXXXXXXXXXXXXXX);

 

// getting Cross-Site Scripting (XSS) in below line

dtOpStrm.write(StringEscapeUtils.unescapeHtml(Encode.forHtmlContent(requestString)).getBytes());

 

 

After adding StringEscapeUtils.unescapeHtml(), we started getting this flaw.

We need this for converting "& to &" html chars.

 

Please suggest some solution.

 

I already tried few solutions from Veracode Community regarding this flaw.

Seems like we still facing this Vulnerability.


  • Hi @ASahu202858 (Community Member)​ ,

     

    "StringEscapeUtils.unescapeHtml(Encode.forHtmlContent(" does not do anything. It's like tying your shoes and immediately untying them.

    Typically, if adding HTML encoding is producing unwanted "&" characters it means that you are either:

    1. Double encoding, doing HTML encode earlier, meaning that you can simply remove the later encoding.
    2. Encoding something that is not HTML, a typical example would be HTML encoding JSON data. JSON should not be HTML encoded, rather the correct "Content-Type" header should be used ("application/json").

     

    If you have any other questions, I would recommend you schedule a consultation call to discuss.

    You can check out this knowledge article (https://community.veracode.com/s/article/How-to-schedule-a-consultation-call) on how to schedule a consultation call with us.

     

    Thank you,

    Boy Baukema

    Expand Post

Topics (2)

No articles found
Loading

Ask the Community

Get answers, share a use case, discuss your favorite features, or get input from the community.