
BLy145736 (Community Member) asked a question.
I tried to implement a view model to fix this flaw as the documentation suggests, but the issue remains. Can anyone tell me where I went wrong? Thanks in advance!

BLy145736 (Community Member) asked a question.
I tried to implement a view model to fix this flaw as the documentation suggests, but the issue remains. Can anyone tell me where I went wrong? Thanks in advance!
Ask the Community
Get answers, share a use case, discuss your favorite features, or get input from the community.
By clicking “Accept All Cookies”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts.
.png)
These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site will not then work. These cookies do not store any personally identifiable information.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us to know which pages are the most and least popular and see how visitors move around the site. All information these cookies collect is aggregated and therefore anonymous. If you do not allow these cookies we will not know when you have visited our site, and will not be able to monitor its performance.
These cookies may be set through our site by our advertising partners. They may be used by those companies to build a profile of your interests and show you relevant adverts on other sites. They do not store directly personal information, but are based on uniquely identifying your browser and internet device. If you do not allow these cookies, you will experience less targeted advertising.
Hi @BLy145736 (Community Member) ,
Usage of a ViewModel is a valid way to prevent underposting/overposting and for addressing/mitigating CWE 915. The ViewModel is supposed to represent what properties of the model you want exposed in your view. You would normally achieve this with a model by using bind attributes. In the example below, I only ever want the FirstName, LastName, Email to be updated as part of Edit() action.
public class User
{
public int ID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public bool IsAdmin { get; set; }
}
public ViewResult Edit([Bind(Include = "FirstName","LastName","Email")] User user)
{
// ...
}
or
public ViewResult Edit([Bind(Exclude = "ID","IsAdmin")] User user)
{
// ...
}
Notice the usage of Bind Include which tells the action that only these properties are in scope for this action or Bind Exclude which tells the action that all other properties of the model are in scope except for these specific ones.
When using a ViewModel, you're specifying this in the ViewModel itself:
pubic class UserViewModel
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
}
public ViewResult Edit(UserViewModel viewModel)
{
// ...
}
Since the properties are defined within the ViewModel, the Veracode Static Analysis Tool can't determine which properties from the context of the controller should be allowed. Whereas with the the Bind Include, the properties are explicitly called in the arguments to the controller method which the Veracode Static Analysis Tool can infer as the intended properties to be used. Usage of Bind Exclude, while valid to mitigate the risk, is not something we support or will it be recognized by the Veracode Static Analysis Tool as this is a block-list approach which is not recommended unless absolutely necessary.
So from the snippet, it looks like you have addressed the risk properly but unfortunately this is not something the Veracode Static Analysis tool will recognize as a fix. I would recommend using the mitigation workflow to document the controls and reach out to your security team for review/approval: https://help.veracode.com/reader/DGHxSJy3Gn3gtuSIN2jkRQ/~p4MSKOS8F8X8h0KwFTKoQ .
If you still have any questions, I would recommend schedule a consultation call to discuss the flaw as it relates to your specific code with a member of my team: https://help.veracode.com/reader/DGHxSJy3Gn3gtuSIN2jkRQ/7YQTCDJKFEQzL3gL_N90hQ .
Thanks,
Veasna Nhin
Senior Application Security Consultant