Skip to content

Commit c3625ae

Browse files
Jeavonmikecp
authored andcommitted
Fix the basehttpheader so that it's checking the root of the domain instead of /umbraco
1 parent b046098 commit c3625ae

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/Umbraco.Web/HealthCheck/Checks/Security/BaseHttpHeaderCheck.cs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ namespace Umbraco.Web.HealthCheck.Checks.Security
1414
{
1515
public abstract class BaseHttpHeaderCheck : HealthCheck
1616
{
17-
protected IRuntimeState Runtime { get; }
18-
protected ILocalizedTextService TextService { get; }
17+
private readonly ILocalizedTextService _textService;
18+
private readonly IRuntimeState _runtime;
1919

2020
private const string SetHeaderInConfigAction = "setHeaderInConfig";
2121

@@ -24,14 +24,14 @@ public abstract class BaseHttpHeaderCheck : HealthCheck
2424
private readonly string _localizedTextPrefix;
2525
private readonly bool _metaTagOptionAvailable;
2626

27+
2728
protected BaseHttpHeaderCheck(
2829
IRuntimeState runtime,
2930
ILocalizedTextService textService,
3031
string header, string value, string localizedTextPrefix, bool metaTagOptionAvailable)
3132
{
32-
Runtime = runtime;
33-
TextService = textService ?? throw new ArgumentNullException(nameof(textService));
34-
33+
_runtime = runtime;
34+
_textService = textService ?? throw new ArgumentNullException(nameof(textService));
3535
_header = header;
3636
_value = value;
3737
_localizedTextPrefix = localizedTextPrefix;
@@ -70,7 +70,8 @@ protected HealthCheckStatus CheckForHeader()
7070
var success = false;
7171

7272
// Access the site home page and check for the click-jack protection header or meta tag
73-
var url = Runtime.ApplicationUrl;
73+
var url = _runtime.ApplicationUrl.GetLeftPart(UriPartial.Authority);
74+
7475
var request = WebRequest.Create(url);
7576
request.Method = "GET";
7677
try
@@ -84,24 +85,25 @@ protected HealthCheckStatus CheckForHeader()
8485
if (success == false && _metaTagOptionAvailable)
8586
{
8687
success = DoMetaTagsContainKeyForHeader(response);
88+
8789
}
8890

8991
message = success
90-
? TextService.Localize($"healthcheck", $"{_localizedTextPrefix}CheckHeaderFound")
91-
: TextService.Localize($"healthcheck", $"{_localizedTextPrefix}CheckHeaderNotFound");
92+
? _textService.Localize($"healthcheck", $"{_localizedTextPrefix}CheckHeaderFound")
93+
: _textService.Localize($"healthcheck", $"{_localizedTextPrefix}CheckHeaderNotFound");
9294
}
9395
catch (Exception ex)
9496
{
95-
message = TextService.Localize("healthcheck", "healthCheckInvalidUrl", new[] { url.ToString(), ex.Message });
97+
message = _textService.Localize("healthcheck", "healthCheckInvalidUrl", new[] { url.ToString(), ex.Message });
9698
}
9799

98100
var actions = new List<HealthCheckAction>();
99101
if (success == false)
100102
{
101103
actions.Add(new HealthCheckAction(SetHeaderInConfigAction, Id)
102104
{
103-
Name = TextService.Localize("healthcheck", "setHeaderInConfig"),
104-
Description = TextService.Localize($"healthcheck", $"{_localizedTextPrefix}SetHeaderInConfigDescription")
105+
Name = _textService.Localize("healthcheck", "setHeaderInConfig"),
106+
Description = _textService.Localize($"healthcheck", $"{_localizedTextPrefix}SetHeaderInConfigDescription")
105107
});
106108
}
107109

@@ -149,14 +151,14 @@ private HealthCheckStatus SetHeaderInConfig()
149151
if (success)
150152
{
151153
return
152-
new HealthCheckStatus(TextService.Localize("healthcheck", _localizedTextPrefix + "SetHeaderInConfigSuccess"))
154+
new HealthCheckStatus(_textService.Localize("healthcheck", _localizedTextPrefix + "SetHeaderInConfigSuccess"))
153155
{
154156
ResultType = StatusResultType.Success
155157
};
156158
}
157159

158160
return
159-
new HealthCheckStatus(TextService.Localize("healthcheck", "setHeaderInConfigError", new [] { errorMessage }))
161+
new HealthCheckStatus(_textService.Localize("healthcheck", "setHeaderInConfigError", new [] { errorMessage }))
160162
{
161163
ResultType = StatusResultType.Error
162164
};

0 commit comments

Comments
 (0)