From 24c5d91fe42d0ef1a36ae09bfeb4b6bcec92f535 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20B=C3=BCchel?= Date: Wed, 4 Mar 2020 10:08:34 +0100 Subject: [PATCH] SEBWIN-376: Fixed error with browser request filtering and improved logging if request is blocked. Also fixed error in configuration value mapping for content request filter. --- .../Handlers/RequestHandler.cs | 30 ++++++++++++++----- .../Handlers/ResourceHandler.cs | 12 +++----- .../DataMapping/BrowserDataMapper.cs | 2 +- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/SafeExamBrowser.Browser/Handlers/RequestHandler.cs b/SafeExamBrowser.Browser/Handlers/RequestHandler.cs index d8ab8b66..e2d616e0 100644 --- a/SafeExamBrowser.Browser/Handlers/RequestHandler.cs +++ b/SafeExamBrowser.Browser/Handlers/RequestHandler.cs @@ -73,7 +73,10 @@ namespace SafeExamBrowser.Browser.Handlers if (Block(request)) { - RequestBlocked?.Invoke(request.Url); + if (request.ResourceType == ResourceType.MainFrame) + { + RequestBlocked?.Invoke(request.Url); + } return true; } @@ -105,20 +108,31 @@ namespace SafeExamBrowser.Browser.Handlers private bool Block(IRequest request) { - if (settings.Filter.ProcessMainRequests) + var block = false; + + if (settings.Filter.ProcessMainRequests && request.ResourceType == ResourceType.MainFrame) { var result = filter.Process(new Request { Url = request.Url }); - var block = result == FilterResult.Block; - if (block) + if (result == FilterResult.Block) { - logger.Info($"Blocked main request for '{request.Url}'."); + block = true; + logger.Info($"Blocked main request for '{request.Url}' ({request.ResourceType}, {request.TransitionType})."); } - - return block; } - return false; + if (settings.Filter.ProcessContentRequests && request.ResourceType != ResourceType.MainFrame) + { + var result = filter.Process(new Request { Url = request.Url }); + + if (result == FilterResult.Block) + { + block = true; + logger.Info($"Blocked content request for '{request.Url}' ({request.ResourceType}, {request.TransitionType})."); + } + } + + return block; } } } diff --git a/SafeExamBrowser.Browser/Handlers/ResourceHandler.cs b/SafeExamBrowser.Browser/Handlers/ResourceHandler.cs index c16d22a6..4d547c65 100644 --- a/SafeExamBrowser.Browser/Handlers/ResourceHandler.cs +++ b/SafeExamBrowser.Browser/Handlers/ResourceHandler.cs @@ -72,18 +72,14 @@ namespace SafeExamBrowser.Browser.Handlers protected override bool OnResourceResponse(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, IResponse response) { - var abort = true; - if (RedirectToDisablePdfToolbar(request, response, out var url)) { chromiumWebBrowser.Load(url); - } - else - { - abort = base.OnResourceResponse(chromiumWebBrowser, browser, frame, request, response); + + return true; } - return abort; + return base.OnResourceResponse(chromiumWebBrowser, browser, frame, request, response); } private void AppendCustomHeaders(IRequest request) @@ -121,7 +117,7 @@ namespace SafeExamBrowser.Browser.Handlers if (result == FilterResult.Block) { block = true; - logger.Info($"Blocked content request for '{request.Url}'."); + logger.Info($"Blocked content request for '{request.Url}' ({request.ResourceType}, {request.TransitionType})."); } } diff --git a/SafeExamBrowser.Configuration/ConfigurationData/DataMapping/BrowserDataMapper.cs b/SafeExamBrowser.Configuration/ConfigurationData/DataMapping/BrowserDataMapper.cs index a7cd5ecd..f0c55711 100644 --- a/SafeExamBrowser.Configuration/ConfigurationData/DataMapping/BrowserDataMapper.cs +++ b/SafeExamBrowser.Configuration/ConfigurationData/DataMapping/BrowserDataMapper.cs @@ -350,7 +350,7 @@ namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping private void MapRequestFilter(IDictionary rawData, AppSettings settings) { var processMainRequests = rawData.TryGetValue(Keys.Browser.Filter.EnableMainRequestFilter, out var value) && value as bool? == true; - var processContentRequests = rawData.TryGetValue(Keys.Browser.UserAgentModeMobile, out value) && value as bool? == true; + var processContentRequests = rawData.TryGetValue(Keys.Browser.Filter.EnableContentRequestFilter, out value) && value as bool? == true; settings.Browser.Filter.ProcessMainRequests = processMainRequests; settings.Browser.Filter.ProcessContentRequests = processMainRequests && processContentRequests;