mirror of
https://github.com/github/codeql.git
synced 2026-04-27 17:55:19 +02:00
Merge pull request #5102 from luchua-bc/java/main-method-in-servlet
Java: CWE-489 Query to detect main() method in servlets
This commit is contained in:
@@ -0,0 +1 @@
|
||||
| ServiceBean.java:55:24:55:27 | main | Java EE application has a main method. |
|
||||
@@ -0,0 +1,59 @@
|
||||
import javax.ejb.SessionBean;
|
||||
import javax.ejb.EJBException;
|
||||
import java.rmi.RemoteException;
|
||||
import javax.ejb.SessionContext;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
|
||||
public class ServiceBean implements SessionBean {
|
||||
|
||||
protected SessionContext ctx;
|
||||
|
||||
private String _serviceName;
|
||||
|
||||
/**
|
||||
* Create the session bean (empty implementation)
|
||||
*/
|
||||
public void ejbCreate() throws javax.ejb.CreateException {
|
||||
System.out.println("ServiceBean:ejbCreate()");
|
||||
}
|
||||
|
||||
public void ejbActivate() throws javax.ejb.EJBException, java.rmi.RemoteException {
|
||||
}
|
||||
|
||||
public void ejbPassivate() throws javax.ejb.EJBException, java.rmi.RemoteException {
|
||||
}
|
||||
|
||||
public void ejbRemove() throws javax.ejb.EJBException, java.rmi.RemoteException {
|
||||
}
|
||||
|
||||
public void setSessionContext(SessionContext parm1) throws javax.ejb.EJBException, java.rmi.RemoteException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get service name
|
||||
* @return service name
|
||||
*/
|
||||
public String getServiceName() {
|
||||
return _serviceName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set service name
|
||||
* @param serviceName the service name
|
||||
*/
|
||||
public void setServiceName(String serviceName) {
|
||||
_serviceName = serviceName;
|
||||
}
|
||||
|
||||
/** Do service (no implementation) */
|
||||
public String doService() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Local unit testing code */
|
||||
public static void main(String[] args) throws Exception {
|
||||
ServiceBean b = new ServiceBean();
|
||||
b.doService();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
experimental/Security/CWE/CWE-489/EJBMain.ql
|
||||
@@ -0,0 +1,25 @@
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
import java.net.URL;
|
||||
|
||||
public class ServletContextListenerMain implements ServletContextListener {
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent sce) {
|
||||
System.out.println("listener starts to work!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent sce) {
|
||||
System.out.println("listener stopped!");
|
||||
}
|
||||
|
||||
// BAD - Implement a main method in servlet listener.
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
URL url = new URL("https://www.example.com");
|
||||
url.openConnection();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
| ServletContextListenerMain.java:17:21:17:24 | main | Web application has a main method. |
|
||||
| ServletMain.java:28:21:28:24 | main | Web application has a main method. |
|
||||
@@ -0,0 +1,33 @@
|
||||
import javax.servlet.Servlet;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletConfig;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
public class ServletMain implements Servlet {
|
||||
public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
|
||||
}
|
||||
|
||||
public void init(ServletConfig servletConfig) throws ServletException {
|
||||
}
|
||||
|
||||
public ServletConfig getServletConfig() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getServletInfo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
// BAD - Implement a main method in servlet.
|
||||
public static void main(String[] args) throws Exception {
|
||||
// Connect to my server
|
||||
URL url = new URL("https://www.example.com");
|
||||
url.openConnection();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
experimental/Security/CWE/CWE-489/WebComponentMain.ql
|
||||
@@ -0,0 +1 @@
|
||||
// semmle-extractor-options: --javac-args -cp ${testdir}/../../../../stubs/servlet-api-2.4:${testdir}/../../../../stubs/ejb-3.2
|
||||
Reference in New Issue
Block a user