/* TEMPLATE GENERATED TESTCASE FILE Filename: CWE90_LDAP_Injection__Servlet_getCookiesServlet_71a.java Label Definition File: CWE90_LDAP_Injection__Servlet.label.xml Template File: sources-sink-71a.tmpl.java */ /* * @description * CWE: 90 LDAP Injection * BadSource: getCookiesServlet Read data from the first cookie * GoodSource: A hardcoded string * Sinks: * BadSink : unchecked data leads to LDAP injection * Flow Variant: 71 Data flow: data passed as an Object reference argument from one method to another in different classes in the same package * * */ package testcases.CWE90_LDAP_Injection; import testcasesupport.*; import javax.naming.*; import javax.naming.directory.*; import javax.servlet.http.*; import java.util.Hashtable; import java.io.IOException; import org.apache.commons.lang.StringEscapeUtils; import javax.servlet.http.*; import java.util.logging.Logger; public class CWE90_LDAP_Injection__Servlet_getCookiesServlet_71a extends AbstractTestCaseServlet { public void bad(HttpServletRequest request, HttpServletResponse response) throws Throwable { String data; Logger log_bad = Logger.getLogger("local-logger"); /* read parameter from cookie */ Cookie cookieSources[] = request.getCookies(); if (cookieSources != null) { data = cookieSources[0].getValue(); } else { data = null; } (new CWE90_LDAP_Injection__Servlet_getCookiesServlet_71b()).bad_sink((Object)data , request, response ); } public void good(HttpServletRequest request, HttpServletResponse response) throws Throwable { goodG2B(request, response); } /* goodG2B() - use goodsource and badsink */ private void goodG2B(HttpServletRequest request, HttpServletResponse response) throws Throwable { String data; java.util.logging.Logger log_good = java.util.logging.Logger.getLogger("local-logger"); /* FIX: Use a hardcoded string */ data = "foo"; (new CWE90_LDAP_Injection__Servlet_getCookiesServlet_71b()).goodG2B_sink((Object)data , request, response ); } /* Below is the main(). It is only used when building this testcase on its own for testing or for building a binary to use in testing binary analysis tools. It is not used when compiling all the testcases as one application, which is how source code analysis tools are tested. */ public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException { mainFromParent(args); } }