Repository navigation
Trusted Domains Security
Available since version 10.3.0
The Trusted Domains feature is an optional security enhancement that allows you to restrict which URLs can be opened by the Mobile Messaging SDK. This helps protect your users from potentially malicious URLs that could be sent through push notifications.
- Overview
- Configuration
- How It Works
- Domain Matching Rules
- What URLs Are Affected
- Backward Compatibility
- Examples
- Logging
A push message or a Mirror push notification can contain an on-tap action which opens a URL in the in-app webView or in the device browser. When trusted domains are configured, the SDK will only open those URLs that match the specified domains. URLs from untrusted domains will be blocked and logged as warnings.
Key Benefits:
- Protection against malicious URLs
- Control over which domains your app can navigate to
- No breaking changes - completely optional feature
- Backward compatible with existing implementations
Configure trusted domains during plugin initialization using the trustedDomains parameter of Configuration:
import 'package:infobip_mobilemessaging/infobip_mobilemessaging.dart';
import 'package:infobip_mobilemessaging/models/configurations/configuration.dart';
await InfobipMobilemessaging.init(Configuration(
applicationCode: '<Your Application Code>',
iosSettings: IOSSettings(
notificationTypes: ['alert', 'badge', 'sound'],
),
trustedDomains: ['example.com', 'yourdomain.com', 'api.trusted.org'],
));Parameters:
-
trustedDomains:List<String>of domains that should be trusted - Domain format:
'example.com','subdomain.example.com', etc. Provide only the host name in lowercase, without scheme (https://), port or path.
The plugin passes the trusted domains to the native iOS and Android SDKs, which perform the validation. The trusted domains are stored on the device, so they are also applied to notifications received while the application is not running, before init is called again. Calling init without trustedDomains (or with an empty list) removes the stored domains.
The SDK validates domains for the following URL types:
-
WebView URLs (
webViewUrl): URLs opened in the in-app webView -
Browser URLs (
browserUrl): URLs opened in an external browser
The validation happens before opening the URL. If a URL's domain is not trusted, the SDK will:
- Block the URL from opening
- Log a warning message
- Continue normal execution without the URL action
// Trusted domain: "example.com"
// ✅ Matches: https://example.com/page
// ✅ Matches: https://api.example.com/endpoint
// ✅ Matches: https://cdn.example.com/image.jpg
// ✅ Matches: https://www.example.com/home// Trusted domain: "example.com"
// ❌ Does not match: https://badexample.com/malicious
// ❌ Does not match: https://example.com.evil.org/phishing- URLs from the push notification
webViewUrlfield (webView action) - URLs from the push notification
browserUrlfield (browser action)
-
Deep links sent in the dedicated
deeplinkfield (deeplink action). They are delivered to your application and opened by your own code, see How to use "deeplink" to land user to a particular app page? - URLs opened programmatically by your application, outside of SDK notification handling
Note: To open a deep link or another non-HTTP/HTTPS URL (e.g.
myapp://,tel:,mailto:), use the deeplink action. When trusted domains are configured, such URLs sent as a webView or browser action may be blocked, because they have no domain to match. The exact behavior differs between platforms and is not guaranteed.
The trusted domains feature is completely backward compatible:
-
Without configuration (
trustedDomainsomitted ornull): All URLs work exactly as before -
With empty list:
trustedDomains: []- All URLs are allowed - With domains: Only specified domains are allowed
// Configuration
trustedDomains: ['example.com', 'trusted.org']
// ✅ These URLs will be opened:
// https://example.com/page
// https://api.example.com/data
// https://www.example.com/home
// https://trusted.org/content
// ❌ These URLs will be blocked:
// https://malicious.com/phishing
// https://untrusted.net/spam
// https://fake-example.com/scam
// ✅ These deeplinks will still work when sent as the deeplink action (not validated):
// myapp://open-screen
// myapp://deeplink/ProductScreenWhen URLs are blocked, the SDK logs warning messages, for example:
URL domain is not trusted and will not be opened: https://malicious.com/phishing
WebView URL domain is not trusted and will not be opened: https://malicious.com/phishing
Browser URL domain is not trusted and will not be opened: https://untrusted.net/spam
These logs help with debugging and monitoring security events in your application. See How to enable logging.