Closed mwhouser closed 3 years ago
@mwhouser I agree it's possible to force an error here. However, what is the impact of the Exception
beyond returning an error page to the spammer? (I don't see how actual users could hit this case when using a generated <form>
.)
Hi @dougbu
I completely agree that under normal circumstances, this shouldn't be an issue.
The problem is that it doesn't just return an error page to the spammer. Instead, it triggers an unhandled exception.
And when you log all unhandled exceptions (as I am), the logs fill up with the spam.
And when you pay by the MB for your logging service and/or have a daily logging cap, that spam can have a significant impact.
Also, when you have PagerDuty triggered by significant volume of logs being injested, you get alerted at 3am.
There are some alternative mitigation methods:
ModelState
in the controller before the view is rendered. This happens "blind" so the benefits of using the ModelState
value are lost even in valid cases.Options 1 & 2 won't work for me. Using 3 as a solution is basically working against the framework, and must be implemented on every action that includes a bool
in the model.
Thanks for contacting us, @mwhouser. Given the available workarounds we're not planning to fix this as this issue doesn't impact many customers.
MVC Version: 5.2.7 .NET Framework Version: 4.7.2 Visual Studio Version: (2017) 15.9.6
Symptoms
Html.CheckBoxFor(m => m.BoolValue)
will throw an exception ifModelState["BoolValue"]
contains a value that cannot be converted to true/false or checked/unchecked:I am getting this exception during spam attacks in my logs.
Steps to Reproduce
Model:
Controller:
In my view (.cshtml)
Use PostMan or curl to send a POST to the action, sending
IsRememberMe
with value of555
.The problem will happen when the model failed to validate and the view is being rendered for the user to correct the issues (theoretically). However, in this case, the
ModelState
has bad data and the view crashes.Expected Behaviour
At the very least, don't crash taking the whole view with it.
Ideally, if the value in
ModelState
cannot be converted, then catch the exception and use the value in the model instead.