CWE-382 J2EE不安全实践:使用System.exit()

J2EE Bad Practices: Use of System.exit()

结构: Simple

Abstraction: Variant

状态: Draft

被利用可能性: unkown

基本描述

A J2EE application uses System.exit(), which also shuts down its container.

扩展描述

It is never a good idea for a web application to attempt to shut down the application container. Access to a function that can shut down the application is an avenue for Denial of Service (DoS) attacks.

相关缺陷

  • cwe_Nature: ChildOf cwe_CWE_ID: 705 cwe_View_ID: 1000 cwe_Ordinal: Primary

适用平台

Language: {'cwe_Name': 'Java', 'cwe_Prevalence': 'Undetermined'}

常见的影响

范围 影响 注释
Availability DoS: Crash, Exit, or Restart

可能的缓解方案

Architecture and Design

策略: Separation of Privilege

The shutdown function should be a privileged function available only to a properly authorized administrative user

Implementation

策略:

Web applications should not call methods that cause the virtual machine to exit, such as System.exit()

Implementation

策略:

Web applications should also not throw any Throwables to the application server as this may adversely affect the container.

Implementation

策略:

Non-web applications may have a main() method that contains a System.exit(), but generally should not call System.exit() from other locations in the code

示例代码

Included in the doPost() method defined below is a call to System.exit() in the event of a specific exception.

bad Java

Public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
...
} catch (ApplicationSpecificException ase) {
logger.error("Caught: " + ase.toString());
System.exit(1);
}
}

分类映射

映射的分类名 ImNode ID Fit Mapped Node Name
7 Pernicious Kingdoms J2EE Bad Practices: System.exit()
OWASP Top Ten 2004 A9 CWE More Specific Denial of Service
The CERT Oracle Secure Coding Standard for Java (2011) ERR09-J Do not allow untrusted code to terminate the JVM
Software Fault Patterns SFP3 Use of an improper API