Description
ASP.NET Core treats AllowAnyOrigin() with AllowCredentials() as an invalid CORS policy. Using SetIsOriginAllowed(_ => true) instead allows any origin to read the response to a request sent with credentials.
Potential impact
An untrusted site can read account data if the browser sends the user’s authentication cookie. Cookie delivery depends on client settings, SameSite and browser policy.
Remediation
Use WithOrigins to list each trusted frontend’s exact scheme, host and port. Enable AllowCredentials() only when needed, and authenticate and authorize each request on the server.
Examples
Each excerpt configures a separate CorsPolicyBuilder. Policy registration and endpoint application are omitted.
Before
policy.SetIsOriginAllowed(_ => true).AllowCredentials();
After
policy.WithOrigins("https://app.example.com").AllowCredentials();
This policy permits credentialed cross-origin reads only from https://app.example.com.