Skip to main content
iOS apps embed web content via WebViews. Each type has distinct security properties and testing approaches.

WebView Types

UIWebView

Deprecated since iOS 12. Cannot disable JavaScript, making it inherently vulnerable to script injection and XSS. Avoid entirely in new apps.

WKWebView

Preferred choice. JavaScript can be disabled, supports hasOnlySecureContent for mixed content detection, and minimizes memory corruption risk to the main app process.

SFSafariViewController

Standardized browser experience sharing Safari’s cookies. Cannot disable JavaScript. Must be displayed prominently per App Store guidelines.

Static Analysis

Identify WebView Type

Check JavaScript Configuration

File Access Analysis

UIWebView allows universal file access by default. WKWebView is stricter but has two dangerous optional settings:
  • allowFileAccessFromFileURLs — allows file URLs to access other file URLs (default: false)
  • allowUniversalAccessFromFileURLs — allows file URLs to access any origin (default: false)
Both being false by default is the correct, secure state.

Dynamic Analysis

Heap Inspection with Frida

WebView Protocol Handling

WKWebView supports http(s)://, file://, and tel:// protocols. Methods for loading content:
  • loadHTMLString:baseURL: — loads HTML string with a base URL
  • loadData:MIMEType:textEncodingName:baseURL: — loads raw data
  • loadRequest: — loads a URL request
  • loadFileURL:allowingReadAccessToURL: — loads a local file (dangerous if a directory is specified — exposes all files in it)
If loadFileURL:allowingReadAccessToURL: is called with a directory path (not a file path), all files in that directory become accessible to the WebView’s JavaScript.

File Exfiltration PoC

This JavaScript payload exfiltrates a local file via XHR if the WebView has file access:

Native Methods via WebViews

JSContext (UIWebView)

iOS 7+ allows JavaScript to call native Swift/Objective-C via JSContext:

postMessage (WKWebView)

WKWebView uses message passing for JS-to-native communication:
JavaScript side:
Native handler (Swift):
Exposed native methods via JSContext or postMessage handlers should be carefully reviewed. Sensitive operations (reading files, accessing the Keychain, making network requests) must not be accessible from JavaScript without proper authentication and input validation.

Debugging iOS WebViews

1

Enable Web Inspector on iOS Device

Go to Settings → Safari → Advanced and enable Web Inspector.
2

Enable Developer Tools in Safari (macOS)

Open Safari → Safari → Preferences → Advanced → check Show Develop menu.
3

Connect and Debug

Connect the iOS device to the Mac. In Safari on Mac, go to Develop → [Your Device Name] and select the WebView instance to inspect.
Only WebViews in apps loaded via Xcode can be debugged this way. Apps installed via App Store or Apple Configurator cannot be inspected.

References