Skip to content

Commit 56d54d4

Browse files
Merge pull request #11907 from umbraco/v8/feature/allowlist-for-help-page
V8: Add allowlist for HelpPage
2 parents d70a207 + 9dbe2d2 commit 56d54d4

File tree

7 files changed

+61
-0
lines changed

7 files changed

+61
-0
lines changed

src/Umbraco.Core/ConfigsExtensions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Umbraco.Core.Configuration.HealthChecks;
66
using Umbraco.Core.Configuration.UmbracoSettings;
77
using Umbraco.Core.Dashboards;
8+
using Umbraco.Core.Help;
89
using Umbraco.Core.IO;
910
using Umbraco.Core.Logging;
1011
using Umbraco.Core.Manifest;
@@ -50,6 +51,8 @@ public static void AddCoreConfigs(this Configs configs)
5051
factory.GetInstance<IRuntimeState>().Debug));
5152

5253
configs.Add<IContentDashboardSettings>(() => new ContentDashboardSettings());
54+
55+
configs.Add<IHelpPageSettings>(() => new HelpPageSettings());
5356
}
5457
}
5558
}

src/Umbraco.Core/Constants-AppSettings.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ public static class AppSettings
125125
/// </summary>
126126
public const string ContentDashboardUrlAllowlist = "Umbraco.Core.ContentDashboardUrl-Allowlist";
127127

128+
/// <summary>
129+
/// A list of allowed addresses to fetch content for the help page.
130+
/// </summary>
131+
public const string HelpPageUrlAllowList = "Umbraco.Core.HelpPage-Allowlist";
132+
128133
/// <summary>
129134
/// TODO: FILL ME IN
130135
/// </summary>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System.Configuration;
2+
3+
namespace Umbraco.Core.Help
4+
{
5+
public class HelpPageSettings : IHelpPageSettings
6+
{
7+
public string HelpPageUrlAllowList =>
8+
ConfigurationManager.AppSettings.ContainsKey(Constants.AppSettings.HelpPageUrlAllowList)
9+
? ConfigurationManager.AppSettings[Constants.AppSettings.HelpPageUrlAllowList]
10+
: null;
11+
}
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace Umbraco.Core.Help
2+
{
3+
public interface IHelpPageSettings
4+
{
5+
/// <summary>
6+
/// Gets the allowed addresses to retrieve data for the help page.
7+
/// </summary>
8+
string HelpPageUrlAllowList { get; }
9+
}
10+
}

src/Umbraco.Core/Umbraco.Core.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@
137137
<Compile Include="Constants-Sql.cs" />
138138
<Compile Include="Constants-SqlTemplates.cs" />
139139
<Compile Include="Events\UnattendedInstallEventArgs.cs" />
140+
<Compile Include="Help\HelpPageSettings.cs" />
141+
<Compile Include="Help\IHelpPageSettings.cs" />
140142
<Compile Include="Logging\ILogger2.cs" />
141143
<Compile Include="Logging\Logger2Extensions.cs" />
142144
<Compile Include="Dashboards\ContentDashboardSettings.cs" />

src/Umbraco.Web.UI/web.Template.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
<add key="Umbraco.Core.UseHttps" value="false" />
4040
<add key="Umbraco.Core.AllowContentDashboardAccessToAllUsers" value="true"/>
4141
<add key="Umbraco.Core.ContentDashboardUrl-Allowlist" value=""/>
42+
<add key="Umbraco.Core.HelpPage-Allowlist" value=""/>
4243

4344
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
4445
<add key="webpages:Enabled" value="false" />

src/Umbraco.Web/Editors/HelpController.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,33 @@
11
using Newtonsoft.Json;
22
using System.Collections.Generic;
3+
using System.Net;
34
using System.Net.Http;
45
using System.Runtime.Serialization;
56
using System.Threading.Tasks;
7+
using System.Web.Http;
8+
using Umbraco.Core.Help;
9+
using Umbraco.Core.Logging;
610

711
namespace Umbraco.Web.Editors
812
{
913
public class HelpController : UmbracoAuthorizedJsonController
1014
{
15+
private readonly IHelpPageSettings _helpPageSettings;
16+
17+
public HelpController(IHelpPageSettings helpPageSettings)
18+
{
19+
_helpPageSettings = helpPageSettings;
20+
}
21+
1122
private static HttpClient _httpClient;
1223
public async Task<List<HelpPage>> GetContextHelpForPage(string section, string tree, string baseUrl = "https://our.umbraco.com")
1324
{
25+
if (IsAllowedUrl(baseUrl) is false)
26+
{
27+
Logger.Error<HelpController>($"The following URL is not listed in the allowlist for HelpPage in web.config: {baseUrl}");
28+
throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "HelpPage source not permitted"));
29+
}
30+
1431
var url = string.Format(baseUrl + "/Umbraco/Documentation/Lessons/GetContextHelpDocs?sectionAlias={0}&treeAlias={1}", section, tree);
1532

1633
try
@@ -33,6 +50,17 @@ public async Task<List<HelpPage>> GetContextHelpForPage(string section, string t
3350

3451
return new List<HelpPage>();
3552
}
53+
54+
private bool IsAllowedUrl(string url)
55+
{
56+
if (string.IsNullOrEmpty(_helpPageSettings.HelpPageUrlAllowList) ||
57+
_helpPageSettings.HelpPageUrlAllowList.Contains(url))
58+
{
59+
return true;
60+
}
61+
62+
return false;
63+
}
3664
}
3765

3866
[DataContract(Name = "HelpPage")]

0 commit comments

Comments
 (0)