Skip to content

[webview_flutter_platform_interface] Adds support to respond to recoverable SSL certificate errors #9248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.13.0

* Adds support to respond to recoverable SSL certificate errors. See `PlatformNavigationDelegate.setOnSSlAuthError`.

## 2.12.0

* Adds support to set whether to draw the scrollbar. See
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
import 'platform_ssl_auth_error.dart';
import 'types/types.dart';

import 'webview_platform.dart' show WebViewPlatform;
Expand Down Expand Up @@ -34,6 +35,13 @@ typedef UrlChangeCallback = void Function(UrlChange change);
/// authentication request.
typedef HttpAuthRequestCallback = void Function(HttpAuthRequest request);

/// Signature for callbacks that notify the host application of an SSL
/// authentication error.
///
/// The host application must call either [PlatformSslAuthError.cancel] or
/// [PlatformSslAuthError.proceed].
typedef SslAuthErrorCallback = void Function(PlatformSslAuthError error);

/// An interface defining navigation events that occur on the native platform.
///
/// The [PlatformWebViewController] is notifying this delegate on events that
Expand Down Expand Up @@ -143,4 +151,15 @@ abstract class PlatformNavigationDelegate extends PlatformInterface {
'setOnHttpAuthRequest is not implemented on the current platform.',
);
}

/// Invoked when the web view receives a recoverable SSL error for a
/// certificate.
///
/// The host application must call either [PlatformSslAuthError.cancel] or
/// [PlatformSslAuthError.proceed].
Future<void> setOnSSlAuthError(SslAuthErrorCallback onSslAuthError) {
throw UnimplementedError(
'setOnSSlAuthError is not implemented on the current platform.',
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/foundation.dart';

import 'types/types.dart';

/// Represents an SSL error with the associated certificate.
///
/// The host application must call [cancel] or, contrary to secure web
/// communication standards, [proceed] to provide the web view's response to the
/// request. [proceed] should generally only be used in test environments, as
/// using it in production can expose users to security and privacy risks.
abstract class PlatformSslAuthError {
/// Creates a [PlatformSslAuthError].
@protected
PlatformSslAuthError({required this.certificate, required this.description});

/// The certificate associated with this error.
final X509Certificate? certificate;

/// A human-presentable description for a given error.
final String description;

/// Instructs the WebView that encountered the SSL certificate error to ignore
/// the error and continue communicating with the server.
///
/// **Warning:** Warning: Calling [proceed] in a production environment is
/// strongly discouraged, as an invalid SSL certificate means that the
/// connection is not secure, so proceeding can expose users to security and
/// privacy risks.
Future<void> proceed();

/// Instructs the WebView that encountered the SSL certificate error to
/// terminate communication with the server.
///
/// The host application must call this method to prevent a resource from
/// loading when an SSL certificate is invalid.
Future<void> cancel();
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ export 'web_resource_request.dart';
export 'web_resource_response.dart';
export 'webview_cookie.dart';
export 'webview_credential.dart';
export 'x509_certificate.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/foundation.dart';

/// Represents an X.509 certificate.
@immutable
class X509Certificate {
/// Creates an [X509Certificate].
const X509Certificate({this.data});

/// A DER representation of the certificate object.
final Uint8List? data;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

export 'src/platform_navigation_delegate.dart';
export 'src/platform_ssl_auth_error.dart';
export 'src/platform_webview_controller.dart';
export 'src/platform_webview_cookie_manager.dart';
export 'src/platform_webview_widget.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/webview_flutt
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview_flutter%22
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 2.12.0
version: 2.13.0

environment:
sdk: ^3.4.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,19 @@ void main() {
throwsUnimplementedError,
);
});

test(
'Default implementation of setOnSSlAuthError should throw unimplemented error',
() {
final PlatformNavigationDelegate callbackDelegate =
ExtendsPlatformNavigationDelegate(
const PlatformNavigationDelegateCreationParams());

expect(
() => callbackDelegate.setOnSSlAuthError((PlatformSslAuthError eror) {}),
throwsUnimplementedError,
);
});
}

class MockWebViewPlatformWithMixin extends MockWebViewPlatform
Expand Down