BLy145736 (Community Member) asked a question.

CWE 915: IMPROPERLY CONTROLLED MODIFICATION OF DYNAMICALLY-DETERMINED OBJECT ATTRIBUTES

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!

 

cwe-915


VCode likes this.
  • vnhin (Veracode, Inc.)

    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

    Expand Post

Topics (1)

No articles found
Loading

Ask the Community

Get answers, share a use case, discuss your favorite features, or get input from the community.