Skip to content
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

Added Redirect validation during Web3Wallet and Web3App initialization #277

Closed
wants to merge 3 commits into from
Closed
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
6 changes: 6 additions & 0 deletions example/dapp/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ PODS:
- Flutter (1.0.0)
- package_info_plus (0.4.5):
- Flutter
- platform_metadata (0.0.1):
- Flutter
- shared_preferences_foundation (0.0.1):
- Flutter
- FlutterMacOS
Expand All @@ -11,6 +13,7 @@ PODS:
DEPENDENCIES:
- Flutter (from `Flutter`)
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
- platform_metadata (from `.symlinks/plugins/platform_metadata/ios`)
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)
- url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`)

Expand All @@ -19,6 +22,8 @@ EXTERNAL SOURCES:
:path: Flutter
package_info_plus:
:path: ".symlinks/plugins/package_info_plus/ios"
platform_metadata:
:path: ".symlinks/plugins/platform_metadata/ios"
shared_preferences_foundation:
:path: ".symlinks/plugins/shared_preferences_foundation/darwin"
url_launcher_ios:
Expand All @@ -27,6 +32,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
package_info_plus: 115f4ad11e0698c8c1c5d8a689390df880f47e85
platform_metadata: cd10670dd6127617d67e1bb814b869eff946b90e
shared_preferences_foundation: 5b919d13b803cadd15ed2dc053125c68730e5126
url_launcher_ios: bf5ce03e0e2088bad9cc378ea97fa0ed5b49673b

Expand Down
4 changes: 4 additions & 0 deletions example/dapp/linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@

#include "generated_plugin_registrant.h"

#include <platform_metadata/platform_metadata_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) platform_metadata_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "PlatformMetadataPlugin");
platform_metadata_plugin_register_with_registrar(platform_metadata_registrar);
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
Expand Down
1 change: 1 addition & 0 deletions example/dapp/linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
platform_metadata
url_launcher_linux
)

Expand Down
2 changes: 2 additions & 0 deletions example/dapp/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import FlutterMacOS
import Foundation

import package_info_plus
import platform_metadata
import shared_preferences_foundation
import url_launcher_macos

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
PlatformMetadataPlugin.register(with: registry.registrar(forPlugin: "PlatformMetadataPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
}
3 changes: 3 additions & 0 deletions example/dapp/windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@

#include "generated_plugin_registrant.h"

#include <platform_metadata/platform_metadata_plugin_c_api.h>
#include <url_launcher_windows/url_launcher_windows.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
PlatformMetadataPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PlatformMetadataPluginCApi"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
}
1 change: 1 addition & 0 deletions example/dapp/windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
platform_metadata
url_launcher_windows
)

Expand Down
6 changes: 6 additions & 0 deletions example/wallet/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ PODS:
- nanopb/encode (2.30909.0)
- package_info_plus (0.4.5):
- Flutter
- platform_metadata (0.0.1):
- Flutter
- PromisesObjC (2.2.0)
- shared_preferences_foundation (0.0.1):
- Flutter
Expand All @@ -69,6 +71,7 @@ DEPENDENCIES:
- Flutter (from `Flutter`)
- mobile_scanner (from `.symlinks/plugins/mobile_scanner/ios`)
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
- platform_metadata (from `.symlinks/plugins/platform_metadata/ios`)
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)
- url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`)

Expand All @@ -94,6 +97,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/mobile_scanner/ios"
package_info_plus:
:path: ".symlinks/plugins/package_info_plus/ios"
platform_metadata:
:path: ".symlinks/plugins/platform_metadata/ios"
shared_preferences_foundation:
:path: ".symlinks/plugins/shared_preferences_foundation/darwin"
url_launcher_ios:
Expand All @@ -114,6 +119,7 @@ SPEC CHECKSUMS:
mobile_scanner: 5090a13b7a35fc1c25b0d97e18e84f271a6eb605
nanopb: b552cce312b6c8484180ef47159bc0f65a1f0431
package_info_plus: 115f4ad11e0698c8c1c5d8a689390df880f47e85
platform_metadata: cd10670dd6127617d67e1bb814b869eff946b90e
PromisesObjC: 09985d6d70fbe7878040aa746d78236e6946d2ef
shared_preferences_foundation: 5b919d13b803cadd15ed2dc053125c68730e5126
url_launcher_ios: bbd758c6e7f9fd7b5b1d4cde34d2b95fcce5e812
Expand Down
4 changes: 4 additions & 0 deletions example/wallet/linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@

#include "generated_plugin_registrant.h"

#include <platform_metadata/platform_metadata_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) platform_metadata_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "PlatformMetadataPlugin");
platform_metadata_plugin_register_with_registrar(platform_metadata_registrar);
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
Expand Down
1 change: 1 addition & 0 deletions example/wallet/linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
platform_metadata
url_launcher_linux
)

Expand Down
2 changes: 2 additions & 0 deletions example/wallet/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import Foundation

import mobile_scanner
import package_info_plus
import platform_metadata
import shared_preferences_foundation
import url_launcher_macos

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
MobileScannerPlugin.register(with: registry.registrar(forPlugin: "MobileScannerPlugin"))
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
PlatformMetadataPlugin.register(with: registry.registrar(forPlugin: "PlatformMetadataPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
}
3 changes: 3 additions & 0 deletions example/wallet/windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@

#include "generated_plugin_registrant.h"

#include <platform_metadata/platform_metadata_plugin_c_api.h>
#include <url_launcher_windows/url_launcher_windows.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
PlatformMetadataPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PlatformMetadataPluginCApi"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
}
1 change: 1 addition & 0 deletions example/wallet/windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
platform_metadata
url_launcher_windows
)

Expand Down
7 changes: 7 additions & 0 deletions lib/apis/sign_api/sign_engine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ class SignEngine implements ISignEngine {
return;
}

final validation = await WalletConnectUtils.validateRedirect(
metadata.redirect,
);
if (validation != null) {
core.logger.e(validation);
}

await core.pairing.init();
await core.verify.init(verifyUrl: metadata.verifyUrl);
await proposals.init();
Expand Down
47 changes: 43 additions & 4 deletions lib/apis/utils/walletconnect_utils.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import 'dart:convert';

import 'package:package_info_plus/package_info_plus.dart';
import 'package:universal_io/io.dart';
import 'package:platform_metadata/platform_metadata.dart';
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:walletconnect_flutter_v2/apis/core/relay_client/relay_client_models.dart';
import 'package:walletconnect_flutter_v2/apis/models/basic_models.dart';
import 'package:walletconnect_flutter_v2/apis/models/uri_parse_result.dart';
import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart';

class WalletConnectUtils {
static bool isExpired(int expiry) {
Expand Down Expand Up @@ -208,4 +206,45 @@ class WalletConnectUtils {
}
return m;
}

static Future<String?> validateRedirect(Redirect? redirect) async {
try {
final metaDataValue = await PlatformMetadata.getMetaDataValue(
'CFBundleURLTypes',
);
if (metaDataValue == null) {
return 'CFBundleURLTypes\'s key is missing on iOS\'s Info.plist.\n'
'If you want deep linking to work this key must be added.\n'
'Check out https://docs.walletconnect.com/web3wallet/mobileLinking on how to include it';
}
final properties = metaDataValue as List;
for (var prop in properties) {
if (prop is Map && prop.keys.contains('CFBundleURLSchemes')) {
final plistSchemas = prop['CFBundleURLSchemes'] as List;
final nativeSchema = redirect?.native ?? '';
final universalLink = redirect?.universal ?? '';
if (nativeSchema.isEmpty && universalLink.isEmpty) {
return 'No metadata.redirect object has been set\n'
'If you want deep linking to work redirect object must be set.\n'
'Check out https://docs.walletconnect.com/web3wallet/wallet-usage#initialization ';
}
if (nativeSchema.isEmpty) {
return 'Metadata\'s native redirect value has not been set\n'
'Check out https://docs.walletconnect.com/web3wallet/wallet-usage#initialization ';
}
final uri = Uri.parse(nativeSchema);
if (uri.scheme.isEmpty) {
return 'Metadata\'s native redirect must be a valid scheme. E.g.: example:// ';
}
if (!plistSchemas.contains(uri.scheme)) {
return 'Metadata\'s native redirect ($uri) is not included under CFBundleURLSchemes\'s key.\n'
'Check out https://docs.walletconnect.com/web3wallet/mobileLinking on how to include it';
}
}
}
return null;
} catch (e) {
return 'Failed to get iOS configuration: $e';
}
}
}
3 changes: 3 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ dependencies:
json_annotation: ^4.8.1
logger: ^2.0.2+1
package_info_plus: ^5.0.1
platform_metadata:
git:
url: https://github.com/quetool/platform_metadata.git
pointycastle: ^3.7.4
shared_preferences: ^2.2.2
stack_trace: ^1.10.0
Expand Down
Loading