Skip to content

Commit 9eb8ec7

Browse files
committed
Create a separate file for EJB check
1 parent 40df01d commit 9eb8ec7

File tree

4 files changed

+62
-3
lines changed

4 files changed

+62
-3
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
public class EJBMain implements SessionBean {
2+
/**
3+
* Create the session bean (empty implementation)
4+
*/
5+
public void ejbCreate() throws javax.ejb.CreateException {
6+
System.out.println("ServiceBean:ejbCreate()");
7+
}
8+
9+
public void ejbActivate() throws javax.ejb.EJBException, java.rmi.RemoteException {
10+
}
11+
12+
public void ejbPassivate() throws javax.ejb.EJBException, java.rmi.RemoteException {
13+
}
14+
15+
public void ejbRemove() throws javax.ejb.EJBException, java.rmi.RemoteException {
16+
}
17+
18+
public void setSessionContext(SessionContext parm1) throws javax.ejb.EJBException, java.rmi.RemoteException {
19+
}
20+
21+
public String doService() {
22+
return null;
23+
}
24+
25+
// BAD - Implement a main method in session bean.
26+
public static void main(String[] args) throws Exception {
27+
ServiceBean b = new ServiceBean();
28+
b.doService();
29+
}
30+
31+
// GOOD - Not to have a main method in session bean.
32+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE qhelp PUBLIC "-//Semmle//qhelp//EN" "qhelp.dtd">
2+
<qhelp>
3+
4+
<overview>
5+
<p>Debug code can create unintended entry points in a deployed Java EE web application therefore should never make into production. There is no reason to have a main method in a Java EE web application. Having a main method in the Java EE application increases the attack surface that an attacker can exploit to attack the application logic.</p>
6+
</overview>
7+
8+
<recommendation>
9+
<p>Remove the main method from enterprise beans.</p>
10+
</recommendation>
11+
12+
<example>
13+
<p>The following example shows two ways of implementing enterprise beans. In the 'BAD' case, a main method is implemented. In the 'GOOD' case, no main method is implemented.</p>
14+
<sample src="EJBMain.java" />
15+
</example>
16+
17+
<references>
18+
<li>
19+
SonarSource:
20+
<a href="https://rules.sonarsource.com/java/tag/owasp/RSPEC-2653">Web applications should not have a "main" method</a>
21+
</li>
22+
<li>
23+
Carnegie Mellon University:
24+
<a href="https://wiki.sei.cmu.edu/confluence/display/java/ENV06-J.+Production+code+must+not+contain+debugging+entry+points">ENV06-J. Production code must not contain debugging entry points</a>
25+
</li>
26+
</references>
27+
</qhelp>

java/ql/src/experimental/Security/CWE/CWE-489/ServletMain.java renamed to java/ql/src/experimental/Security/CWE/CWE-489/WebComponentMain.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
public class ServletMain implements Servlet {
1+
public class WebComponentMain implements Servlet {
22
// BAD - Implement a main method in servlet.
33
public static void main(String[] args) throws Exception {
44
// Connect to my server

java/ql/src/experimental/Security/CWE/CWE-489/ServletMain.qhelp renamed to java/ql/src/experimental/Security/CWE/CWE-489/WebComponentMain.qhelp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
</overview>
77

88
<recommendation>
9-
<p>Remove the main method from web components including servlets, filters, and listeners, as well as enterprise beans.</p>
9+
<p>Remove the main method from web components including servlets, filters, and listeners.</p>
1010
</recommendation>
1111

1212
<example>
1313
<p>The following example shows two ways of implementing web components. In the 'BAD' case, a main method is implemented. In the 'GOOD' case, no main method is implemented.</p>
14-
<sample src="ServletMain.java" />
14+
<sample src="WebComponentMain.java" />
1515
</example>
1616

1717
<references>

0 commit comments

Comments
 (0)