CWE-111: Direct Use of Unsafe JNI
CWE版本: 4.18
更新日期: 2025-09-09
弱点描述
When a Java application uses the Java Native Interface (JNI) to call code written in another programming language, it can expose the application to weaknesses in that code, even if those weaknesses cannot occur in Java.
扩展描述
Many safety features that programmers may take for granted do not apply for native code, so you must carefully review all such code for potential problems. The languages used to implement native code may be more susceptible to buffer overflows and other attacks. Native code is unprotected by the security features enforced by the runtime environment, such as strong typing and array bounds checking.
常见后果
影响范围: Access Control
技术影响: Bypass Protection Mechanism
潜在缓解措施
阶段: Implementation
描述: Implement error handling around the JNI call.
阶段: Implementation
策略: Refactoring
描述: Do not use JNI calls if you don't trust the native library.
阶段: Implementation
策略: Refactoring
描述: Be reluctant to use JNI calls. A Java API equivalent may exist.
检测方法
方法: Automated Static Analysis
Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)
有效性: High
引入模式
| 阶段 | 说明 |
|---|---|
| Implementation | - |
适用平台
编程语言
分类映射
| 分类名称 | 条目ID | 条目名称 | 映射适配度 |
|---|---|---|---|
| 7 Pernicious Kingdoms | - | Unsafe JNI | - |
| The CERT Oracle Secure Coding Standard for Java (2011) | SEC08-J | Define wrappers around native methods | - |
| SEI CERT Oracle Coding Standard for Java | JNI01-J | Safely invoke standard APIs that perform tasks using the immediate caller's class loader instance (loadLibrary) | - |
| SEI CERT Oracle Coding Standard for Java | JNI00-J | Define wrappers around native methods | Imprecise |
| Software Fault Patterns | SFP3 | Use of an improper API | - |