界: Code Quality

代码质量不佳会导致不可预测的行为。对于用户来说,通常表现为可用性差。对于攻击者来说,提供了以意外方式对系统施加压力的机会。

93 个项目已找到
弱点
Abstract
检测到 PendingIntent,其标记值设置为 FLAG_MUTABLE。使用标记值 FLAG_MUTABLE 创建的待定意图很容易在下游设置未指定的 Intent 字段,这样会修改 Intent 的容量并使系统容易受到攻击。
Explanation
允许在创建 PendingIntent 后修改其底层 Intent 可能会使系统容易受到攻击。这主要取决于底层 Intent 的整体功能。在大多数情况下,最佳实践是通过将 PendingIntent 标记设置为 FLAG_IMMUTABLE 来防止发生潜在问题。

示例 1:以下代码包含使用标记值 FLAG_MUTABLE 创建的 PendingIntent


...
val intent_flag_mut = Intent(Intent.ACTION_GTALK_SERVICE_DISCONNECTED, Uri.EMPTY, this, DownloadService::class.java)
val flag_mut = PendingIntent.FLAG_MUTABLE

val pi_flagmutable = PendingIntent.getService(
this,
0,
intent_flag_mut,
flag_mut
)
...
References
[1] Remediation for Implicit PendingIntent Vulnerability
[2] Standards Mapping - CIS Azure Kubernetes Service Benchmark 1
[3] Standards Mapping - CIS Microsoft Azure Foundations Benchmark complete
[4] Standards Mapping - CIS Amazon Elastic Kubernetes Service Benchmark 4
[5] Standards Mapping - CIS Amazon Web Services Foundations Benchmark 1
[6] Standards Mapping - CIS Google Cloud Computing Platform Benchmark partial
[7] Standards Mapping - CIS Google Kubernetes Engine Benchmark integrity
[8] Standards Mapping - CIS Kubernetes Benchmark partial
[9] Standards Mapping - Common Weakness Enumeration CWE ID 99
[10] Standards Mapping - DISA Control Correlation Identifier Version 2 CCI-001094
[11] Standards Mapping - General Data Protection Regulation (GDPR) Indirect Access to Sensitive Data
[12] Standards Mapping - NIST Special Publication 800-53 Revision 4 SC-5 Denial of Service Protection (P1)
[13] Standards Mapping - NIST Special Publication 800-53 Revision 5 SC-5 Denial of Service Protection
[14] Standards Mapping - OWASP Top 10 2004 A9 Application Denial of Service
[15] Standards Mapping - Payment Card Industry Data Security Standard Version 1.1 Requirement 6.5.1
[16] Standards Mapping - Payment Card Industry Data Security Standard Version 1.2 Requirement 6.3.1.1, Requirement 6.5.4
[17] Standards Mapping - Payment Card Industry Data Security Standard Version 2.0 Requirement 6.5.8
[18] Standards Mapping - Payment Card Industry Data Security Standard Version 3.0 Requirement 6.5.8
[19] Standards Mapping - Payment Card Industry Data Security Standard Version 3.2 Requirement 6.5.8
[20] Standards Mapping - Payment Card Industry Data Security Standard Version 3.2.1 Requirement 6.5.8
[21] Standards Mapping - Payment Card Industry Data Security Standard Version 3.1 Requirement 6.5.8
[22] Standards Mapping - Payment Card Industry Data Security Standard Version 4.0 Requirement 6.2.4
[23] Standards Mapping - Security Technical Implementation Guide Version 3.1 APP6080 CAT II
[24] Standards Mapping - Security Technical Implementation Guide Version 3.4 APP6080 CAT II
[25] Standards Mapping - Security Technical Implementation Guide Version 3.5 APP6080 CAT II
[26] Standards Mapping - Security Technical Implementation Guide Version 3.6 APP6080 CAT II
[27] Standards Mapping - Security Technical Implementation Guide Version 3.7 APP6080 CAT II
[28] Standards Mapping - Security Technical Implementation Guide Version 3.9 APP6080 CAT II
[29] Standards Mapping - Security Technical Implementation Guide Version 3.10 APP6080 CAT II
[30] Standards Mapping - Security Technical Implementation Guide Version 4.1 APSC-DV-002400 CAT II
[31] Standards Mapping - Security Technical Implementation Guide Version 4.2 APSC-DV-002400 CAT II
[32] Standards Mapping - Security Technical Implementation Guide Version 4.3 APSC-DV-002400 CAT II
[33] Standards Mapping - Security Technical Implementation Guide Version 4.4 APSC-DV-002400 CAT II
[34] Standards Mapping - Security Technical Implementation Guide Version 4.5 APSC-DV-002400 CAT II
[35] Standards Mapping - Security Technical Implementation Guide Version 4.6 APSC-DV-002400 CAT II
[36] Standards Mapping - Security Technical Implementation Guide Version 4.7 APSC-DV-002400 CAT II
[37] Standards Mapping - Security Technical Implementation Guide Version 4.8 APSC-DV-002400 CAT II
[38] Standards Mapping - Security Technical Implementation Guide Version 4.9 APSC-DV-002400 CAT II
[39] Standards Mapping - Security Technical Implementation Guide Version 4.10 APSC-DV-002400 CAT II
[40] Standards Mapping - Security Technical Implementation Guide Version 4.11 APSC-DV-002400 CAT II
[41] Standards Mapping - Security Technical Implementation Guide Version 5.1 APSC-DV-002400 CAT II
[42] Standards Mapping - Security Technical Implementation Guide Version 5.2 APSC-DV-002400 CAT II
[43] Standards Mapping - Security Technical Implementation Guide Version 5.3 APSC-DV-002400 CAT II
[44] Standards Mapping - Web Application Security Consortium Version 2.00 Denial of Service (WASC-10)
[45] Standards Mapping - Web Application Security Consortium 24 + 2 Denial of Service
desc.controlflow.java.intent_manipulation_mutable_pending_intent
Abstract
内存已分配,但永远不会释放。
Explanation
Memory leak 的产生有两个常见(有时候这两个原因会同时发生作用)原因:

- 错误状况及其他异常情况。

— 不清楚由程序的哪一部分负责释放内存。

大多数 memory leak 会导致常规软件可靠性问题,但如果攻击者能够蓄意触发 memory leak,他就可能会通过引发程序崩溃来发起一个 denial of service 攻击,或者是利用因内存低的情况 [1] 所引发的其他意外的程序行为。

例 1:如果调用 read() 后没有返回预期的字节数,以下 C 函数将会泄漏已分配的内存块的信息:


char* getBlock(int fd) {
char* buf = (char*) malloc(BLOCK_SIZE);
if (!buf) {
return NULL;
}
if (read(fd, buf, BLOCK_SIZE) != BLOCK_SIZE) {
return NULL;
}
return buf;
}
References
[1] J. Whittaker and H. Thompson How to Break Software Security Addison Wesley
desc.controlflow.cpp.memory_leak
Abstract
内存会得到分配但从不会被释放。
Explanation
内存泄漏有两个共通而有时部分相同的原因:

- 错误状况及其他异常情况。

- 未明确程序的哪一部份负责释放内存。

大部分内存泄漏只会导致常规软件可靠性问题,但如果攻击者可能有意触发内存泄漏,该攻击者就有可能发起 Denial of Service 攻击(通过引发程序崩溃的方式)或利用由内存较低情况 [1] 引起的其他意外程序行为。

示例 1:如果发生错误,以下 Micro Focus COBOL 程序会泄漏已分配内存块:


CALL "CBL_ALLOC_MEM"
USING mem-pointer
BY VALUE mem-size
BY VALUE flags
RETURNING status-code
END-CALL

IF status-code NOT = 0
DISPLAY "Error!"
GOBACK
ELSE
SET ADDRESS OF mem TO mem-pointer
END-IF

PERFORM write-data
IF ws-status-code NOT = 0
DISPLAY "Error!"
GOBACK
ELSE
DISPLAY "Success!"
END-IF

CALL "CBL_FREE_MEM"
USING BY VALUE mem-pointer
RETURNING status-code
END-CALL

GOBACK
.
References
[1] J. Whittaker and H. Thompson How to Break Software Security Addison Wesley
desc.controlflow.cobol.memory_leak
Abstract
对象为成员变量分配了内存,但在其 dealloc() 方法中未能将其释放。
Explanation
Memory leak 的产生有两个常见(有时候这两个原因会同时发生作用)原因:

- 错误状况及其他异常情况。

— 不清楚由程序的哪一部分负责释放内存。

大多数 memory leak 会导致常规软件可靠性问题,但如果攻击者能够蓄意触发 memory leak,他就可能会通过引发程序崩溃来发起一个 denial of service 攻击,或者是利用因内存低的情况 [1] 所引发的其他意外的程序行为。

例 1:该 Objective-C 对象通过 init() 方法分配内存,但无法通过 deallocate() 方法将其释放,导致 memory leak:


- (void)init
{
myVar = [NSString alloc] init];
...
}

- (void)dealloc
{
[otherVar release];
}
References
[1] J. Whittaker and H. Thompson How to Break Software Security Addison Wesley
desc.structural.objc.memory_leak
Abstract
该程序会调整分配的内存块的大小。如果调整大小时失败,初始块将会泄漏。
Explanation
Memory leak 的产生有两个常见(有时候这两个原因会同时发生作用)原因:

- 错误状况及其他异常情况。

— 不清楚由程序的哪一部分负责释放内存。

大多数 memory leak 会导致常规软件可靠性问题,但如果攻击者能够蓄意触发 memory leak,他就可能会通过引发程序崩溃来发起一个 denial of service 攻击,或者是利用因内存低的情况 [1] 所引发的其他意外的程序行为。

例 1:如果 realloc() 调用无法调整初始分配的大小,以下 C 函数会泄漏一块分配的内存。


char* getBlocks(int fd) {
int amt;
int request = BLOCK_SIZE;
char* buf = (char*) malloc(BLOCK_SIZE + 1);
if (!buf) {
goto ERR;
}
amt = read(fd, buf, request);
while ((amt % BLOCK_SIZE) != 0) {
if (amt < request) {
goto ERR;
}
request = request + BLOCK_SIZE;
buf = realloc(buf, request);
if (!buf) {
goto ERR;
}
amt = read(fd, buf, request);
}

return buf;

ERR:
if (buf) {
free(buf);
}
return NULL;
}
References
[1] J. Whittaker and H. Thompson How to Break Software Security Addison Wesley
[2] Standards Mapping - CIS Azure Kubernetes Service Benchmark 1
[3] Standards Mapping - CIS Amazon Elastic Kubernetes Service Benchmark 5
[4] Standards Mapping - CIS Amazon Web Services Foundations Benchmark 2
[5] Standards Mapping - CIS Google Kubernetes Engine Benchmark normal
[6] Standards Mapping - Common Weakness Enumeration CWE ID 401
[7] Standards Mapping - DISA Control Correlation Identifier Version 2 CCI-001094
[8] Standards Mapping - General Data Protection Regulation (GDPR) Indirect Access to Sensitive Data
[9] Standards Mapping - Motor Industry Software Reliability Association (MISRA) C Guidelines 2012 Rule 21.3
[10] Standards Mapping - Motor Industry Software Reliability Association (MISRA) C++ Guidelines 2008 Rule 18-4-1
[11] Standards Mapping - NIST Special Publication 800-53 Revision 4 SC-5 Denial of Service Protection (P1)
[12] Standards Mapping - NIST Special Publication 800-53 Revision 5 SC-5 Denial of Service Protection
[13] Standards Mapping - OWASP Top 10 2004 A9 Application Denial of Service
[14] Standards Mapping - OWASP Mobile Application Security Verification Standard 2.0 MASVS-STORAGE-2
[15] Standards Mapping - Payment Card Industry Data Security Standard Version 1.1 Requirement 6.5.9
[16] Standards Mapping - Security Technical Implementation Guide Version 3.1 APP6080 CAT II
[17] Standards Mapping - Security Technical Implementation Guide Version 3.4 APP6080 CAT II
[18] Standards Mapping - Security Technical Implementation Guide Version 3.5 APP6080 CAT II
[19] Standards Mapping - Security Technical Implementation Guide Version 3.6 APP6080 CAT II
[20] Standards Mapping - Security Technical Implementation Guide Version 3.7 APP6080 CAT II
[21] Standards Mapping - Security Technical Implementation Guide Version 3.9 APP6080 CAT II
[22] Standards Mapping - Security Technical Implementation Guide Version 3.10 APP6080 CAT II
[23] Standards Mapping - Security Technical Implementation Guide Version 4.1 APSC-DV-002400 CAT II
[24] Standards Mapping - Security Technical Implementation Guide Version 4.2 APSC-DV-002400 CAT II
[25] Standards Mapping - Security Technical Implementation Guide Version 4.3 APSC-DV-002400 CAT II
[26] Standards Mapping - Security Technical Implementation Guide Version 4.4 APSC-DV-002400 CAT II
[27] Standards Mapping - Security Technical Implementation Guide Version 4.5 APSC-DV-002400 CAT II
[28] Standards Mapping - Security Technical Implementation Guide Version 4.6 APSC-DV-002400 CAT II
[29] Standards Mapping - Security Technical Implementation Guide Version 4.7 APSC-DV-002400 CAT II
[30] Standards Mapping - Security Technical Implementation Guide Version 4.8 APSC-DV-002400 CAT II
[31] Standards Mapping - Security Technical Implementation Guide Version 4.9 APSC-DV-002400 CAT II
[32] Standards Mapping - Security Technical Implementation Guide Version 4.10 APSC-DV-002400 CAT II
[33] Standards Mapping - Security Technical Implementation Guide Version 4.11 APSC-DV-002400 CAT II
[34] Standards Mapping - Security Technical Implementation Guide Version 5.1 APSC-DV-002400 CAT II
[35] Standards Mapping - Security Technical Implementation Guide Version 5.2 APSC-DV-002400 CAT II
[36] Standards Mapping - Security Technical Implementation Guide Version 5.3 APSC-DV-002400 CAT II
[37] Standards Mapping - Web Application Security Consortium Version 2.00 Denial of Service (WASC-10)
[38] Standards Mapping - Web Application Security Consortium 24 + 2 Denial of Service
desc.controlflow.cpp.memory_leak_reallocation
Abstract
程序将调整已分配内存块的大小。如果调整大小失败,则原始块会泄漏。
Explanation
内存泄漏有两个共通而有时部分相同的原因:

- 错误状况及其他异常情况。

- 未明确程序的哪一部份负责释放内存。

大部分内存泄漏只会导致常规软件可靠性问题,但如果攻击者可能有意触发内存泄漏,该攻击者就有可能发起 Denial of Service 攻击(通过引发程序崩溃的方式)或利用由内存较低情况 [1] 引起的其他意外程序行为。

示例 1:如果调用 realloc() 无法调整原始分配的大小,则以下 Micro Focus COBOL 程序会泄漏已分配内存块。


CALL "malloc" USING
BY VALUE mem-size
RETURNING mem-pointer
END-CALL

ADD 1000 TO mem-size

CALL "realloc" USING
BY VALUE mem-pointer
BY VALUE mem-size
RETURNING mem-pointer
END-CALL

IF mem-pointer <> null
CALL "free" USING
BY VALUE mem-pointer
END-CALL
END-IF
References
[1] J. Whittaker and H. Thompson How to Break Software Security Addison Wesley
[2] Standards Mapping - CIS Azure Kubernetes Service Benchmark 1
[3] Standards Mapping - CIS Amazon Elastic Kubernetes Service Benchmark 5
[4] Standards Mapping - CIS Amazon Web Services Foundations Benchmark 2
[5] Standards Mapping - CIS Google Kubernetes Engine Benchmark normal
[6] Standards Mapping - Common Weakness Enumeration CWE ID 401
[7] Standards Mapping - DISA Control Correlation Identifier Version 2 CCI-001094
[8] Standards Mapping - General Data Protection Regulation (GDPR) Indirect Access to Sensitive Data
[9] Standards Mapping - Motor Industry Software Reliability Association (MISRA) C Guidelines 2012 Rule 21.3
[10] Standards Mapping - Motor Industry Software Reliability Association (MISRA) C++ Guidelines 2008 Rule 18-4-1
[11] Standards Mapping - NIST Special Publication 800-53 Revision 4 SC-5 Denial of Service Protection (P1)
[12] Standards Mapping - NIST Special Publication 800-53 Revision 5 SC-5 Denial of Service Protection
[13] Standards Mapping - OWASP Top 10 2004 A9 Application Denial of Service
[14] Standards Mapping - OWASP Mobile Application Security Verification Standard 2.0 MASVS-STORAGE-2
[15] Standards Mapping - Payment Card Industry Data Security Standard Version 1.1 Requirement 6.5.9
[16] Standards Mapping - Security Technical Implementation Guide Version 3.1 APP6080 CAT II
[17] Standards Mapping - Security Technical Implementation Guide Version 3.4 APP6080 CAT II
[18] Standards Mapping - Security Technical Implementation Guide Version 3.5 APP6080 CAT II
[19] Standards Mapping - Security Technical Implementation Guide Version 3.6 APP6080 CAT II
[20] Standards Mapping - Security Technical Implementation Guide Version 3.7 APP6080 CAT II
[21] Standards Mapping - Security Technical Implementation Guide Version 3.9 APP6080 CAT II
[22] Standards Mapping - Security Technical Implementation Guide Version 3.10 APP6080 CAT II
[23] Standards Mapping - Security Technical Implementation Guide Version 4.1 APSC-DV-002400 CAT II
[24] Standards Mapping - Security Technical Implementation Guide Version 4.2 APSC-DV-002400 CAT II
[25] Standards Mapping - Security Technical Implementation Guide Version 4.3 APSC-DV-002400 CAT II
[26] Standards Mapping - Security Technical Implementation Guide Version 4.4 APSC-DV-002400 CAT II
[27] Standards Mapping - Security Technical Implementation Guide Version 4.5 APSC-DV-002400 CAT II
[28] Standards Mapping - Security Technical Implementation Guide Version 4.6 APSC-DV-002400 CAT II
[29] Standards Mapping - Security Technical Implementation Guide Version 4.7 APSC-DV-002400 CAT II
[30] Standards Mapping - Security Technical Implementation Guide Version 4.8 APSC-DV-002400 CAT II
[31] Standards Mapping - Security Technical Implementation Guide Version 4.9 APSC-DV-002400 CAT II
[32] Standards Mapping - Security Technical Implementation Guide Version 4.10 APSC-DV-002400 CAT II
[33] Standards Mapping - Security Technical Implementation Guide Version 4.11 APSC-DV-002400 CAT II
[34] Standards Mapping - Security Technical Implementation Guide Version 5.1 APSC-DV-002400 CAT II
[35] Standards Mapping - Security Technical Implementation Guide Version 5.2 APSC-DV-002400 CAT II
[36] Standards Mapping - Security Technical Implementation Guide Version 5.3 APSC-DV-002400 CAT II
[37] Standards Mapping - Web Application Security Consortium Version 2.00 Denial of Service (WASC-10)
[38] Standards Mapping - Web Application Security Consortium 24 + 2 Denial of Service
desc.controlflow.cobol.memory_leak_reallocation
Abstract
程序可能会间接引用一个 null 指针,从而引发 NullException
Explanation
null 指针错误通常是由于违反一个或多个程序员假设而造成的。

大多数 null 指针问题会导致一般软件可靠性问题,但如果攻击者可能有意触发 null 指针间接引用,他们可以使用生成的异常绕过安全逻辑或使应用程序显示调试信息,这些信息在规划后续攻击时十分有用。

示例 1:在以下代码中,程序员假定系统始终会定义一个名为“cmd”的属性。如果攻击者可以控制程序的环境,从而使“cmd”处于未定义状态,则它就会在尝试调用 Trim() 方法时抛出一个 null 指针异常。


string cmd = null;
...
cmd = Environment.GetEnvironmentVariable("cmd");
cmd = cmd.Trim();
desc.controlflow.dotnet.null_dereference
Abstract
该程序可能会间接引用一个 null 指针,从而造成分段故障。
Explanation
如果不符合程序员的一个或多个假设,则通常会出现 null 指针异常。此问题至少有三种类型:check-after-dereference、dereference-after-check 和 dereference-after-store。如果程序在检查可能为 null 的指针是否为 null 之前间接引用该指针,则会发生 check-after-dereference 错误。如果程序明确检查过 null,并确定该指针为 null,但仍继续间接引用该指针,则会出现 dereference-after-check 错误。此类错误通常是由于错别字或程序员疏忽造成的。如果程序明确将指针设置为 null,但稍后却间接引用该指针,则将出现 dereference-after-store 错误。此错误通常是因为程序员在声明变量时将该变量初始化为 null 所致。

大多数 null 指针问题会导致一般软件可靠性问题,但如果攻击者可能有意触发 null 指针间接引用,他们可以使用生成的异常绕过安全逻辑以发动拒绝服务攻击,或使应用程序显示调试信息,这些信息在规划后续攻击时十分有用。

示例 1:在下列代码中,程序员假设变量 ptr 不是 NULL。当程序员间接引用该指针时,这个假设就会清晰的体现出来。当程序员检查 ptr 是否为 NULL 时,就会与该假设发生矛盾。当在 if 语句中检查时,如果 ptr 可以为 NULL,则在其间接引用时也将为 NULL,并引起 segmentation fault。


ptr->field = val;
...
if (ptr != NULL) {
...
}
示例 2:在下列代码中,程序员会确认变量 ptrNULL,然后错误地对其进行间接引用。如果在 if 语句中检查 ptr 时其为 NULL,则会发生 null dereference,从而导致分段故障。


if (ptr == null) {
ptr->field = val;
...
}
示例 3:在下列代码中,程序员忘记了字符串 '\0' 实际上为 0 还是 NULL,从而间接引用 null 指针并引发分段故障。


if (ptr == '\0') {
*ptr = val;
...
}
示例 4:在下列代码中,程序员会将变量 ptr 明确设置为 NULL。之后,程序员会间接引用 ptr,而未检查对象是否为 null 值。


*ptr = NULL;
...
ptr->field = val;
...
}
desc.controlflow.cpp.null_dereference
Abstract
程序可能会间接引用一个 null 指针,从而引发 NullPointerException
Explanation
null 指针错误通常是由于违反一个或多个程序员假设而造成的。

大多数 null 指针问题会导致一般软件可靠性问题,但如果攻击者可能有意触发 null 指针间接引用,他们可以使用生成的异常绕过安全逻辑或使应用程序显示调试信息,这些信息在规划后续攻击时十分有用。

示例:在以下代码中,程序员假定系统始终会定义一个名为“cmd”的属性。如果攻击者可以控制程序的环境,从而使“cmd”处于未定义状态,则它就会在尝试调用 trim() 方法时抛出一个 null 指针异常。


String val = null;
...
cmd = System.getProperty("cmd");
if (cmd)
val = util.translateCommand(cmd);
...
cmd = val.trim();
desc.controlflow.java.null_dereference
Abstract
使用不推荐的或过时的函数可能表示这是一段被忽略的代码。
Explanation
一般而言,随着编程语言的发展,有时一些方法会因下列原因过时:

- 为了改进该编程语言
- 对如何有效、安全地执行操作有了更深一步的了解

- 某些操作的管理规则发生了变化

有的语言会删除一些语句,并通常将其替换为执行相同任务的新语句,这些新语句采用不同但更有效的处理方式。

具体来讲,SAP ABAP 已演变成将 ABAP 对象(面向对象的 ABAP 扩展)包含在内,并在兼容 Unicode 的环境中运行。因此,在类或 Unicode 程序中实施了更严格的语法。过时构造仅由于为了兼容早期版本而仍然可用,且只能在类外部或非 Unicode 程序中使用。所有过时语言元素均存在替代构造,这提高了程序的效率和可读性。过时语法中很多隐式、模糊的类型/长度/内存规范需要在较新的语法中以更精确和清晰的方式指定。建议采用较新的语法编写程序,使其更容易理解、功能更强大、更易于维护。


并非所有函数都会因为存在安全漏洞而被弃用或被取代。然而,出现被弃用的函数通常表示周围代码已经不起作用了,有可能处于不受维护的状况。在过去很长一段时间内,人们并没有将软件安全放在首位,甚至都未曾考虑过。如果程序使用了不推荐的或过时的函数,在其附近就会潜伏着安全问题。
desc.semantic.abap.obsolete
Abstract
使用不推荐的或过时的函数可能表示这是一段被忽略的代码。
Explanation
随着编程语言的发展,一些函数有时会被弃用,原因如下:

- 为了改进该编程语言
- 对如何有效、安全地执行操作有了更深一步的了解

- 某些操作的管理规则发生了变化


在一种编程语言中,旧函数会被新函数所替代,比起旧函数,新函数更能以我们所期望的方式执行任务。
示例:以下代码会构造一个新的 SqlClientPermission 对象,这个对象规定了用户可以使用的连接到数据库的方式。在这个例子中,程序把 false 作为第二个参数传递给构造函数(控制着是否允许用户用空密码进行连接)。如果传递的参数值为 false,则说明不允许使用空密码。


...
SCP = new SqlClientPermission(pstate, false);
...


然而,因为作为第一个参数传递的 PermissionState 对象代替了任何传递给第二个参数的值,所以这个构造函数允许使用空密码连接到数据库,这与第二个参数相矛盾。要禁止使用空密码,程序应该把 PermissionState.None 传递给构造函数的第一个参数。由于其功能尚不明确,因此不赞成采用 SqlClientPermission 构造函数的“双参数”版本,而建议采用“单参数”版本(与“双参数”版本功能相同但是避免了被误译的风险)。

并非所有函数都会因为存在安全漏洞而被弃用或被取代。然而,出现被弃用的函数通常表示周围代码已经不起作用了,有可能处于不受维护的状况。在过去很长一段时间内,人们并没有将软件安全放在首位,甚至都未曾考虑过。如果程序使用了不推荐的或过时的函数,在其附近就会潜伏着安全问题。
desc.semantic.dotnet.obsolete
Abstract
使用不推荐的或过时的函数可能表示这是一段被忽略的代码。
Explanation
随着编程语言的发展,一些函数有时会被弃用,原因如下:

— 为了改进该编程语言。
— 对操作的有效性、安全性有更深一步的了解。
—某些操作的管理规则发生了变化。

在编程语中,函数会经常被删除或由新的替代函数所取代,因为新的函数能以我们所期望的方式从多种角度执行相同的任务。
示例:以下代码使用了不被推荐的函数 getpw() 来验证明文密码是否与用户加密密码相匹配。如果密码是有效的,则函数将 result 设为 1;如果无效,将其设为 0。


...
getpw(uid, pwdline);
for (i=0; i<3; i++){
cryptpw=strtok(pwdline, ":");
pwdline=0;
}
result = strcmp(crypt(plainpw,cryptpw), cryptpw) == 0;
...


尽管代码经常正确地运行,使用 getpw() 函数从安全角度来说是有问题的,因为它可以溢出传递给它的第二个参数的缓冲区。因为这个漏洞,getpw() 已由 getpwuid() 替代,它与 getpw() 执行相同的查找,但返回一个指向静态分配结构的指针来降低风险。

并非所有函数都会因为存在安全漏洞而被弃用或被取代。然而,出现被弃用的函数通常表示周围代码已经不起作用了,有可能处于不受维护的状况。在过去很长一段时间内,人们并没有将软件安全放在首位,甚至都未曾考虑过。如果程序使用了不推荐的或过时的函数,在其附近就会潜伏着安全问题。
desc.semantic.cpp.obsolete
Abstract
使用不推荐使用的或过时的函数可能表示存在忽略的代码或使用了陈旧的 ColdFusion 版本。
Explanation
随着编程语言的发展,有时会弃用些一些方法,原因是:

- 为了改进该编程语言
- 对如何有效、安全地执行操作有了更深一步的了解

- 某些操作的管理规则发生了变化

在某一种编程语言中,人们通常会放弃使用某些方法,转而采用更新的方法。在执行同样的任务时,新方法会采用不同的处理方式,这种方式往往比原有的方法更合理。


并非所有函数都会因为存在安全漏洞而被弃用或被取代。然而,出现被弃用的函数通常表示周围代码已经不起作用了,有可能处于不受维护的状况。在过去很长一段时间内,人们并没有将软件安全放在首位,甚至都未曾考虑过。如果程序使用了不推荐的或过时的函数,在其附近就会潜伏着安全问题。
desc.semantic.cfml.obsolete
Abstract
使用不推荐的或过时的函数可能表示这是一段被忽略的代码。
Explanation
随着编程语言的发展,有时会弃用些一些方法,原因是:

- 为了改进该编程语言
- 对如何有效、安全地执行操作有了更深一
步的了解
- 某些操作的管理规则发生了变化

在某一种编程语言中,人们通常会放弃使用某些方法,转而采用更新的方法。在执行同样的任务时,新方法会采用不同的处理方式,这种方式往往比原有的方法更合理。
示例:以下代码使用一个字节数组和一个指定每个 16 位 Unicode 字符中前 8 位的值来构造一个字符串对象。


...
String name = new String(nameBytes, highByte);
...


在此示例中,构造函数可能无法正确地将字节转换为字符,具体取决于使用哪个字符集对以 nameBytes 表示的字符串进行编码。由于用于编码字符串的字符集的演变,此构造函数已被弃用,取而代之的是接受用于编码字节进行转换的 charset 的名称作为其参数之一的构造函数。

并非所有函数都会因为存在安全漏洞而被弃用或被取代。然而,出现被弃用的函数通常表示周围代码已经不起作用了,有可能处于不受维护的状况。在过去很长一段时间内,人们并没有将软件安全放在首位,甚至都未曾考虑过。如果程序使用了不推荐的或过时的函数,在其附近就会潜伏着安全问题。
References
[1] MET02-J. Do not use deprecated or obsolete classes or methods CERT
desc.semantic.java.obsolete
Abstract
使用不推荐的或过时的函数可能表示这是一段被忽略的代码。
Explanation
随着编程语言的发展,有时会弃用些一些方法,原因是:

- 为了改进该编程语言
- 对如何有效、安全地执行操作有了更深一步的了解

—某些操作的管理规则发生了变化。

在某一种编程语言中,人们通常会放弃使用某些方法,转而采用更新的方法。在执行同样的任务时,新方法会采用不同的处理方式,这种方式往往比原有的方法更合理。
示例:以下代码使用了 Digest::HMAC stdlib,它的使用在文档中是明确禁止的,是由于意外介入才出现在版本中。


require 'digest/hmac'

hmac = Digest::HMAC.new("foo", Digest::RMD160)
...
hmac.update(buf)
...


在此示例中,Digest::HMAC 类在由于偶然纳入版本中而介入时立即被弃用。由于代码是试验性的且未经正确测试,导致类存在不按预期工作的可能性,因此绝对禁止使用该类,尤其是考虑到关系 HMAC 与加密功能有关。

并非所有函数都会因为存在安全漏洞而被弃用或被取代。然而,出现被弃用的函数通常表示周围代码已经不起作用了,有可能处于不受维护的状况。在过去很长一段时间内,人们并没有将软件安全放在首位,甚至都未曾考虑过。如果程序使用了不推荐的或过时的函数,在其附近就会潜伏着安全问题。
desc.structural.ruby.obsolete
Abstract
使用了一个已弃用的函数。
Explanation
由于智能合约具有快节奏的性质,因此在较新的编译器版本中可能会弃用一些函数和运算符,使用它们可能会导致代码质量低、出现意外的不利作用和/或编译错误。

示例 1:以下代码使用 block.blockhash() 获取当前块的散列值,但是自 Solidity 编译器 0.5.0 版本以来已将其弃用。


bytes32 blockhash = block.blockhash(0);
desc.structural.solidity.swc111
Abstract
函数已过时,不能保证指针是有效的,或引用的内存可以安全使用。
Explanation
不使用 IsBadXXXPtr() 类的函数有多种原因。这些函数是:
1) 非线程安全的。
2) 通常与由于其探测无效内存地址而导致的崩溃有关。
3) 被错误地认为在异常条件中执行正确的错误处理。

示例:以下代码使用 IsBadWritePtr() 尝试避免错误的内存写入。

if (IsBadWritePtr(ptr, length))
{
[handle error]
}


程序员原本希望使用这些函数来检测异常情况,但它们通常导致更多无法修复的问题。
References
[1] Raymond Chen IsBadXxxPtr should really be called CrashProgramRandomly
[2] IsBadWritePtr Function Microsoft
[3] Standards Mapping - CIS Azure Kubernetes Service Benchmark 1
[4] Standards Mapping - CIS Amazon Elastic Kubernetes Service Benchmark 2
[5] Standards Mapping - CIS Amazon Web Services Foundations Benchmark 1
[6] Standards Mapping - CIS Google Kubernetes Engine Benchmark normal
[7] Standards Mapping - Common Weakness Enumeration CWE ID 730
[8] Standards Mapping - DISA Control Correlation Identifier Version 2 CCI-001094
[9] Standards Mapping - NIST Special Publication 800-53 Revision 4 SC-5 Denial of Service Protection (P1)
[10] Standards Mapping - NIST Special Publication 800-53 Revision 5 SC-5 Denial of Service Protection
[11] Standards Mapping - OWASP Top 10 2004 A9 Application Denial of Service
[12] Standards Mapping - Payment Card Industry Data Security Standard Version 1.1 Requirement 6.5.9
[13] Standards Mapping - Security Technical Implementation Guide Version 3.1 APP6080 CAT II
[14] Standards Mapping - Security Technical Implementation Guide Version 3.4 APP6080 CAT II
[15] Standards Mapping - Security Technical Implementation Guide Version 3.5 APP6080 CAT II
[16] Standards Mapping - Security Technical Implementation Guide Version 3.6 APP6080 CAT II
[17] Standards Mapping - Security Technical Implementation Guide Version 3.7 APP6080 CAT II
[18] Standards Mapping - Security Technical Implementation Guide Version 3.9 APP6080 CAT II
[19] Standards Mapping - Security Technical Implementation Guide Version 3.10 APP6080 CAT II
[20] Standards Mapping - Security Technical Implementation Guide Version 4.1 APSC-DV-002400 CAT II
[21] Standards Mapping - Security Technical Implementation Guide Version 4.2 APSC-DV-002400 CAT II
[22] Standards Mapping - Security Technical Implementation Guide Version 4.3 APSC-DV-002400 CAT II
[23] Standards Mapping - Security Technical Implementation Guide Version 4.4 APSC-DV-002400 CAT II
[24] Standards Mapping - Security Technical Implementation Guide Version 4.5 APSC-DV-002400 CAT II
[25] Standards Mapping - Security Technical Implementation Guide Version 4.6 APSC-DV-002400 CAT II
[26] Standards Mapping - Security Technical Implementation Guide Version 4.7 APSC-DV-002400 CAT II
[27] Standards Mapping - Security Technical Implementation Guide Version 4.8 APSC-DV-002400 CAT II
[28] Standards Mapping - Security Technical Implementation Guide Version 4.9 APSC-DV-002400 CAT II
[29] Standards Mapping - Security Technical Implementation Guide Version 4.10 APSC-DV-002400 CAT II
[30] Standards Mapping - Security Technical Implementation Guide Version 4.11 APSC-DV-002400 CAT II
[31] Standards Mapping - Security Technical Implementation Guide Version 5.1 APSC-DV-002400 CAT II
[32] Standards Mapping - Security Technical Implementation Guide Version 5.2 APSC-DV-002400 CAT II
[33] Standards Mapping - Security Technical Implementation Guide Version 5.3 APSC-DV-002400 CAT II
[34] Standards Mapping - Web Application Security Consortium Version 2.00 Denial of Service (WASC-10)
[35] Standards Mapping - Web Application Security Consortium 24 + 2 Denial of Service
desc.semantic.cpp.obsolete_inadequate_pointer_validation
Abstract
该类包含具有同一名称的字段和方法。
Explanation
在同一个类中,成员字段与方法同名会给程序员带来诸多困扰。当他想要访问某字段时却意外地调用了与之同名的方法;反之当他想要调用某一方法时却又访问了与之同名的字段。

例 1:

public class Totaller {
private int total;
public int total() {
...
}
}
References
[1] Standards Mapping - CIS Azure Kubernetes Service Benchmark 1
[2] Standards Mapping - CIS Amazon Elastic Kubernetes Service Benchmark 5
[3] Standards Mapping - CIS Amazon Web Services Foundations Benchmark 1
[4] Standards Mapping - CIS Google Kubernetes Engine Benchmark normal
[5] Standards Mapping - Common Weakness Enumeration CWE ID 398, CWE ID 710
[6] Standards Mapping - Smart Contract Weakness Classification SWC-119
desc.structural.java.poor_style_confusing_naming.member_and_method
Abstract
合约使用了一个隐藏变量,该变量不明确,很容易被误用。
Explanation
Solidity 允许开发人员以不确定的方式声明状态变量。这意味着即使两个不同上下文中的两个不同变量可以使用相同的名称进行声明,但使用它们可能会导致混乱和误用。

在函数级别和继承级别上都可能会发生这种情况。例如,如果 Contract1 声明了 var1 并继承自 Contract2,而 Contract2 也声明了一个名为 var1 的变量,则该变量为不明确变量,并且在以后的智能合约执行中很容易相互混淆。

示例 1:以下代码使用了继承,并且在两个智能合约中都声明了一个具有相同名称的状态变量。很难确定代币销售的实际 hardcap


contract Tokensale {
uint hardcap = 10000 ether;

function Tokensale() { }

function fetchCap() public constant returns(uint) {
return hardcap;
}
}

contract Presale is Tokensale {
uint hardcap = 1000 ether;

function Presale() Tokensale() { }
}
References
[1] Standards Mapping - CIS Azure Kubernetes Service Benchmark 1
[2] Standards Mapping - CIS Amazon Elastic Kubernetes Service Benchmark 5
[3] Standards Mapping - CIS Amazon Web Services Foundations Benchmark 1
[4] Standards Mapping - CIS Google Kubernetes Engine Benchmark normal
[5] Standards Mapping - Common Weakness Enumeration CWE ID 398, CWE ID 710
[6] Standards Mapping - Smart Contract Weakness Classification SWC-119
desc.structural.solidity.swc119