-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Conversation
@@ -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(")", "")); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(")", "")); |
There was a problem hiding this comment.
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
# Conflicts: # OrchardCore.sln # src/OrchardCore/OrchardCore.Queries.Abstractions/LuceneQueryResults.cs
Hi when the root path is a in a Windows directory that contains parenthesis I get the following antiforgery 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:
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.