From eff1b634e42f492731a60c4bdcfdeea6ae078231 Mon Sep 17 00:00:00 2001 From: Jared Goodwin Date: Wed, 1 Feb 2023 20:43:12 -0800 Subject: [PATCH] Add "ForceClientHttps" application option. --- Desktop.Win/Desktop.Win.csproj | 1 + Desktop.Win/app.manifest | 79 +++++++++++++++++++++++++ Server/API/ClientDownloadsController.cs | 14 +++-- Server/Pages/ServerConfig.razor | 7 +++ Server/Pages/ServerConfig.razor.cs | 3 + Server/Services/ApplicationConfig.cs | 2 + Server/appsettings.json | 3 +- 7 files changed, 104 insertions(+), 5 deletions(-) create mode 100644 Desktop.Win/app.manifest diff --git a/Desktop.Win/Desktop.Win.csproj b/Desktop.Win/Desktop.Win.csproj index cac037ca..4a7134ac 100644 --- a/Desktop.Win/Desktop.Win.csproj +++ b/Desktop.Win/Desktop.Win.csproj @@ -18,6 +18,7 @@ AnyCPU;x86;x64 True + app.manifest diff --git a/Desktop.Win/app.manifest b/Desktop.Win/app.manifest new file mode 100644 index 00000000..49e8b2e6 --- /dev/null +++ b/Desktop.Win/app.manifest @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Server/API/ClientDownloadsController.cs b/Server/API/ClientDownloadsController.cs index afcc2899..0d90de90 100644 --- a/Server/API/ClientDownloadsController.cs +++ b/Server/API/ClientDownloadsController.cs @@ -135,7 +135,9 @@ namespace Remotely.Server.API var hostIndex = fileContents.IndexOf("HostName="); var orgIndex = fileContents.IndexOf("Organization="); - fileContents[hostIndex] = $"HostName=\"{Request.Scheme}://{Request.Host}\""; + var effectiveScheme = _appConfig.ForceClientHttps ? "https" : Request.Scheme; + + fileContents[hostIndex] = $"HostName=\"{effectiveScheme}://{Request.Host}\""; fileContents[orgIndex] = $"Organization=\"{organizationId}\""; var fileBytes = Encoding.UTF8.GetBytes(string.Join("\n", fileContents)); return File(fileBytes, "application/octet-stream", fileName); @@ -145,7 +147,8 @@ namespace Remotely.Server.API { LogRequest(nameof(GetDesktopFile)); - var serverUrl = $"{Request.Scheme}://{Request.Host}"; + var effectiveScheme = _appConfig.ForceClientHttps ? "https" : Request.Scheme; + var serverUrl = $"{effectiveScheme}://{Request.Host}"; var embeddedData = new EmbeddedServerData(new Uri(serverUrl), organizationId); var result = await _embeddedDataSearcher.GetRewrittenStream(filePath, embeddedData); @@ -172,8 +175,9 @@ namespace Remotely.Server.API { case "WindowsInstaller": { + var effectiveScheme = _appConfig.ForceClientHttps ? "https" : Request.Scheme; + var serverUrl = $"{effectiveScheme}://{Request.Host}"; var filePath = Path.Combine(_hostEnv.WebRootPath, "Content", "Remotely_Installer.exe"); - var serverUrl = $"{Request.Scheme}://{Request.Host}"; var embeddedData = new EmbeddedServerData(new Uri(serverUrl), organizationId); var result = await _embeddedDataSearcher.GetRewrittenStream(filePath, embeddedData); @@ -228,10 +232,12 @@ namespace Remotely.Server.API ip = ip.MapToIPv4(); } + var effectiveScheme = _appConfig.ForceClientHttps ? "https" : Request.Scheme; + _logger.LogInformation( "Started client download via {methodName}. Effective Scheme: {scheme}. Effective Host: {host}. Remote IP: {ip}.", methodName, - Request.Scheme, + effectiveScheme, Request.Host, $"{ip}"); } diff --git a/Server/Pages/ServerConfig.razor b/Server/Pages/ServerConfig.razor index 24c639e0..3932c83b 100644 --- a/Server/Pages/ServerConfig.razor +++ b/Server/Pages/ServerConfig.razor @@ -150,6 +150,13 @@
+
+ +
+ +
+ +

diff --git a/Server/Pages/ServerConfig.razor.cs b/Server/Pages/ServerConfig.razor.cs index 8af3073f..586c9a44 100644 --- a/Server/Pages/ServerConfig.razor.cs +++ b/Server/Pages/ServerConfig.razor.cs @@ -44,6 +44,9 @@ namespace Remotely.Server.Pages [Display(Name = "Enforce Attended Access")] public bool EnforceAttendedAccess { get; set; } + [Display(Name = "Force Client HTTPS")] + public bool ForceClientHttps { get; set; } + [Display(Name = "Known Proxies")] public List KnownProxies { get; set; } = new(); diff --git a/Server/Services/ApplicationConfig.cs b/Server/Services/ApplicationConfig.cs index 777540ab..f39f8d41 100644 --- a/Server/Services/ApplicationConfig.cs +++ b/Server/Services/ApplicationConfig.cs @@ -13,6 +13,7 @@ namespace Remotely.Server.Services string DBProvider { get; } bool EnableWindowsEventLog { get; } bool EnforceAttendedAccess { get; } + bool ForceClientHttps { get; } string[] KnownProxies { get; } int MaxConcurrentUpdates { get; } int MaxOrganizationCount { get; } @@ -50,6 +51,7 @@ namespace Remotely.Server.Services public string DBProvider => Config["ApplicationOptions:DBProvider"] ?? "SQLite"; public bool EnableWindowsEventLog => bool.Parse(Config["ApplicationOptions:EnableWindowsEventLog"]); public bool EnforceAttendedAccess => bool.Parse(Config["ApplicationOptions:EnforceAttendedAccess"] ?? "false"); + public bool ForceClientHttps => bool.Parse(Config["ApplicationOptions:ForceClientHttps"] ?? "false"); public string[] KnownProxies => Config.GetSection("ApplicationOptions:KnownProxies").Get() ?? System.Array.Empty(); public int MaxConcurrentUpdates => int.Parse(Config["ApplicationOptions:MaxConcurrentUpdates"] ?? "10"); public int MaxOrganizationCount => int.Parse(Config["ApplicationOptions:MaxOrganizationCount"] ?? "1"); diff --git a/Server/appsettings.json b/Server/appsettings.json index 63e9e50f..e2195ee2 100644 --- a/Server/appsettings.json +++ b/Server/appsettings.json @@ -17,6 +17,7 @@ "DBProvider": "SQLite", "EnableWindowsEventLog": false, "EnforceAttendedAccess": false, + "ForceClientHttps": false, "KnownProxies": [], "MaxConcurrentUpdates": 10, "MaxOrganizationCount": 1, @@ -39,4 +40,4 @@ "UseHsts": false, "UseHttpLogging": false } -} +} \ No newline at end of file