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

Fix invalid cookie name caused by parenthesis in path name #11489

Closed

Conversation

jardg
Copy link
Contributor

@jardg jardg commented Apr 4, 2022

Hi when the root path is a in a Windows directory that contains parenthesis I get the following antiforgery error
Error

I believe his happens since the project upgraded to a .NET Core version that no longer scapes characters in the antiforgery cookie (3 or 5 I don't remember the version). I encounter this error while deploying release version on Windows Server or while developing with Visual Studio when the project is inside a folder with parenthesis.

Repro steps:

  1. Download OrchardCore project in a folder with parenthesis(or a parent folder) and launch OrchardCore.Cms.Web project. Then the error appears inmediately in the setup screen.

This pr fixes this error. I don't know if it could be more problematic characters since HttpUtility.UrlEncode method can get rid of them.

@@ -312,7 +312,7 @@ private static void AddAntiForgery(OrchardCoreBuilder builder)
var settings = serviceProvider.GetRequiredService<ShellSettings>();
var environment = serviceProvider.GetRequiredService<IHostEnvironment>();

var cookieName = "orchantiforgery_" + HttpUtility.UrlEncode(settings.Name + environment.ContentRootPath);
var cookieName = "orchantiforgery_" + HttpUtility.UrlEncode(settings.Name + environment.ContentRootPath.Replace("(", "").Replace(")", ""));
Copy link
Member

Choose a reason for hiding this comment

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

Can we define a static array of the invalid characters, then we can remove them from ContentRootPath

Copy link
Contributor

@Skrypt Skrypt Apr 4, 2022

Choose a reason for hiding this comment

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

Let's use the slugify method here. It will do "that".

Copy link
Contributor

@Skrypt Skrypt Apr 4, 2022

Choose a reason for hiding this comment

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

Hmm, ISlugService and SlugService should be moved somewhere else than the OrchardCore.Liquid module.

Copy link
Contributor Author

@jardg jardg Apr 4, 2022

Choose a reason for hiding this comment

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

Sure. This approach is way better and scapes all the characters

@@ -312,7 +312,7 @@ private static void AddAntiForgery(OrchardCoreBuilder builder)
var settings = serviceProvider.GetRequiredService<ShellSettings>();
var environment = serviceProvider.GetRequiredService<IHostEnvironment>();

var cookieName = "orchantiforgery_" + HttpUtility.UrlEncode(settings.Name + environment.ContentRootPath);
var cookieName = "orchantiforgery_" + HttpUtility.UrlEncode(settings.Name + environment.ContentRootPath.Replace("(", "").Replace(")", ""));
Copy link
Member

@sebastienros sebastienros Apr 12, 2022

Choose a reason for hiding this comment

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

I think the issue is with the encoding logic, UrlEncode is apparently not adapted. Base64 or Uri.EscapeDataString (something close).

Also we can use a Guid.ToString("N") instead of the ContentRootPath.
Details: #5803

@jardg jardg deleted the jardg-hotfix-antiforgery-rootpath branch April 18, 2022 08:39
sebastienros added a commit that referenced this pull request Jun 9, 2022
Skrypt added a commit that referenced this pull request Sep 22, 2022
# Conflicts:
#	OrchardCore.sln
#	src/OrchardCore/OrchardCore.Queries.Abstractions/LuceneQueryResults.cs
Skrypt added a commit that referenced this pull request Oct 8, 2022
Skrypt added a commit that referenced this pull request Oct 12, 2022
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.

4 participants