界: Encapsulation

封装即绘制强边界。在 Web 浏览器中,这可能意味着确保您的移动代码不会被其他移动代码滥用。在服务器上,这可能意味着区分已验证数据和未验证数据、区分一个用户的数据和另一个用户的数据,或者区分允许用户查看的数据和不允许用户查看的数据。

Django Bad Practices: Attributes in Deny List

Abstract
应用程序使用拒绝列表来控制表单所显示的属性。当添加新属性时开发人员可能会忘记更新拒绝列表,也可能会不小心将敏感字段暴露给攻击者。
Explanation
应用程序使用 exclude 拒绝列表。这很难维护,而且容易出错。如果开发人员向表单或备份表单的 Model 添加新字段,并忘记了更新 exclude 筛选器,则可能会向攻击者暴露敏感字段。攻击者将能够向任何未排除的字段提交和恶意绑定数据。

示例 1:以下表单显示了一些 User 属性,但对以下用户 id 检验了拒绝列表:


from myapp.models import User
...
class UserForm(ModelForm):
class Meta:
model = User
exclude = ['id']
...


如果使用新的 role 属性更新了 User 模型,但未更新相关联的 UserForm,则 role 属性将显示在表单中。
References
[1] Django Foundation Creating forms from models
[2] Standards Mapping - CIS Azure Kubernetes Service Benchmark 3
[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 - General Data Protection Regulation (GDPR) Indirect Access to Sensitive Data
[7] Standards Mapping - OWASP API 2023 API3 Broken Object Property Level Authorization
[8] Standards Mapping - OWASP Mobile 2024 M8 Security Misconfiguration
desc.structural.python.django_bad_practices_attributes_in_deny_list