60 lines
1.9 KiB
Plaintext
60 lines
1.9 KiB
Plaintext
Even though the signatures for methods in a servlet include ``++throws IOException, ServletException++``, it's a bad idea to let such exceptions be thrown. Failure to catch exceptions in a servlet could leave a system in a vulnerable state, possibly resulting in denial-of-service attacks, or the exposure of sensitive information because when a servlet throws an exception, the servlet container typically sends debugging information back to the user. And that information could be very valuable to an attacker.
|
|
|
|
|
|
This rule checks all exceptions in methods named "do*" are explicitly handled in servlet classes.
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
[source,java]
|
|
----
|
|
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
|
throws IOException, ServletException {
|
|
String ip = request.getRemoteAddr();
|
|
InetAddress addr = InetAddress.getByName(ip); // Noncompliant; getByName(String) throws UnknownHostException
|
|
//...
|
|
}
|
|
----
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
[source,java]
|
|
----
|
|
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
|
throws IOException, ServletException {
|
|
try {
|
|
String ip = request.getRemoteAddr();
|
|
InetAddress addr = InetAddress.getByName(ip);
|
|
//...
|
|
}
|
|
catch (UnknownHostException uhex) {
|
|
//...
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
== See
|
|
|
|
* https://www.owasp.org/www-project-top-ten/2017/A3_2017-Sensitive_Data_Exposure[OWASP Top 10 2017 Category A3] - Sensitive Data Exposure
|
|
* https://cwe.mitre.org/data/definitions/600[MITRE, CWE-600] - Uncaught Exception in Servlet
|
|
* https://wiki.sei.cmu.edu/confluence/x/-zZGBQ[CERT, ERR01-J.] - Do not allow exceptions to expose sensitive information
|
|
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::message.adoc[]
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::comments-and-links.adoc[]
|
|
endif::env-github,rspecator-view[]
|