CWE-500 公开静态字段没有标记为Final

admin 2021年12月16日16:45:46评论62 views字数 1995阅读6分39秒阅读模式

CWE-500 公开静态字段没有标记为Final

Public Static Field Not Marked Final

结构: Simple

Abstraction: Variant

状态: Draft

被利用可能性: High

基本描述

An object contains a public static field that is not marked final, which might allow it to be modified in unexpected ways.

扩展描述

Public static variables can be read without an accessor and changed without a mutator by any classes in the application.

相关缺陷

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

  • cwe_Nature: ChildOf cwe_CWE_ID: 493 cwe_View_ID: 699 cwe_Ordinal: Primary

适用平台

Language: [{'cwe_Name': 'C++', 'cwe_Prevalence': 'Undetermined'}, {'cwe_Name': 'Java', 'cwe_Prevalence': 'Undetermined'}]

常见的影响

范围 影响 注释
Integrity Modify Application Data The object could potentially be tampered with.
Confidentiality Read Application Data The object could potentially allow the object to be read.

可能的缓解方案

Architecture and Design

策略:

Clearly identify the scope for all critical data elements, including whether they should be regarded as static.

Implementation

策略:

Make any static fields private and constant.
A constant field is denoted by the keyword 'const' in C/C++ and ' final' in Java

示例代码

The following examples use of a public static String variable to contain the name of a property/configuration file for the application.

bad C++

class SomeAppClass {


public:

static string appPropertiesConfigFile = "app/properties.config";

...

}

bad Java

public class SomeAppClass {


public static String appPropertiesFile = "app/Application.properties";
...

}

Having a public static variable that is not marked final (constant) may allow the variable to the altered in a way not intended by the application. In this example the String variable can be modified to indicate a different on nonexistent properties file which could cause the application to crash or caused unexpected behavior.

good C++

class SomeAppClass {


public:

static const string appPropertiesConfigFile = "app/properties.config";

...

}

good Java

public class SomeAppClass {


public static final String appPropertiesFile = "app/Application.properties";
...

}

分类映射

映射的分类名 ImNode ID Fit Mapped Node Name
CLASP Overflow of static internal buffer
The CERT Oracle Secure Coding Standard for Java (2011) OBJ10-J Do not use public static nonfinal variables
Software Fault Patterns SFP28 Unexpected access points

文章来源于互联网:scap中文网

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2021年12月16日16:45:46
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   CWE-500 公开静态字段没有标记为Finalhttp://cn-sec.com/archives/612979.html

发表评论

匿名网友 填写信息