Updating handling of SSL error in WebView, Fixes AB#3268908 #2688
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary:
This PR updates the handling of SSL errors in the Android WebView used for authentication. The change is in response to an incident where the MSA sign-up flow failed due to an expired certificate on an MSA UX web page. The expired certificate was associated with a resource loaded by the page; however, the existing SSL error handling in Common’s WebView would cancel the loading of that resource and subsequently terminate the entire authentication flow. (See PBI for details.)
Solution
Option 1
We simply log and stop loading the resource that caused the error by calling
SssHandler.cancel()but not stop the flow by erroring out. This is a simple change. The only thing is the main URL (the url loading in the WebView) itself has SSL error then the flow would end up in blank page. This is as bad as finishing the flow but does not inform calling app of the error via exception.But if sub-resource has the error, then the flow continues.
This is a low cost solution and easy to implement with slightly poorer UX.
Option 2 (Changes in this PR)
The objective of this update is to improve SSL error handling so that the flow is only cancelled if an SSL error occurs on the main frame resource (the primary page being loaded). If an SSL error affects a sub-resource, only the loading of that specific resource is cancelled, and the overall authentication flow continues. This approach helps prevent unnecessary failures caused by SSL errors on secondary or non-critical resources.
Changes introduced:
WebView and WebViewClient Update:
AzureActiveDirectoryWebViewclass, which extends Android'sWebViewand tracks the active URL being loaded, along withAzureActiveDirectoryWebViewClientWebViewClient's callbacks likeonPageStartedbecause webpage can run into error even beforeonPageStartedis called. So, we track the URL ourselves byshouldOverrideUrlLoading(..)callback. This is called before URL is about to get loadedloadUrlis called explicitly. This is case whereshouldOverrideUrlLoading()is not called. Since there are multiple places webView.loadUrl is called, addedAzureActiveDirectoryWebViewwhich keeps track of the URL being loaded in loadUrl and then continues with webView.loadUrlHandling error in onReceivedSslError
onReceivedSslErrorchecks if the SSL error is for the main frame (i.e., the main page being loaded). It does so by comparing the active url against the error url on host/domain. If error is for main frame, it cancels the flow and calls the completion callback with an error; otherwise, it just cancels the faulty resource, and let the flow continue.Flighting
WEB_VIEW_NEW_SSL_ERROR_HANDLER_ENABLED) inAuthenticationConstants.javato control whether the new SSL error handler logic is enabled. This can be used by OneAuth to opt-in or opt-out.true. If the key is not passed. If the key passed, that will be used (primarily meant for OneAuth/MSALCPP). If not, flight would be used (meant for Broker). MSAL would also use default flight value, as there's no remote flighting there.