Skip to content

Commit acaece6

Browse files
authored
[v9] Fix the basehttpheader health check so that it's checking the root of the domain instead of the /umbraco path (#11535)
* Fix the basehttpheader health check so that it's checking the root of the domain instead of the /umbraco path. * Remove unused value from security health checks (it was used in v8 for fixing)
1 parent dfdb498 commit acaece6

File tree

6 files changed

+17
-25
lines changed

6 files changed

+17
-25
lines changed

src/Umbraco.Core/HealthChecks/Checks/Security/BaseHttpHeaderCheck.cs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Umbraco.
1+
// Copyright (c) Umbraco.
22
// See LICENSE for more details.
33

44
using System;
@@ -20,8 +20,8 @@ namespace Umbraco.Cms.Core.HealthChecks.Checks.Security
2020
public abstract class BaseHttpHeaderCheck : HealthCheck
2121
{
2222
private readonly IHostingEnvironment _hostingEnvironment;
23+
private readonly ILocalizedTextService _textService;
2324
private readonly string _header;
24-
private readonly string _value;
2525
private readonly string _localizedTextPrefix;
2626
private readonly bool _metaTagOptionAvailable;
2727
private static HttpClient s_httpClient;
@@ -33,26 +33,18 @@ protected BaseHttpHeaderCheck(
3333
IHostingEnvironment hostingEnvironment,
3434
ILocalizedTextService textService,
3535
string header,
36-
string value,
3736
string localizedTextPrefix,
3837
bool metaTagOptionAvailable)
3938
{
40-
LocalizedTextService = textService ?? throw new ArgumentNullException(nameof(textService));
39+
_textService = textService ?? throw new ArgumentNullException(nameof(textService));
4140
_hostingEnvironment = hostingEnvironment;
4241
_header = header;
43-
_value = value;
4442
_localizedTextPrefix = localizedTextPrefix;
4543
_metaTagOptionAvailable = metaTagOptionAvailable;
4644
}
4745

4846
private static HttpClient HttpClient => s_httpClient ??= new HttpClient();
4947

50-
51-
/// <summary>
52-
/// Gets the localized text service.
53-
/// </summary>
54-
protected ILocalizedTextService LocalizedTextService { get; }
55-
5648
/// <summary>
5749
/// Gets a link to an external read more page.
5850
/// </summary>
@@ -79,7 +71,7 @@ protected async Task<HealthCheckStatus> CheckForHeader()
7971
var success = false;
8072

8173
// Access the site home page and check for the click-jack protection header or meta tag
82-
Uri url = _hostingEnvironment.ApplicationMainUrl;
74+
var url = _hostingEnvironment.ApplicationMainUrl.GetLeftPart(UriPartial.Authority);
8375

8476
try
8577
{
@@ -95,12 +87,12 @@ protected async Task<HealthCheckStatus> CheckForHeader()
9587
}
9688

9789
message = success
98-
? LocalizedTextService.Localize($"healthcheck", $"{_localizedTextPrefix}CheckHeaderFound")
99-
: LocalizedTextService.Localize($"healthcheck", $"{_localizedTextPrefix}CheckHeaderNotFound");
90+
? _textService.Localize($"healthcheck", $"{_localizedTextPrefix}CheckHeaderFound")
91+
: _textService.Localize($"healthcheck", $"{_localizedTextPrefix}CheckHeaderNotFound");
10092
}
10193
catch (Exception ex)
10294
{
103-
message = LocalizedTextService.Localize("healthcheck","healthCheckInvalidUrl", new[] { url.ToString(), ex.Message });
95+
message = _textService.Localize("healthcheck","healthCheckInvalidUrl", new[] { url.ToString(), ex.Message });
10496
}
10597

10698
return

src/Umbraco.Core/HealthChecks/Checks/Security/ClickJackingCheck.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Umbraco.
1+
// Copyright (c) Umbraco.
22
// See LICENSE for more details.
33

44
using Umbraco.Cms.Core.Hosting;
@@ -20,7 +20,7 @@ public class ClickJackingCheck : BaseHttpHeaderCheck
2020
/// Initializes a new instance of the <see cref="ClickJackingCheck"/> class.
2121
/// </summary>
2222
public ClickJackingCheck(IHostingEnvironment hostingEnvironment, ILocalizedTextService textService)
23-
: base(hostingEnvironment, textService, "X-Frame-Options", "sameorigin", "clickJacking", true)
23+
: base(hostingEnvironment, textService, "X-Frame-Options", "clickJacking", true)
2424
{
2525
}
2626

src/Umbraco.Core/HealthChecks/Checks/Security/ExcessiveHeadersCheck.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Umbraco.
1+
// Copyright (c) Umbraco.
22
// See LICENSE for more details.
33

44
using System;
@@ -53,7 +53,7 @@ private async Task<HealthCheckStatus> CheckForHeaders()
5353
{
5454
string message;
5555
var success = false;
56-
var url = _hostingEnvironment.ApplicationMainUrl.GetLeftPart(UriPartial.Authority);;
56+
var url = _hostingEnvironment.ApplicationMainUrl.GetLeftPart(UriPartial.Authority);
5757

5858
// Access the site home page and check for the headers
5959
var request = new HttpRequestMessage(HttpMethod.Head, url);

src/Umbraco.Core/HealthChecks/Checks/Security/HstsCheck.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Umbraco.
1+
// Copyright (c) Umbraco.
22
// See LICENSE for more details.
33

44
using Umbraco.Cms.Core.Hosting;
@@ -27,7 +27,7 @@ public class HstsCheck : BaseHttpHeaderCheck
2727
/// but then you should include subdomains and I wouldn't suggest to do that for Umbraco-sites.
2828
/// </remarks>
2929
public HstsCheck(IHostingEnvironment hostingEnvironment, ILocalizedTextService textService)
30-
: base(hostingEnvironment, textService, "Strict-Transport-Security", "max-age=10886400", "hSTS", true)
30+
: base(hostingEnvironment, textService, "Strict-Transport-Security", "hSTS", true)
3131
{
3232
}
3333

src/Umbraco.Core/HealthChecks/Checks/Security/NoSniffCheck.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Umbraco.
1+
// Copyright (c) Umbraco.
22
// See LICENSE for more details.
33

44
using Umbraco.Cms.Core.Hosting;
@@ -20,7 +20,7 @@ public class NoSniffCheck : BaseHttpHeaderCheck
2020
/// Initializes a new instance of the <see cref="NoSniffCheck"/> class.
2121
/// </summary>
2222
public NoSniffCheck(IHostingEnvironment hostingEnvironment, ILocalizedTextService textService)
23-
: base(hostingEnvironment, textService, "X-Content-Type-Options", "nosniff", "noSniff", false)
23+
: base(hostingEnvironment, textService, "X-Content-Type-Options", "noSniff", false)
2424
{
2525
}
2626

src/Umbraco.Core/HealthChecks/Checks/Security/XssProtectionCheck.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Umbraco.
1+
// Copyright (c) Umbraco.
22
// See LICENSE for more details.
33

44
using Umbraco.Cms.Core.Hosting;
@@ -27,7 +27,7 @@ public class XssProtectionCheck : BaseHttpHeaderCheck
2727
/// but then you should include subdomains and I wouldn't suggest to do that for Umbraco-sites.
2828
/// </remarks>
2929
public XssProtectionCheck(IHostingEnvironment hostingEnvironment, ILocalizedTextService textService)
30-
: base(hostingEnvironment, textService, "X-XSS-Protection", "1; mode=block", "xssProtection", true)
30+
: base(hostingEnvironment, textService, "X-XSS-Protection", "xssProtection", true)
3131
{
3232
}
3333

0 commit comments

Comments
 (0)