diff --git a/src/Umbraco.Core/ConfigsExtensions.cs b/src/Umbraco.Core/ConfigsExtensions.cs index 25c69899c0..01247cc69e 100644 --- a/src/Umbraco.Core/ConfigsExtensions.cs +++ b/src/Umbraco.Core/ConfigsExtensions.cs @@ -5,6 +5,7 @@ using Umbraco.Core.Configuration.Grid; using Umbraco.Core.Configuration.HealthChecks; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Dashboards; +using Umbraco.Core.Help; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Manifest; @@ -50,6 +51,8 @@ namespace Umbraco.Core factory.GetInstance().Debug)); configs.Add(() => new ContentDashboardSettings()); + + configs.Add(() => new HelpPageSettings()); } } } diff --git a/src/Umbraco.Core/Constants-AppSettings.cs b/src/Umbraco.Core/Constants-AppSettings.cs index 4e5619813e..6a58675e91 100644 --- a/src/Umbraco.Core/Constants-AppSettings.cs +++ b/src/Umbraco.Core/Constants-AppSettings.cs @@ -125,6 +125,11 @@ namespace Umbraco.Core /// public const string ContentDashboardUrlAllowlist = "Umbraco.Core.ContentDashboardUrl-Allowlist"; + /// + /// A list of allowed addresses to fetch content for the help page. + /// + public const string HelpPageUrlAllowList = "Umbraco.Core.HelpPage-Allowlist"; + /// /// TODO: FILL ME IN /// diff --git a/src/Umbraco.Core/Help/HelpPageSettings.cs b/src/Umbraco.Core/Help/HelpPageSettings.cs new file mode 100644 index 0000000000..d2a4a3a0f5 --- /dev/null +++ b/src/Umbraco.Core/Help/HelpPageSettings.cs @@ -0,0 +1,12 @@ +using System.Configuration; + +namespace Umbraco.Core.Help +{ + public class HelpPageSettings : IHelpPageSettings + { + public string HelpPageUrlAllowList => + ConfigurationManager.AppSettings.ContainsKey(Constants.AppSettings.HelpPageUrlAllowList) + ? ConfigurationManager.AppSettings[Constants.AppSettings.HelpPageUrlAllowList] + : null; + } +} diff --git a/src/Umbraco.Core/Help/IHelpPageSettings.cs b/src/Umbraco.Core/Help/IHelpPageSettings.cs new file mode 100644 index 0000000000..5643e47a30 --- /dev/null +++ b/src/Umbraco.Core/Help/IHelpPageSettings.cs @@ -0,0 +1,10 @@ +namespace Umbraco.Core.Help +{ + public interface IHelpPageSettings + { + /// + /// Gets the allowed addresses to retrieve data for the help page. + /// + string HelpPageUrlAllowList { get; } + } +} diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index e27c6eeceb..35948ede91 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -137,6 +137,8 @@ + + diff --git a/src/Umbraco.Web.UI/web.Template.config b/src/Umbraco.Web.UI/web.Template.config index e4e3e19bcb..32e624e400 100644 --- a/src/Umbraco.Web.UI/web.Template.config +++ b/src/Umbraco.Web.UI/web.Template.config @@ -39,6 +39,7 @@ + diff --git a/src/Umbraco.Web/Editors/HelpController.cs b/src/Umbraco.Web/Editors/HelpController.cs index 39dbbc435c..77e1675f87 100644 --- a/src/Umbraco.Web/Editors/HelpController.cs +++ b/src/Umbraco.Web/Editors/HelpController.cs @@ -1,16 +1,33 @@ using Newtonsoft.Json; using System.Collections.Generic; +using System.Net; using System.Net.Http; using System.Runtime.Serialization; using System.Threading.Tasks; +using System.Web.Http; +using Umbraco.Core.Help; +using Umbraco.Core.Logging; namespace Umbraco.Web.Editors { public class HelpController : UmbracoAuthorizedJsonController { + private readonly IHelpPageSettings _helpPageSettings; + + public HelpController(IHelpPageSettings helpPageSettings) + { + _helpPageSettings = helpPageSettings; + } + private static HttpClient _httpClient; public async Task> GetContextHelpForPage(string section, string tree, string baseUrl = "https://our.umbraco.com") { + if (IsAllowedUrl(baseUrl) is false) + { + Logger.Error($"The following URL is not listed in the allowlist for HelpPage in web.config: {baseUrl}"); + throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "HelpPage source not permitted")); + } + var url = string.Format(baseUrl + "/Umbraco/Documentation/Lessons/GetContextHelpDocs?sectionAlias={0}&treeAlias={1}", section, tree); try @@ -33,6 +50,17 @@ namespace Umbraco.Web.Editors return new List(); } + + private bool IsAllowedUrl(string url) + { + if (string.IsNullOrEmpty(_helpPageSettings.HelpPageUrlAllowList) || + _helpPageSettings.HelpPageUrlAllowList.Contains(url)) + { + return true; + } + + return false; + } } [DataContract(Name = "HelpPage")]