TRENDING

TECHNOLOGY NEWS FROM AROUND THE WORLD

→
ASP.NET MVC ModelState: why client-side validation is insufficient
Software Engineering · 2018Photo: Unsplash / Unsplash ↗
Software Engineering2018 / RETROSPECTIVE

ASP.NET MVC ModelState: why client-side validation is insufficient

Model binding, server-side validation, actionable feedback and overposting risks in ASP.NET MVC.

Yazılımcının GünlüğüPublished: Nov 16, 20263 min read

Sample period date: Aug 11, 2018. These essays revisit earlier technologies from today's editorial perspective; they are not represented as posts originally published in those years.

Browser validation improves experience only

Showing missing-field or malformed-email errors in the browser is useful, but any HTTP client can bypass those checks. The server must validate the submitted model, inspect ModelState and stop before persisting invalid values. JavaScript validation alone is not a security boundary, especially on administrative forms.

Model binding and overposting

A property such as IsAdmin must not become writable merely because it exists on a model class. Attackers can submit fields that the form never rendered. Use dedicated input models and source authorization, ownership and system-managed fields from trusted server state. A valid ModelState does not replace an authorization check.

Give actionable validation feedback

On validation failure, preserve safe input values and explain which field is rejected and why. Ordinary validation problems should not become generic error pages. Yet do not expose database exception messages or stack traces to visitors; keep details in server logs.

Test negative cases too

Test missing fields, type mismatches, unauthorized updates, unexpected posted properties and concurrent edits alongside valid requests. Verify both HTTP response status and the durable database state. The durable lesson of the MVC era is to treat all submitted fields as crossing a trust boundary.

0 reads

Comments

0 real comments

No real reader comments yet.

✎ Write a comment

Comments are reviewed before publication.