☰
  • 首页
  • 规则分类
  • 项目介绍
search
•••

公共成员或全局对象不应记录敏感数据

1.4 ID_sensitiveName
目录 › next › previous

公共成员、全局对象可被外部代码引用,如果存有敏感数据则可能会被误用或窃取。

示例:

extern string password;   // Non-compliant

struct A {
    string username;
    string password;      // Non-compliant
};

至少应将相关成员改为 private:

class A {
public:
    ....                  // Interfaces for accessing passwords safely
private:
    string username;
    string password;      // Compliant
};

敏感数据最好对引用者完全隐藏,避免被恶意分析、复制或序列化。使数据与接口进一步分离,可参见“Pimpl idiom”等模式。

参考

CWE-766
Copyright©2024 360 Security Technology Inc., Licensed under the Apache-2.0 license.