-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Removes duplicated email validation in user registration. #11766
Removes duplicated email validation in user registration. #11766
Conversation
src/OrchardCore.Modules/OrchardCore.Users/Controllers/RegistrationController.cs
Show resolved
Hide resolved
You break the build |
Sorry, one should not send pull requests when in a rush... I've updated the unit test, but it's still breaking the build - don't know why. |
No, we can't assume that the View that is posting to that form is using that ViewModel. It is important that the controller makes a double verification to make sure it is a valid email. |
Sorry, but that statement isn't correct, validation takes place in the controller. It does it twice! |
It is fine to validate in the Controller. The ViewModel validation is just for that View. What if you use a different form to post to that controller action and that you don't validate the email? |
The issue is that the controller does the normal model validation with |
Add validation on the ViewModel itself to make sure it is never NULL on that controller action before doing anything else. That might fix the issue I was referring to... It is not given that the ViewModel databinding will not fail. |
Maybe I'm not getting your point, but it's already doing all of that in OrchardCore/src/OrchardCore.Modules/OrchardCore.Users/ViewModels/RegisterViewModel.cs Line 31 in 40d3f65
It doesn't make sense to redo the validation a second time IMHO. |
Here, when we call the action : OrchardCore/src/OrchardCore.Modules/OrchardCore.Users/Controllers/RegistrationController.cs Lines 64 to 67 in cf16293
The So basically, make sure that the model passed is never null. |
That's the normal way it is handled everywhere in asp.net and I didn't change that here. If model is null, an |
We need to try to make sure. Because else keeping the validation in the controller makes sense. I don't want to rely on an NRE to say that it is safe. |
This is what model binding and model validation is build for, no need to reinvent the wheel here in a single instance. |
Well for this PR I assume that it is ok. I don't mind. if you omit to send only an email param from an AJAX POST request then it should throw an NRE at line 73. We could instead on the first line do a redirect with a notification message if model == null. Need to try I guess. |
By the way, if the request throws an NRE from an AJAX request it can be used for a DDOS attack. So while we have the Antiforgery Token I feel less concerned but we should probably still take some time to think about potential security issues on known routes like these. |
I don't think there is a problem in this anyway, validation will always take place before the controller is executed. And if I remember correctly, polymorphic model binding is also not possible by default in Asp.net core, so it will never reach line 73 without an email address. This might be different in Orchard, but that would surprise me. |
It happens quite often when I'm using ApiControllers that the model binding is not working. I don't want to assume that it works without throwing an NRE which is what I will test. Anyways let's not digress to other topics. Thanks for your contribution. ❤️ |
Fixes #11765