MVC Security Violation - Improperly Controlled Modification of Dynamically-Determined Object Attributes

时间秒杀一切 提交于 2019-12-13 02:34:59

问题


We are developing an MVC 5 Application and while we ran security scan using Veracode we are getting the below flaw saying

"Improperly Controlled Modification of Dynamically-Determined Object Attributes"

And added this link as reference to fix.

Tried implementing Bind Attribute to my Controllers functions with HTTP Post and the issue is fixed.

So in ASP.NET MVC is it mandatory to use Bind Attribute for all the Post to avoid security violation ?

Or can i ignore this flaw or any other alternative way i can address this as hard coding and maintaining Bind Attributes really gets difficult in real time applications.

Please share your views.


回答1:


it is not mandatory to use the Bind attribute.

The link which you have posted is basically the dirtiest example they could have came up with. They are directly binding an EF model into the controller, which no real world application would do and I hate Miscrosoft where they show you how easily you can go from DB to Web by applying the dirtiest worst practise patterns without explaining that this is not something you would want to do in real life.

In real life you would create a (View)Model which is tailored to your View. This means the class will ONLY have the properties which you want to accept from the request, therefore you wouldn't really need the Bind attribute in most cases.

EF models are low level classes in your data layer and shouldn't be bound to any controllers IMO.

UPDATE: Actually on the top of the link they have posted this:

Note It's a common practice to implement the repository pattern in order to create an abstraction layer between your controller and the data access layer. To keep these tutorials simple and focused on teaching how to use the Entity Framework itself, they don't use repositories. For information about how to implement repositories, see the ASP.NET Data Access Content Map.

However, this is just talking about the repository pattern, which is a good pattern to abstract your data layer, but the DTO which the repository pattern would return is still too low level for binding to a View.

You should create a model which is tailored to your view and in your controller or service layer you can do the infrastructure mapping between the different layers.



来源:https://stackoverflow.com/questions/29164776/mvc-security-violation-improperly-controlled-modification-of-dynamically-deter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!