Skip to content

Conversation

@uo1
Copy link
Contributor

@uo1 uo1 commented Jan 6, 2025

Closes #110073
Removed check for Resource Type to be public.
Added test for DisplayAttribute to ensure it works with with internal Resource Type.

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jan 6, 2025
@rhuijben
Copy link
Contributor

rhuijben commented Jan 6, 2025

Not sure if this should be in the common library. This opens this api up to read every private string property. When this was designed that would be a huge security issue. (Times have changed, but not sure this api should as well)

@tarekgh
Copy link
Member

tarekgh commented Jan 6, 2025

@jeffhandley @eiriktsarpalis @ericstj @krwq do you know the history of the affected APIs? a concern is raised by @rhuijben in the comment #111130 (comment).

@tarekgh tarekgh added this to the 10.0.0 milestone Jan 6, 2025
@uo1
Copy link
Contributor Author

uo1 commented Jan 6, 2025

Not sure if this should be in the common library. This opens this api up to read every private string property. When this was designed that would be a huge security issue. (Times have changed, but not sure this api should as well)

It's not about the property to be public, it's only about the ResourceType, that might be only internal and not public. But since you need to have access to the type that is assigned to the ResourceType, I don't see that it might be a security issue. But I'm also not fully sure about this either.

@uo1 uo1 force-pushed the fix-localizablestring branch from d52cf62 to c5e7e6f Compare January 6, 2025 22:07
@tarekgh
Copy link
Member

tarekgh commented Jan 6, 2025

@uo1 reading the code

GetRuntimeProperty will work only if the property is public property. Implicitly indicating the type containing the property must be public too. Right?

@uo1
Copy link
Contributor Author

uo1 commented Jan 6, 2025

@uo1 reading the code

GetRuntimeProperty will work only if the property is public property. Implicitly indicating the type containing the property must be public too. Right?

@tarekgh I just checked it and you are right, that the property needs to be public, but it does not matter, which access modifier the type has. Even if _resourceType is assigned with a type that is only private or internal the method GetRuntimeProperty will still return a valid PropertyInfo if the property exists and is public.

@tarekgh
Copy link
Member

tarekgh commented Jan 6, 2025

Even if _resourceType is assigned with a type that is only private or internal the method GetRuntimeProperty will still return a valid PropertyInfo if the property exists and is public.

Yes, I understand that. I was trying to figure out if checking the resource type in the code to be public was done intentionally for specific reason or it was just early check to avoid calling reflection. I don't know the history to tell.

Generally, I do not see a significant issue if we allow using the internal types with the DisplayAttribute. It is kind of breaking change but not major breaking. Also, I am not seeing this is a security issue either. Users can still call reflection with the internal types to get the property value if they want.

I'll not object to accepting this change if others do not have any concerns.

@jeffhandley @eiriktsarpalis @ericstj @krwq @GrabYourPitchforks

uo1 added 2 commits January 7, 2025 23:25
Removed check for Resource Type to be public.
Added test for DisplayAttribute to ensure it works with with internal Resource Type.
@uo1 uo1 force-pushed the fix-localizablestring branch from 3ef97e9 to 8e7afff Compare January 7, 2025 22:25
@tarekgh
Copy link
Member

tarekgh commented Jan 7, 2025

@uo1 Why do you keep force-pushing the changes? Please avoid doing that so the reviewers don't have to repeat the review process.

@uo1
Copy link
Contributor Author

uo1 commented Jan 8, 2025

@uo1 Why do you keep force-pushing the changes? Please avoid doing that so the reviewers don't have to repeat the review process.

The pipelines keep failing with different errors that are not related to the changes in this PR. I just rebased the PR a few times to start the pipeline again, but it's still not successful. I will not rebase the PR anymore. Hopefully someone will take care if that problem.

@krwq
Copy link
Member

krwq commented Jan 8, 2025

@uo1 that's not necessary to be green - look at the details of Build Analysis — .NET Result Analysis and you only need to review that failures are known. If failures are unrelated to your changes we can still merge the PR. With the traffic we have in this repo it's really hard to keep checks green at all times especially with all configurations on different OSes. If you're changing fairly deterministic things most configurations will fail on any error.

Copy link
Member

@krwq krwq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I agree with what we change here. My concerns are mainly with code generators:

  • code with DisplayAttribute can be generated and now it will have access to internal stuff - it's much harder to reason about it if we allow this - is it always right to allow this?
  • code generator or different assembly can consume this attribute and effectively access stuff which was not meant to be public if they go through data annotations APIs - IMO we should not risk exposing what was not meant to be visible

I also fully agree with #15794 (comment) - the workaround is simple enough and we're opening unknown territory here for very little benefit

Copy link
Member

@jeffhandley jeffhandley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I introduced this type back in ~2009 as part of the WCF RIA Services product. I tried to remember why we put these "bad configuration" detections in place and here's what I recall...

For RIA Services, we were going to consume the resources and project them from an ASP.NET project into a Silverlight project where a lot of code was being generated. In the Silverlight client, we would not have private reflection available to us, and the types therefore needed to be public for the end-to-end scenario to work.

When the client code would fail because of the types not being public, it would lead to a difficult-to-diagnose crash in the Silverlight app, without any feedback to the developer. We shifted this detection into the attribute so that if the end-to-end would not work (in our app model), we would fail at a time during the developer flow that the error message would be visible in Visual Studio and the developer could be unblocked.

Since this is no longer about an environment of projecting the app from ASP.NET to Silverlight, I think it's OK to remove this detection. We cannot guarantee non-public resources will work in every app model, for for app models where it does work it's valuable to remove the block.

@tarekgh tarekgh merged commit 06a6ea7 into dotnet:main Jan 8, 2025
80 of 83 checks passed
@tarekgh
Copy link
Member

tarekgh commented Jan 8, 2025

Thanks @uo1 for providing the change!

@uo1 uo1 deleted the fix-localizablestring branch January 8, 2025 17:22
@github-actions github-actions bot locked and limited conversation to collaborators Feb 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.ComponentModel.DataAnnotations community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[DataAnnotations] LocalizableString does not work with internal resource types

5 participants