Robert (Community Member) asked a question.

CWE ID 80 (XSS) - JSP Tag - Bug (false positive) or are we actually doing something "wrong"?

So we have the following JSP tag (minor changes for simplicity, hopefully I didn't introduce any typos):

 

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@taglib prefix="e" uri="https://www.owasp.org/index.php/OWASP_Java_Encoder_Project" %>

<select id="${e:forHtmlAttribute(selectId)}" >

<c:forEach var="role" items="${roles}">

<c:choose>

<c:when test="${role.id eq selectedId or roles.size() eq 1}">

<c:set var="selected" value="selected"/>

</c:when>

<c:otherwise>

<c:set var="selected" value=""/>

</c:otherwise>

</c:choose>

<option

value="${e:forHtmlAttribute(role.id)}"

${selected}

title="${e:forHtmlAttribute(role.description)}"

>${e:forHtmlContent(role.description)}</option>

</c:forEach>

</select>

 

And without failure, the static analyzer flags the line with "${selected}" on it, indicating a CWE ID 80 on the line.

 

We have the same issue in a few other places with similar code, such as:

<option value="..." ${selectedId eq item.id ? 'selected' : ''} >

and these also get flagged (so at least there is consistency).

 

The scanner thinks that the tainted value from the DB (i.e. "role.id" or "item.id") is somehow part of the output, and thus a possible XSS issue. Now in the second example, I could see how maybe it could be confused -- after all, they are part of the same EL expression. However, in the first example, the generated Java code clearly outputs a static text string.

 

So, are we doing something wrong, or is this a bug in the static analyzer?

 


  • Robert (Community Member)

    Sorry, I forgot to follow up on this one.

     

    We did discuss it with via a Consultation, and it was investigated by the Ops team in more detail. It was confirmed by the Ops team to be a false positive from the scanning engine.

     

    We can work around it by wrapping the "${selected}" with encoding ( "${e:forHtmlAttribute(selected)}" ) as it has no ill effects on the data emitted into the HTML and keeps the scanning engine happy, but it shouldn't be strictly necessary.

    Expand Post
    Selected as Best
  • Hi @Robert (Community Member)​ ,

     

    I don't believe "selected" in the given example should be reported for CWE 80, but we'll need more information.

    I would recommend you contact our technical support team. Here's how you can log a case:

    1. Navigate to the upper right corner of any page in the Community, click on your user avatar.

    2. Select Contact Support from the drop-down menu.

     

    Please ensure you report:

    1. A URL to the Veracode Platform (starting with https://analysiscenter or https://web.analysiscenter) with where the results can be seen.
    2. The flaw identifier (first column on the left in the Triage Flaws view).

     

    Thank you,

    Boy Baukema

    Expand Post
    • Robert (Community Member)

      Sorry, I forgot to follow up on this one.

       

      We did discuss it with via a Consultation, and it was investigated by the Ops team in more detail. It was confirmed by the Ops team to be a false positive from the scanning engine.

       

      We can work around it by wrapping the "${selected}" with encoding ( "${e:forHtmlAttribute(selected)}" ) as it has no ill effects on the data emitted into the HTML and keeps the scanning engine happy, but it shouldn't be strictly necessary.

      Expand Post
      Selected as Best

Topics (5)

No articles found
Loading

Ask the Community

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