MVC Security Violation - Improperly Controlled Mod

2019-08-14 04:44发布

问题:

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.