Using unsanitized untrusted data in an external API can cause a variety of security issues. This query reports all uses of external APIs with untrusted data for review. This query has a deliberately low true positive rate, and is designed to help security reviews for the application, as well as helping identify external APIs that should be modeled as either taint steps, or sinks for specific problems.

An external API is defined as a method call to a method which is not defined in the source code, not overridden in the source code, and is not modeled as a taint step in the default taint library. External APIs may be from the Java standard library, third party dependencies or from internal dependencies. The query will report uses of untrusted data in either the qualifier or as one of the arguments of external APIs.

For each result:

Otherwise, the result is likely uninteresting. Custom versions of this query can extend the SafeExternalAPIMethod class to exclude known safe external APIs from future analysis.

In this first example, a request parameter is read from HttpServletRequest and then ultimately used in a call to the HttpServletResponse.sendError external API:

This is an XSS sink. The XSS query should therefore be reviewed to confirm that this sink is appropriately modeled, and if it is, to confirm that the query reports this particular result, or that the result is false positive due to some existing sanitization.

In this second example, again a request parameter is read from HttpServletRequest.

If the query reported the call to StringBuilder.append on Line 7, this would suggest that this external API is not currently modeled as a taint step in the taint tracking library. The next step would be to model this as taint step, then re-run the query to determine what additional results might be found. In this example, it seems likely that the result of the StringBuilder will be executed as an SQL query, potentially leading to an SQL injection vulnerability.

Note that both examples are correctly handled with the standard taint tracking library and XSS query.