CWE-495 从公开方法中返回私有的数组类型数据域

admin 2021年12月16日15:50:33评论57 views字数 1777阅读5分55秒阅读模式

CWE-495 从公开方法中返回私有的数组类型数据域

Private Data Structure Returned From A Public Method

结构: Simple

Abstraction: Variant

状态: Draft

被利用可能性: unkown

基本描述

The product has a method that is declared public, but returns a reference to a private data structure, which could then be modified in unexpected ways.

相关缺陷

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

适用平台

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

常见的影响

范围 影响 注释
Integrity Modify Application Data The contents of the data structure can be modified from outside the intended scope.

可能的缓解方案

Implementation

策略:

Declare the method private.

Implementation

策略:

Clone the member data and keep an unmodified version of the data private to the object.

Implementation

策略:

Use public setter methods that govern how a private member can be modified.

示例代码

Here, a public method in a Java class returns a reference to a private array. Given that arrays in Java are mutable, any modifications made to the returned reference would be reflected in the original private array.

bad Java

private String[] colors;
public String[] getColors() {

return colors;

}

In this example, the Color class defines functions that return non-const references to private members (an array type and an integer type), which are then arbitrarily altered from outside the control of the class.

bad C++

class Color
{

private:

int[2] colorArray;
int colorValue;

public:

Color () : colorArray { 1, 2 }, colorValue (3) { };
int[2] & fa () { return colorArray; } // return reference to private array
int & fv () { return colorValue; } // return reference to private integer

};

int main ()
{

Color c;

c.fa () [1] = 42; // modifies private array element
c.fv () = 42; // modifies private int

return 0;

}

分类映射

映射的分类名 ImNode ID Fit Mapped Node Name
7 Pernicious Kingdoms Private Array-Typed Field Returned From A Public Method
Software Fault Patterns SFP23 Exposed Data

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

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2021年12月16日15:50:33
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   CWE-495 从公开方法中返回私有的数组类型数据域https://cn-sec.com/archives/613243.html

发表评论

匿名网友 填写信息