1
- using System . Collections . Generic ;
1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Linq ;
4
+ using System . Net ;
2
5
using System . Net . Http ;
3
6
using System . Runtime . Serialization ;
4
7
using System . Threading . Tasks ;
8
+ using Microsoft . Extensions . DependencyInjection ;
5
9
using Microsoft . Extensions . Logging ;
10
+ using Microsoft . Extensions . Options ;
6
11
using Newtonsoft . Json ;
12
+ using Umbraco . Cms . Core . Configuration . Models ;
7
13
using Umbraco . Cms . Web . Common . Attributes ;
14
+ using Umbraco . Cms . Web . Common . DependencyInjection ;
8
15
using Constants = Umbraco . Cms . Core . Constants ;
9
16
10
17
namespace Umbraco . Cms . Web . BackOffice . Controllers
@@ -13,15 +20,44 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
13
20
public class HelpController : UmbracoAuthorizedJsonController
14
21
{
15
22
private readonly ILogger < HelpController > _logger ;
23
+ private HelpPageSettings _helpPageSettings ;
16
24
25
+ [ Obsolete ( "Use constructor that takes IOptions<HelpPageSettings>" ) ]
17
26
public HelpController ( ILogger < HelpController > logger )
27
+ : this ( logger , StaticServiceProvider . Instance . GetRequiredService < IOptionsMonitor < HelpPageSettings > > ( ) )
28
+ {
29
+ }
30
+
31
+ [ ActivatorUtilitiesConstructor ]
32
+ public HelpController (
33
+ ILogger < HelpController > logger ,
34
+ IOptionsMonitor < HelpPageSettings > helpPageSettings )
18
35
{
19
36
_logger = logger ;
37
+
38
+ ResetHelpPageSettings ( helpPageSettings . CurrentValue ) ;
39
+ helpPageSettings . OnChange ( ResetHelpPageSettings ) ;
40
+ }
41
+
42
+ private void ResetHelpPageSettings ( HelpPageSettings settings )
43
+ {
44
+ _helpPageSettings = settings ;
20
45
}
21
46
22
47
private static HttpClient _httpClient ;
48
+
23
49
public async Task < List < HelpPage > > GetContextHelpForPage ( string section , string tree , string baseUrl = "https://our.umbraco.com" )
24
50
{
51
+ if ( IsAllowedUrl ( baseUrl ) is false )
52
+ {
53
+ _logger . LogError ( $ "The following URL is not listed in the allowlist for HelpPage in web.config: { baseUrl } ") ;
54
+ HttpContext . Response . StatusCode = ( int ) HttpStatusCode . BadRequest ;
55
+
56
+ // Ideally we'd want to return a BadRequestResult here,
57
+ // however, since we're not returning ActionResult this is not possible and changing it would be a breaking change.
58
+ return new List < HelpPage > ( ) ;
59
+ }
60
+
25
61
var url = string . Format ( baseUrl + "/Umbraco/Documentation/Lessons/GetContextHelpDocs?sectionAlias={0}&treeAlias={1}" , section , tree ) ;
26
62
27
63
try
@@ -44,6 +80,17 @@ public async Task<List<HelpPage>> GetContextHelpForPage(string section, string t
44
80
45
81
return new List < HelpPage > ( ) ;
46
82
}
83
+
84
+ private bool IsAllowedUrl ( string url )
85
+ {
86
+ if ( _helpPageSettings . HelpPageUrlAllowList is null ||
87
+ _helpPageSettings . HelpPageUrlAllowList . Contains ( url ) )
88
+ {
89
+ return true ;
90
+ }
91
+
92
+ return false ;
93
+ }
47
94
}
48
95
49
96
[ DataContract ( Name = "HelpPage" ) ]
0 commit comments