Compare commits

...
Author SHA1 Message Date
d60137e6da Merge commit from fork
* Ensure preview can only be requested with a valid culture code.

* Update src/Umbraco.Web.BackOffice/Controllers/PreviewController.cs

Co-authored-by: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com>

* Restricted to predefined culture codes.

---------

Co-authored-by: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com>
2025-01-20 14:14:28 +01:00
Andy Butland 9f9c88781a Bumped version to 10.8.8. 2025-01-07 10:08:01 +01:00
3 changed files with 33 additions and 2 deletions
@@ -1,3 +1,4 @@
using System.Globalization;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ViewEngines;
@@ -130,6 +131,11 @@ public class PreviewController : Controller
[Authorize(Policy = AuthorizationPolicies.BackOfficeAccess)]
public ActionResult Frame(int id, string culture)
{
if (ValidateProvidedCulture(culture) is false)
{
throw new InvalidOperationException($"Could not recognise the provided culture: {culture}");
}
EnterPreview(id);
// use a numeric URL because content may not be in cache and so .Url would fail
@@ -138,6 +144,28 @@ public class PreviewController : Controller
return RedirectPermanent($"../../{id}{query}");
}
private static bool ValidateProvidedCulture(string culture)
{
if (string.IsNullOrEmpty(culture))
{
return true;
}
// We can be confident the backoffice will have provided a valid culture in linking to the
// preview, so we don't need to check that the culture matches an Umbraco language.
// We are only concerned here with protecting against XSS attacks from a fiddled preview
// URL, so we can just confirm we have a valid culture.
try
{
CultureInfo.GetCultureInfo(culture, true);
return true;
}
catch (CultureNotFoundException)
{
return false;
}
}
public ActionResult? EnterPreview(int id)
{
IUser? user = _backofficeSecurityAccessor.BackOfficeSecurity?.CurrentUser;
@@ -141,7 +141,10 @@ public abstract class UmbracoViewPage<TModel> : RazorPage<TModel>
string.Format(
ContentSettings.PreviewBadge,
HostingEnvironment.ToAbsolute(GlobalSettings.UmbracoPath),
Context.Request.GetEncodedUrl(),
System.Web.HttpUtility.HtmlEncode(Context.Request.GetEncodedUrl()), // Belt and braces - via a browser at least it doesn't seem possible to have anything other than
// a valid culture code provided in the querystring of this URL.
// But just to be sure of prevention of an XSS vulnterablity we'll HTML encode here too.
// An expected URL is untouched by this encoding.
UmbracoContext.PublishedRequest?.PublishedContent?.Id);
}
else
+1 -1
View File
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "10.8.7",
"version": "10.8.8",
"assemblyVersion": {
"precision": "build"
},