Errors when using illegal characters in the URL


Description

Sitecore may throw the following errors instead of redirecting to the “Item Not Found” page when a request that contains illegal characters in the path is sent to the server (e.g. http://<hostname>/somepath"/default.aspx).

Error 1:

[ArgumentException: Illegal characters in path.]
   System.IO.Path.CheckInvalidPathChars(String path)
   System.IO.Path.GetExtension(String path)
   Sitecore.Web.RequestFilter.GetExtension(HttpRequest request)
   Sitecore.Web.RequestFilter.IsBlocked(HttpRequest request)
   Sitecore.Web.RequestFilter.Process(HttpRequest request, HttpResponse response, Boolean& blocked, Boolean& sitecoreOn)
   Sitecore.Pipelines.PreprocessRequest.FilterUrlExtensions.Process(PreprocessRequestArgs args)
   ...

Error 2:

[ArgumentException: Illegal characters in path.]
   System.IO.Path.CheckInvalidPathChars(String path)
   System.IO.Path.GetExtension(String path)
   Sitecore.IO.FileUtil.GetExtension(String path)
   Sitecore.Pipelines.HttpRequest.BeginDiagnostics.Process(HttpRequestArgs args)
   ...

Error 3:

[ArgumentException: Illegal characters in path.]
   System.IO.Path.GetExtension(String path)
   Sitecore.IO.FileUtil.GetExtension(String path)
   Sitecore.Web.RewriteModule.ShouldRequestBeSkipped(HttpRequest request)
   Sitecore.Web.RewriteModule.SaveAndRevertPath(HttpApplication app, String fromKey, String toKey)
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
   ...

Error 4:

[ArgumentException: Illegal characters in path.]
   System.IO.Path.GetExtension(String path)
   Sitecore.IO.FileUtil.GetExtension(String path)
   Sitecore.Pipelines.HttpRequest.EndDiagnostics.Process(HttpRequestArgs args)
   (Object , Object[] )
   Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
   Sitecore.Nexus.Web.HttpModule.(Object , EventArgs )
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
   ...

Solution

If you want to perform redirection to the “Item Not Found” page instead of showing exceptions, please do the following:

  1. Place the Sitecore.Support.388283.388284.dll assembly into the /bin folder.
  2. Insert the following line as the first line after the <modules> and <httpModules> lines in the web.config file:
    <add type="Sitecore.Support.IllegalCharactersChecker, Sitecore.Support.388283.388284" name="IllegalCharactersCheckerModule" />
  3. Modify the web.config file and replace the following line:
    <processor type="Sitecore.Pipelines.HttpRequest.EndDiagnostics, Sitecore.Kernel" />
    with the following:
    <processor type="Sitecore.Support.Pipelines.HttpRequest.EndDiagnostics, Sitecore.Support.388283.388284" />