CRITICAL
Rule Definition
When a Servlet throws an exception, the default error response the Servlet container sends back to the user typically includes debugging information.
This information is of great value to an attacker. For example, a stack trace might show the attacker a malformed SQL query string, the type of database being used, and the version of the application container. This information enables the attacker to target known vulnerabilities in these components.
Remediation
Use of try-catch block is recommended.
Violation Code Sample
@WebServlet(name = "Hello", value = ["/hello"])
class Test123 : HttpServlet() {
@Throws(IOException::class) //Violation
override fun doGet(req: HttpServletRequest, res: HttpServletResponse) {
val ip: String = req.getRemoteAddr()
val addr: InetAddress = InetAddress.getByName(ip)
.
.
.
out.println("hello " + addr.getHostName())
}
}
Fixed Code Sample
@WebServlet(name = "Hello", value = ["/hello"])
class Test123 : HttpServlet() {
override fun doGet(req: HttpServletRequest, res: HttpServletResponse) {
try{ //Violation fixed
val ip: String = req.getRemoteAddr()
val addr: InetAddress = InetAddress.getByName(ip)
.
.
.
out.println("hello " + addr.getHostName())
}
catch(unknownhostexception uhex){
out.println("123")
.
.
}
}
}
Reference
http://cwe.mitre.org/data/definitions/600.html
Related Technologies
Technical Criterion
CWE-703 - Improper Check or Handling of Exceptional Conditions
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.