Skip to content

Commit

Permalink
Fix for umbraco#9950 - HttpsCheck will now retry using the login back…
Browse files Browse the repository at this point in the history
…ground image if inital request returns 301/302. Excessvie Headers check will now check the root url instead of the backoffice
  • Loading branch information
Jeavon committed Mar 9, 2021
1 parent 4916c64 commit 4719417
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private HealthCheckStatus CheckForHeaders()
{
var message = string.Empty;
var success = false;
var url = _runtime.ApplicationUrl;
var url = _runtime.ApplicationUrl.GetLeftPart(UriPartial.Authority);

// Access the site home page and check for the headers
var request = WebRequest.Create(url);
Expand All @@ -69,7 +69,7 @@ private HealthCheckStatus CheckForHeaders()
}
catch (Exception ex)
{
message = _textService.Localize("healthcheck/httpsCheckInvalidUrl", new[] { url.ToString(), ex.Message });
message = _textService.Localize("healthcheck/healthCheckInvalidUrl", new[] { url.ToString(), ex.Message });
}

var actions = new List<HealthCheckAction>();
Expand Down
21 changes: 18 additions & 3 deletions src/Umbraco.Web/HealthCheck/Checks/Security/HttpsCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using System.Collections.Generic;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Web;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.IO;
using Umbraco.Core.Services;
using Umbraco.Web.HealthCheck.Checks.Config;
Expand All @@ -21,14 +21,16 @@ public class HttpsCheck : HealthCheck
private readonly ILocalizedTextService _textService;
private readonly IRuntimeState _runtime;
private readonly IGlobalSettings _globalSettings;
private readonly IContentSection _contentSection;

private const string FixHttpsSettingAction = "fixHttpsSetting";

public HttpsCheck(ILocalizedTextService textService, IRuntimeState runtime, IGlobalSettings globalSettings)
public HttpsCheck(ILocalizedTextService textService, IRuntimeState runtime, IGlobalSettings globalSettings, IContentSection contentSection)
{
_textService = textService;
_runtime = runtime;
_globalSettings = globalSettings;
_contentSection = contentSection;
}

/// <summary>
Expand Down Expand Up @@ -65,12 +67,25 @@ private HealthCheckStatus CheckForValidCertificate()
// Attempt to access the site over HTTPS to see if it HTTPS is supported
// and a valid certificate has been configured
var url = _runtime.ApplicationUrl.ToString().Replace("http:", "https:");

var request = (HttpWebRequest) WebRequest.Create(url);
request.Method = "HEAD";
request.AllowAutoRedirect = false;

try
{

var response = (HttpWebResponse)request.GetResponse();

// Check for 301/302 as a external login provider such as UmbracoID might be in use
if (response.StatusCode == HttpStatusCode.Moved || response.StatusCode == HttpStatusCode.Redirect)
{
// Reset request to use the static login background image
var absoluteLoginBackgroundImage = $"{url}/{_contentSection.LoginBackgroundImage}";

request = (HttpWebRequest)WebRequest.Create(absoluteLoginBackgroundImage);
response = (HttpWebResponse)request.GetResponse();
}

if (response.StatusCode == HttpStatusCode.OK)
{
// Got a valid response, check now for if certificate expiring within 14 days
Expand Down

0 comments on commit 4719417

Please sign in to comment.