The security benefit of using presentation models

Presentation models, or, are are lightweight classes tailored to the needs of the screens on which they are used. The obvious benefit is that they remove some of the work required to translate between domain model objects and user interface elements. Work that is usually performed by the view and controller in an MVC context.

A secondary benefit of presentation models is that they explicity define what can be bound to domain model objects. Automatic binding such as Asp.net MVC's ComplexModelBinder and UpdateModel method can potentially allow a malicious user to bind data to properties that the developer didnt intent. For example when saving their profile they could add an extra form parameter called 'Role' and set its value to 'SuperUser'. If the controller is using ComplexModelBinder or UpdateModel and the domain model object has a property called 'Role' then it could well receive the unintended 'SuperUser' value. Because the presentation model would not have a writable property called 'Role' it would prevent this exploit.

In the pursuit of simplified views and controllers I am starting to use presentation models more often. The security benefit is just another justification to overcome the extra work.

This article is part of the GWB Archives. Original Author: Liam McLennan

New on Geeks with Blogs

  • We Won The One Award I Actually Care About

    Full Scale made the Inc. 5000 for the fifth year straight, the 12th listing across my three companies. Here is why the one award you cannot buy is worth stopping for.

  • Your Customers Build the Features Now

    I let a tool I liked sit dead for a year rather than build the features I wanted. An MCP server meant I never had to, and your customers can do the same to your product.

  • Get the Size of a Directory in Linux the Easy Way

    du -sh for the quick answer, ncdu for the cleanup, df for the disk itself: every command for checking directory size in Linux, plus why du and df never agree.

  • Vim Search and Replace: The Ultimate Guide

    One :%s command replaces every match in a file before a find dialog would even open. The Vim substitute patterns worth the muscle memory: flags, ranges, capture groups, and multi-file edits.