Skip to content
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

Self-assignment instead of delegate creation #111031

Open
PetSerAl opened this issue Jan 2, 2025 · 4 comments
Open

Self-assignment instead of delegate creation #111031

PetSerAl opened this issue Jan 2, 2025 · 4 comments
Labels
area-System.Security help wanted [up-for-grabs] Good issue for external contributors Priority:3 Work that is nice to have
Milestone

Comments

@PetSerAl
Copy link

PetSerAl commented Jan 2, 2025

private static Func<ClaimsPrincipal> s_principalSelector = ClaimsPrincipalSelector;

Here it is basically self-assignment: ClaimsPrincipalSelector property read the same field it is assigned to. As result ClaimsPrincipalSelector property ends up being null: https://sharplab.io/#v2:C4LgTgrgdgNAJiA1AHwAIEYB0GCcAKDTAZQFMBjCMAS2AE9MBhAGwEMqBbAZ0dY84AVqUMlQAOLJjzZdBVYWImkm5YAHswAAiqcNUCEyYBKANxA=
Looks like it should be SelectClaimsPrincipal (to create delegate from method) instead of ClaimsPrincipalSelector.

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Jan 2, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-security, @bartonjs, @vcsjones
See info in area-owners.md if you want to be subscribed.

@KalleOlaviNiemitalo
Copy link

KalleOlaviNiemitalo commented Jan 2, 2025

It looks like a bug indeed. But .NET Framework behaves the same, and ClaimsPrincipal.Current tolerates s_principalSelector being null, so I don't think it's causing any actual problem. https://learn.microsoft.com/dotnet/api/system.security.claims.claimsprincipal.claimsprincipalselector?view=net-9.0 even documents that the default value is null.

I think the initialisation of ClaimsPrincipal.s_principalSelector should be just removed, and the type of ClaimsPrincipal.s_principalSelector and ClaimsPrincipal.ClaimsPrincipalSelector should be changed to nullable Func<ClaimsPrincipal>?.

@jeffhandley
Copy link
Member

Assigned to @bartonjs for triage

@bartonjs bartonjs added help wanted [up-for-grabs] Good issue for external contributors Priority:3 Work that is nice to have labels Jan 16, 2025
@bartonjs bartonjs added this to the Future milestone Jan 16, 2025
@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Jan 16, 2025
@bartonjs
Copy link
Member

Given that everything is working (and matches .NET Framework), this isn't really important.

But, if someone wants to go clean it up, correcting the nullability annotations on the field and the property may help someone in the future.

While changing the nullability annotations will edit the .ref.cs file, no API Review is required for adding a ? where null is already being returned.

If there isn't already a test that shows it's null by default (which will probably require using RemoteExecutor), one should probably be added with the change.

@bartonjs bartonjs removed their assignment Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Security help wanted [up-for-grabs] Good issue for external contributors Priority:3 Work that is nice to have
Projects
None yet
Development

No branches or pull requests

4 participants