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 · 2 comments
Open

Self-assignment instead of delegate creation #111031

PetSerAl opened this issue Jan 2, 2025 · 2 comments
Labels
area-System.Security untriaged New issue has not been triaged by the area owner

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>?.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Security untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

2 participants