From 7d8720d6a26aec4f05046c6d1e49baa636f72f2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20B=C3=BCchel?= Date: Mon, 2 Mar 2020 10:46:42 +0100 Subject: [PATCH] SEBWIN-369: Ensured quit link ignores trailing slash. --- .../Handlers/RequestHandler.cs | 18 +++++++++++++++--- SafeExamBrowser.SystemComponents/UserInfo.cs | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/SafeExamBrowser.Browser/Handlers/RequestHandler.cs b/SafeExamBrowser.Browser/Handlers/RequestHandler.cs index 3362a36e..d8ab8b66 100644 --- a/SafeExamBrowser.Browser/Handlers/RequestHandler.cs +++ b/SafeExamBrowser.Browser/Handlers/RequestHandler.cs @@ -7,6 +7,7 @@ */ using System; +using System.Text.RegularExpressions; using CefSharp; using SafeExamBrowser.Browser.Contracts.Filters; using SafeExamBrowser.Browser.Events; @@ -23,6 +24,7 @@ namespace SafeExamBrowser.Browser.Handlers { private IRequestFilter filter; private ILogger logger; + private string quitUrlPattern; private ResourceHandler resourceHandler; private BrowserSettings settings; @@ -81,11 +83,21 @@ namespace SafeExamBrowser.Browser.Handlers private bool IsQuitUrl(IRequest request) { - var isQuitUrl = settings.QuitUrl?.Equals(request.Url, StringComparison.OrdinalIgnoreCase) == true; + var isQuitUrl = false; - if (isQuitUrl) + if (!string.IsNullOrWhiteSpace(settings.QuitUrl)) { - logger.Debug($"Detected quit URL '{request.Url}'."); + if (quitUrlPattern == default(string)) + { + quitUrlPattern = Regex.Escape(settings.QuitUrl.TrimEnd('/')) + @"\/?"; + } + + isQuitUrl = Regex.IsMatch(request.Url, quitUrlPattern, RegexOptions.IgnoreCase); + + if (isQuitUrl) + { + logger.Debug($"Detected quit URL '{request.Url}'."); + } } return isQuitUrl; diff --git a/SafeExamBrowser.SystemComponents/UserInfo.cs b/SafeExamBrowser.SystemComponents/UserInfo.cs index 196283f4..cd7e265f 100644 --- a/SafeExamBrowser.SystemComponents/UserInfo.cs +++ b/SafeExamBrowser.SystemComponents/UserInfo.cs @@ -89,7 +89,7 @@ namespace SafeExamBrowser.SystemComponents { var process = new Process(); - process.StartInfo.Arguments = string.Format("/c \"wmic useraccount where name='{0}' get sid\"", userName); + process.StartInfo.Arguments = $"/c \"wmic useraccount where name='{userName}' get sid\""; process.StartInfo.CreateNoWindow = true; process.StartInfo.FileName = "cmd.exe"; process.StartInfo.RedirectStandardOutput = true;