界: API Abuse

API 是调用方和被调用方之间的约定。最常见的 API 滥用是由于调用方未能遵守此约定的终止导致的。例如,如果某个程序在调用 chroot() 后未能调用 chdir(),则违反了用于指定如何安全地更改活动根目录的约定。库滥用的另一个典型示例是期望被调用方向调用方返回可信的 DNS 信息。在这种情况下,调用方通过对被调用方行为做出某种假设(返回值可用于身份验证目的)滥用其 API。另一方也可能违反调用方-被调用方约定。例如,如果编码器子类化 SecureRandom 并返回一个非随机值,则将违反此约定。

ASP.NET MVC Bad Practices: Model With Required Non-Nullable Property

Abstract
模型类有要求的不可为空属性,因此可能容易受发布中攻击的影响。
Explanation
如果攻击者传送的请求中包含的数据少于预期,使用有要求的不可为空属性的模型类(标记为 [Required] 属性)可能导致问题。

ASP.NET MVC 框架将尝试捆绑请求参数到模型属性。

如果模型有要求的不可为空属性,而攻击者没有传送需要的参数要求 -- 也就是说,攻击者使用发布中攻击 -- 那么属性将拥有默认值(通常为零),该默认值将满足 [Required] 验证属性。这可能产生不可预期的应用程序行为。

以下代码定义了一种可能的模型类,其中有要求的枚举,不可为空:


public enum ArgumentOptions
{
OptionA = 1,
OptionB = 2
}

public class Model
{
[Required]
public String Argument { get; set; }

[Required]
public ArgumentOptions Rounding { get; set; }
}
References
[1] Input Validation vs. Model Validation in ASP.NET MVC
[2] Standards Mapping - CIS Azure Kubernetes Service Benchmark 3
[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 3
[6] Standards Mapping - CIS Google Kubernetes Engine Benchmark integrity
[7] Standards Mapping - CIS Kubernetes Benchmark partial
[8] Standards Mapping - Common Weakness Enumeration CWE ID 345
[9] Standards Mapping - DISA Control Correlation Identifier Version 2 CCI-002422
[10] Standards Mapping - NIST Special Publication 800-53 Revision 4 SC-8 Transmission Confidentiality and Integrity (P1)
[11] Standards Mapping - NIST Special Publication 800-53 Revision 5 SC-8 Transmission Confidentiality and Integrity
[12] Standards Mapping - OWASP Top 10 2004 A1 Unvalidated Input
[13] Standards Mapping - OWASP Top 10 2007 A2 Injection Flaws
[14] Standards Mapping - OWASP Top 10 2010 A1 Injection
[15] Standards Mapping - OWASP Top 10 2013 A1 Injection
[16] Standards Mapping - OWASP Top 10 2017 A1 Injection
[17] Standards Mapping - OWASP Top 10 2021 A03 Injection
[18] Standards Mapping - OWASP API 2023 API3 Broken Object Property Level Authorization
[19] Standards Mapping - OWASP Application Security Verification Standard 4.0 3.5.3 Token-based Session Management (L2 L3), 13.2.6 RESTful Web Service Verification Requirements (L2 L3)
[20] Standards Mapping - OWASP Mobile 2014 M1 Weak Server Side Controls
[21] Standards Mapping - Payment Card Industry Data Security Standard Version 1.1 Requirement 6.5.6
[22] Standards Mapping - Security Technical Implementation Guide Version 4.1 APSC-DV-002470 CAT II
[23] Standards Mapping - Security Technical Implementation Guide Version 4.2 APSC-DV-002470 CAT II
[24] Standards Mapping - Security Technical Implementation Guide Version 4.3 APSC-DV-002470 CAT II
[25] Standards Mapping - Security Technical Implementation Guide Version 4.4 APSC-DV-002470 CAT II
[26] Standards Mapping - Security Technical Implementation Guide Version 4.5 APSC-DV-002470 CAT II
[27] Standards Mapping - Security Technical Implementation Guide Version 4.6 APSC-DV-002470 CAT II
[28] Standards Mapping - Security Technical Implementation Guide Version 4.7 APSC-DV-002470 CAT II
[29] Standards Mapping - Security Technical Implementation Guide Version 4.8 APSC-DV-002470 CAT II
[30] Standards Mapping - Security Technical Implementation Guide Version 4.9 APSC-DV-002470 CAT II
[31] Standards Mapping - Security Technical Implementation Guide Version 4.10 APSC-DV-002470 CAT II
[32] Standards Mapping - Security Technical Implementation Guide Version 4.11 APSC-DV-002470 CAT II
[33] Standards Mapping - Security Technical Implementation Guide Version 5.1 APSC-DV-002470 CAT II
[34] Standards Mapping - Security Technical Implementation Guide Version 5.2 APSC-DV-002470 CAT II
[35] Standards Mapping - Security Technical Implementation Guide Version 5.3 APSC-DV-002470 CAT II
[36] Standards Mapping - Web Application Security Consortium Version 2.00 Improper Input Handling (WASC-20)
desc.structural.dotnet.aspnet_mvc_bad_practices_required_non_nullable_in_model