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

EnsureUser fails in anonymous http context #240

Open
Vice93 opened this issue Apr 3, 2024 · 3 comments
Open

EnsureUser fails in anonymous http context #240

Vice93 opened this issue Apr 3, 2024 · 3 comments
Assignees

Comments

@Vice93
Copy link

Vice93 commented Apr 3, 2024

Hello.

We are running a multi-webapp SPFarm with various ISAPI calls between themselves. These calls (backend 2 backend) are unable to authenticate properly in SharePoint, resulting in an anonymous SPContext / HttpContext.

This leads to several issues in SharePoint, but also one in EntraCP. Take a look at the following code:

ClaimsProviderConstants.cs#234:

    HttpContext httpctx = HttpContext.Current;
    if (httpctx != null)
    {
    	WIF4_5.ClaimsPrincipal cp = httpctx.User as WIF4_5.ClaimsPrincipal;
    	if (cp != null)
    	{
    		if (SPClaimProviderManager.IsEncodedClaim(cp.Identity.Name))
    		{
    			this.UserInHttpContext = SPClaimProviderManager.Local.DecodeClaimFromFormsSuffix(cp.Identity.Name);
    		}
    		else
    		{
    			// This code is reached only when called from central administration: current user is always a Windows user
    			this.UserInHttpContext = SPClaimProviderManager.Local.ConvertIdentifierToClaim(cp.Identity.Name, SPIdentifierTypes.WindowsSamAccountName);
    		}
    	}
    }

Here we are checking if HttpContext.Current is null, which it is not. However, cp.Identity.Name is null, resulting in an ArgumentNullException. The current workaround for this is to set HttpContext.Current = null before calling .EnsureUser() such that this code doesnt run.

I think this could be solved by either checking that the context is authenticated (by checking .Identity.Name != null), or removing the code alltogether. UserInHttpContext doesnt seem to be referenced outside these two assignments.

@Yvand Yvand self-assigned this Apr 4, 2024
@Yvand Yvand added the bug label Apr 4, 2024
@Yvand
Copy link
Owner

Yvand commented Apr 4, 2024

@Vice93 thank you for reporting this, indeed this is probably legacy code, I'll fix it soon

Copy link

github-actions bot commented May 7, 2024

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the stale label May 7, 2024
@Yvand Yvand added keep and removed stale labels May 7, 2024
@Yvand
Copy link
Owner

Yvand commented Jun 20, 2024

fixed by 825a80b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants