Documentation

Go to Portal Website

WebView Hardening Prevention

PlanPlatformsMASVS
TeamAndroid, iOS 10+MASVS-PLATFORM-2, MASVS-NETWORK-1

Overview

WebView Hardening Prevention automatically secures WebView instances throughout your application by enforcing a robust set of security defaults and optionally applying aggressive restrictions to prevent common attack vectors including file-URL data exfiltration, JavaScript bridge abuse, and mixed-content downgrade attacks.

The control operates transparently on all WebViews while allowing host applications to opt specific WebViews into stricter configurations when needed for high-risk contexts.

How It Works

WebView Hardening Prevention applies a two-tier security model:

Default Hardening (Applied to All WebViews)

Every WebView created in your application receives safe-by-default security settings without any code changes required:

iOS:

Android:

These defaults protect against common exploitation vectors while preserving normal web content functionality.

Aggressive Opt-In Hardening

For WebViews displaying untrusted or external content, you can request additional restrictions:

iOS:

WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
[WebViewHardeningPrevention markConfigurationForHardening:config];
WKWebView *webView = [[WKWebView alloc] initWithFrame:frame configuration:config];

This applies:

Android:

Android applies consistent hardening to all discovered WebViews automatically. No explicit opt-in is required.

Threats Mitigated

How to Enable the Control

Navigate to Preventative Controls from the AppTego portal, and expand the Runtime Environment Hardening section. Under this section you will find the WebView Hardening control. Click Enable to enable it for the next build or for it to be applied with a live push (if enabled).

API Configuration Example

{
  "WebViewHardeningPrevention": {
    "protection": true
  }
}
FieldPurpose
protectionEnables webview hardening for protected apps.

Configuration

iOS Opt-In Hardening

To apply aggressive JavaScript and media restrictions to a specific WebView:

#import <MobileDefender/MobileDefender.h>

WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];

// Mark this configuration for aggressive hardening
[WebViewHardeningPrevention markConfigurationForHardening:config];

// Create WebView with hardened configuration
WKWebView *webView = [[WKWebView alloc] initWithFrame:frame
                                        configuration:config];

Use this approach for WebViews displaying:

Android Automatic Hardening

On Android, hardening is applied automatically to all WebViews attached to your activities when they resume. No configuration code is required.

Caveats and Compatibility

Aggressive hardening (iOS opt-in mode) may interfere with:

Recommendation: Do not use aggressive hardening on WebViews hosting OAuth flows, authentication pages, or trusted first-party web applications.

JavaScript Bridge Requirements

Applications using addJavascriptInterface (Android) or WKUserContentController.add(_:name:) (iOS) to expose native APIs to web content should carefully test WebView functionality:

Recommendation: Only use aggressive hardening on WebViews that do not require JavaScript bridge functionality.

Custom WebView Creation Patterns

Android Limitations:

The control discovers WebViews through activity lifecycle monitoring. It may not harden:

Recommendation: Ensure security-sensitive WebViews are attached to activities before they load content.

Support Matrix

PlatformMinimum VersionHardening CoverageOpt-In Support
Android8.0 (API 26)Activity-attached WebViewsAutomatic
iOS10.0All WKWebView instancesVia markConfigurationForHardening:

Integration

WebView Hardening Prevention activates automatically when enabled in your MobileDefender tenant configuration. No code changes are required for default hardening.

For iOS applications requiring aggressive hardening on specific WebViews, import the MobileDefender header and call markConfigurationForHardening: on your WKWebViewConfiguration instances before creating WebViews.

Further Information

For tenant-specific integration guidance, contact AppTego support.