Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Umbraco.Cms.Core.Web;

namespace Umbraco.Cms.Web.Website.ActionResults;

/// <summary>
/// Redirects to the current URL rendering an Umbraco page including it's query strings
/// Redirects to the current URL rendering an Umbraco page, optionally including its query strings
/// </summary>
/// <remarks>
/// This is useful if you need to redirect
Expand All @@ -15,12 +16,22 @@
public class RedirectToUmbracoUrlResult : IKeepTempDataResult
{
private readonly IUmbracoContext _umbracoContext;
private readonly QueryString _queryString;

/// <summary>
/// Initializes a new instance of the <see cref="RedirectToUmbracoUrlResult" /> class.
/// </summary>
public RedirectToUmbracoUrlResult(IUmbracoContext umbracoContext) => _umbracoContext = umbracoContext;

/// <summary>
/// Initializes a new instance of the <see cref="RedirectToUmbracoUrlResult" /> class.
/// </summary>
public RedirectToUmbracoUrlResult(IUmbracoContext umbracoContext, QueryString queryString)
{
_umbracoContext = umbracoContext;
_queryString = queryString;
}

/// <inheritdoc />
public Task ExecuteResultAsync(ActionContext context)
{
Expand All @@ -29,9 +40,14 @@
throw new ArgumentNullException(nameof(context));
}

var destinationUrl = _umbracoContext.OriginalRequestUrl.PathAndQuery;
var destinationUrl = _umbracoContext.OriginalRequestUrl.AbsolutePath;

if (_queryString.HasValue)
{
destinationUrl += _queryString.ToUriComponent();
}

context.HttpContext.Response.Redirect(destinationUrl);

Check warning

Code scanning / CodeQL

URL redirection from remote source Medium

Untrusted URL redirection due to
user-provided value
.

return Task.CompletedTask;
}
Expand Down
6 changes: 6 additions & 0 deletions src/Umbraco.Web.Website/Controllers/SurfaceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ protected RedirectToUmbracoPageResult RedirectToCurrentUmbracoPage(QueryString q
protected RedirectToUmbracoUrlResult RedirectToCurrentUmbracoUrl()
=> new(UmbracoContext);

/// <summary>
/// Redirects to the currently rendered Umbraco URL and passes provided querystring
/// </summary>
protected RedirectToUmbracoUrlResult RedirectToCurrentUmbracoUrl(QueryString queryString)
=> new(UmbracoContext, queryString);

/// <summary>
/// Returns the currently rendered Umbraco page
/// </summary>
Expand Down
Loading