From c38e57e081d3554eff308d982336c2edef580a35 Mon Sep 17 00:00:00 2001 From: dbuechel Date: Thu, 27 Jun 2019 15:07:36 +0200 Subject: [PATCH] SEBWIN-329: Fixed bug with custom URI scheme handling and blocked mailto URLs. --- .../Handlers/RequestHandler.cs | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/SafeExamBrowser.Browser/Handlers/RequestHandler.cs b/SafeExamBrowser.Browser/Handlers/RequestHandler.cs index 8e90a64a..9e47b615 100644 --- a/SafeExamBrowser.Browser/Handlers/RequestHandler.cs +++ b/SafeExamBrowser.Browser/Handlers/RequestHandler.cs @@ -33,6 +33,11 @@ namespace SafeExamBrowser.Browser.Handlers // reactivated. See https://bitbucket.org/chromiumembedded/cef/issues/2622 for the current status of development. // AppendCustomUserAgent(request); + if (IsMailtoUrl(request.Url)) + { + return CefReturnValue.Cancel; + } + ReplaceCustomScheme(request); return base.OnBeforeResourceLoad(browserControl, browser, frame, request, callback); @@ -47,17 +52,25 @@ namespace SafeExamBrowser.Browser.Handlers request.Headers = headers; } + private bool IsMailtoUrl(string url) + { + return url.StartsWith(Uri.UriSchemeMailto); + } + private void ReplaceCustomScheme(IRequest request) { - var uri = new Uri(request.Url); + if (Uri.IsWellFormedUriString(request.Url, UriKind.RelativeOrAbsolute)) + { + var uri = new Uri(request.Url); - if (uri.Scheme == appConfig.SebUriScheme) - { - request.Url = new UriBuilder(uri) { Scheme = Uri.UriSchemeHttp }.Uri.AbsoluteUri; - } - else if (uri.Scheme == appConfig.SebUriSchemeSecure) - { - request.Url = new UriBuilder(uri) { Scheme = Uri.UriSchemeHttps }.Uri.AbsoluteUri; + if (uri.Scheme == appConfig.SebUriScheme) + { + request.Url = new UriBuilder(uri) { Scheme = Uri.UriSchemeHttp }.Uri.AbsoluteUri; + } + else if (uri.Scheme == appConfig.SebUriSchemeSecure) + { + request.Url = new UriBuilder(uri) { Scheme = Uri.UriSchemeHttps }.Uri.AbsoluteUri; + } } } }