Skip to content

Conversation

@pranavkm
Copy link
Contributor

@pranavkm pranavkm commented Oct 1, 2021

Prevent 'System.Delegate' and some reflection types from being validated.

Fixes #36919

Description

MVC has where it will attempt to ensure that properties of a model being bound, that are marked as non-nullable, and indeed not null during validation. Validation will also recurse over the entire object graph. In the user reported issue, the user had a System.Delegate type appear in their model. Since the BCL is annotated for nullability, MVC's validation ends up at Assembly.ExportedTypes via Delegate.MethodInfo and ends up visiting every Type instance on it.

While we think we need a better fix for this in 7.0, we'd like to consider a much more limited fix for 6.0 by preventing properties on Delegate and some reflection types from being validated. MVC already excludes some types including System.Type from being validated, so this is an expansion of the list to include Delegate and a few reflection types such as MethodInfo, ParameterInfo, that would not warrant validation.

Regression

No

Testing

[x] Manual
[x] Automated

Risk

It's possible that someone's actually trying to model bind a custom instance of MethodInfo that does need to be validated for nullability. This is an incredibly contrived scenario and we don't have any evidence anyone is actually doing so. Users should be able to workaround this by configuring MvcOptions to allow these types to be validated.

Prevent 'System.Delegate' and some reflection types from being validated.

Fixes #36919
@pranavkm pranavkm requested a review from javiercn as a code owner October 1, 2021 17:12
@ghost ghost added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Oct 1, 2021
@pranavkm pranavkm requested review from a team and removed request for javiercn October 1, 2021 17:14
@pranavkm pranavkm changed the title Exclude additional types from being validated (#37150) Add additional types to SuppressChildValidationMetadataProvider (#37150) Oct 1, 2021
@pranavkm pranavkm added the Servicing-approved Shiproom has approved the issue label Oct 4, 2021
@pranavkm
Copy link
Contributor Author

pranavkm commented Oct 4, 2021

@dotnet/aspnet-build this was approved. Could you merge it?

@dougbu dougbu merged commit ddc6da1 into release/6.0 Oct 4, 2021
@dougbu dougbu deleted the prkrishn/port-36919 branch October 4, 2021 23:00
@ghost ghost added this to the 6.0.0 milestone Oct 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates Servicing-approved Shiproom has approved the issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants