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.
This commit is contained in:
parent
50e671c40c
commit
24c5d91fe4
3 changed files with 27 additions and 17 deletions
|
@ -73,7 +73,10 @@ namespace SafeExamBrowser.Browser.Handlers
|
||||||
|
|
||||||
if (Block(request))
|
if (Block(request))
|
||||||
{
|
{
|
||||||
RequestBlocked?.Invoke(request.Url);
|
if (request.ResourceType == ResourceType.MainFrame)
|
||||||
|
{
|
||||||
|
RequestBlocked?.Invoke(request.Url);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -105,20 +108,31 @@ namespace SafeExamBrowser.Browser.Handlers
|
||||||
|
|
||||||
private bool Block(IRequest request)
|
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 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,18 +72,14 @@ namespace SafeExamBrowser.Browser.Handlers
|
||||||
|
|
||||||
protected override bool OnResourceResponse(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, IResponse response)
|
protected override bool OnResourceResponse(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, IResponse response)
|
||||||
{
|
{
|
||||||
var abort = true;
|
|
||||||
|
|
||||||
if (RedirectToDisablePdfToolbar(request, response, out var url))
|
if (RedirectToDisablePdfToolbar(request, response, out var url))
|
||||||
{
|
{
|
||||||
chromiumWebBrowser.Load(url);
|
chromiumWebBrowser.Load(url);
|
||||||
}
|
|
||||||
else
|
return true;
|
||||||
{
|
|
||||||
abort = base.OnResourceResponse(chromiumWebBrowser, browser, frame, request, response);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return abort;
|
return base.OnResourceResponse(chromiumWebBrowser, browser, frame, request, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AppendCustomHeaders(IRequest request)
|
private void AppendCustomHeaders(IRequest request)
|
||||||
|
@ -121,7 +117,7 @@ namespace SafeExamBrowser.Browser.Handlers
|
||||||
if (result == FilterResult.Block)
|
if (result == FilterResult.Block)
|
||||||
{
|
{
|
||||||
block = true;
|
block = true;
|
||||||
logger.Info($"Blocked content request for '{request.Url}'.");
|
logger.Info($"Blocked content request for '{request.Url}' ({request.ResourceType}, {request.TransitionType}).");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -350,7 +350,7 @@ namespace SafeExamBrowser.Configuration.ConfigurationData.DataMapping
|
||||||
private void MapRequestFilter(IDictionary<string, object> rawData, AppSettings settings)
|
private void MapRequestFilter(IDictionary<string, object> rawData, AppSettings settings)
|
||||||
{
|
{
|
||||||
var processMainRequests = rawData.TryGetValue(Keys.Browser.Filter.EnableMainRequestFilter, out var value) && value as bool? == true;
|
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.ProcessMainRequests = processMainRequests;
|
||||||
settings.Browser.Filter.ProcessContentRequests = processMainRequests && processContentRequests;
|
settings.Browser.Filter.ProcessContentRequests = processMainRequests && processContentRequests;
|
||||||
|
|
Loading…
Reference in a new issue