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

Bad Request - Request Too Long, HTTP Error 400. The size of the request is too long. #59771

Open
1 task done
barnwalv opened this issue Jan 8, 2025 · 11 comments
Open
1 task done
Labels
needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically

Comments

@barnwalv
Copy link

barnwalv commented Jan 8, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I have an ASP.NET Core MVC 5 web application where I have implemented Azure AD SSO. I am trying to login with company account and soon after the authentication a white page appears with Bad Request - Request Too Long message.
When I checked the cookies there are cookies stored under developer tools Chrome under Application tab I found 4 chunks of cookies of size 4008 and one of 27.

I have around 95 Azure App Registrations App roles which has been mapped to user. And the few roles is coming as a claim around 35-40 roles and If I increased map of more app roles to user from Enterprise Application then above error start coming.

What I understand and observed is that If I map up to 35/40 app roles from Azure Enterprise Application to a user then all works good, and when I mapped more app roles says after 40 then the error start coming up.

In my startup.cs file, I'm using
services.AddMicrosoftIdentityWebAuthentication(Configuration).EnableTokenAcquistionToCallDownstreamApi().AddInMemoryTokenCaches();

Troubleshooting Steps which I followed before coming here:

  • I marked groupMembershipClaims from App Manifest to null and also SecurityGroup both but it doesn't work.
  • I tried to increased the request header size from code maxRequestHeaderSize to 73728000.
  • I tried to increased the options.Limits.MaxRequestHeadersTotalSize but still doesn't work.
  • I don't want any optional claims.

Expected Behavior

The authentication should be passed and page should be rendered.

Steps To Reproduce

Build a sample application ASP.NET Core MVC 5 and implement Azure AD SSO with above code in startup.cs file for Auth and mapped 100 app roles to a user and try to sign it.

Exceptions (if any)

No response

.NET Version

5.0

Anything else?

VS 2022

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically label Jan 8, 2025
@martincostello
Copy link
Member

.NET 5 has been out of support since May 2022 - you should upgrade to .NET 8 or 9 and see if your issue is resolved.

@barnwalv
Copy link
Author

barnwalv commented Jan 8, 2025

@martincostello its an large application it can't be moved immediately to newer versions. But it would be great to get any support on this.

@martincostello
Copy link
Member

That may be true, but officially you've been out support for over 2 and a half years and are missing lots of important security patches as a consequence.

@barnwalv
Copy link
Author

barnwalv commented Jan 8, 2025

Does this mean I will not get any support for this?

@martincostello
Copy link
Member

I'll leave the ASP.NET Core team to answer that (I just help triage issues), but from the .NET and .NET Core Support Policy:

.NET releases are supported — during the servicing period — according to the following policies. Servicing policies are the same for LTS and STS releases.

Updates are cumulative and released as patches, with each update built upon all of the updates that preceded it. A device needs to install the latest update to remain supported.

@barnwalv
Copy link
Author

barnwalv commented Jan 8, 2025

how to tag ASP.NET Core team?

@martincostello
Copy link
Member

They'll see this issue.

@barnwalv
Copy link
Author

barnwalv commented Jan 8, 2025

@martincostello thanks!

@barnwalv
Copy link
Author

barnwalv commented Jan 8, 2025

@blowdart / @analogrelay can you plz help here.

@blowdart
Copy link
Contributor

blowdart commented Jan 8, 2025

Nope, I'll leave it to the aspnet team

But as the security PM I will point out, as has already been mentioned, you are long outside .NET 5's support lifetime and haven't been getting security updates for a concerning amount of time.

Expecting to get such a large amount of group claims from AAD/Entra is what is causing the problem and it's a limitation of Entra. It's why you have the ability in Entra to limit the group / claim information to the groups that directly apply to your application. Wanting such a large amount indicates an architecture problem rather than an aspnet problem IMO. You could use claims enhancement to make a call to the AAD user information endpoint to supplement the role claim if you feel you need such a large authentication ticket.

Our policy is that in order to get support you must update to a supported runtime.

@barnwalv
Copy link
Author

barnwalv commented Jan 8, 2025

@blowdart I'm not expecting nor even configured token configuration in Azure App Registration to return any AD groups or roles as a claim, I don't need any such claims. The only issue is that by default the roles claims is added http://schemas.microsoft.com/ws/2008/06/identity/claims/role and these roles is in large.

I don't need these claim and it is all adding by default and creating unwanted cookies and increasing its size and getting a trouble with Request header size is too large.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically
Projects
None yet
Development

No branches or pull requests

3 participants