Skip to content

Conversation

@hishamco
Copy link
Member

Fixes #18552

@hishamco
Copy link
Member Author

Seems we need to add another check if the Cors set from appsettings.json, @Piedone, I think logging a warning is enough in this case, or shall we throw an exception coz it will break the site

@hishamco
Copy link
Member Author

FYI the current implementation shows

Specifying AllowAnyOrigin and AllowCredentias is an insecure configuration and can result in cross-site request forgery. The CORS service returns an invalid CORS response when an app is configured with both methods.
Affected policies: New policy

but still accepts the input and the exception throws in the next request

@hishamco
Copy link
Member Author

@rjpowers10 could please confirm

@Piedone
Copy link
Member

Piedone commented Nov 15, 2025

Please see #18552 (comment).

@hishamco
Copy link
Member Author

it reverts." feature

Which feature do you refer to?

@Piedone
Copy link
Member

Piedone commented Nov 15, 2025

image

Copy link
Member

@Piedone Piedone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This displays a warning when the offending configuration is saved, but saves the values. Instead, it should add a validation error and prevent saving the value in the first place.

@sebastienros
Copy link
Member

@rjpowers10 please comment on the PR

@rjpowers10
Copy link
Contributor

I added a few minor comments but the validation change is what I was expecting.

@Piedone
Copy link
Member

Piedone commented Nov 20, 2025

Did you submit your comments? Because nothing appears for me here.

@hishamco hishamco requested a review from rjpowers10 November 20, 2025 22:01
@hishamco
Copy link
Member Author

Is there anything else to add here, or shall we merge this?

@Piedone
Copy link
Member

Piedone commented Nov 21, 2025

I'd appreciate if before these questions you'd please take a look at what the reviewer has written; it's a recurring theme that I come back with links to my prior comments. Because no, we shouldn't merge this until you address my comment here: #18554 (review). Please take a look.

@hishamco
Copy link
Member Author

I got an approval from @rjpowers10; moreover, there's a reason that prevents me from achieving this easily, because the UI is controlled at the client-side. Let me revise this PR again

@hishamco
Copy link
Member Author

@Piedone, as I said, the form relies on client-side, also the policies are not preserved until policyWarnings.Count == 0 satisfied

You could give it a try

@Piedone
Copy link
Member

Piedone commented Nov 22, 2025

Well, then something needs to change because this is really confusing UX.

BTW the wrong configuration is the default when you add a new policy. Please also remove that footgun.

@Piedone
Copy link
Member

Piedone commented Nov 22, 2025

I just noticed:

if (corsPolicy.AllowCredentials && corsPolicy.AllowAnyOrigin)
{
_logger.LogWarning("Using AllowCredentials and AllowAnyOrigin at the same time is considered a security risk, the {PolicyName} policy will not be loaded.", corsPolicy.Name);
continue;
}

Apparently, this isn't working well enough. This is what needs to be fixed.

@hishamco
Copy link
Member Author

Well, then something needs to change because this is really confusing UX.

That's why I show the warning on the UI to let the user know there's something that needs attention

BTW the wrong configuration is the default when you add a new policy. Please also remove that footgun.

Did you mean to check if there's a wrong configuration in the appsettings.json file? coz the UI will prevent this issue

@Piedone
Copy link
Member

Piedone commented Nov 22, 2025

That's why I show the warning on the UI to let the user know there's something that needs attention

Saving (seemingly) the policy while showing a warning that it's wrong and you shouldn't do that is confusing UX.

Did you mean to check if there's a wrong configuration in the appsettings.json file? coz the UI will prevent this issue

Add a policy, leave everything on default, Save, notice warning. The defaults are wrong.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid CORS config can make the site unusable

5 participants