This guide covers the security model of GBGBridge, including transport safety, content policies, and best practices for production deployments.Documentation Index
Fetch the complete documentation index at: https://docs.go.gbgplc.com/llms.txt
Use this file to discover all available pages before exploring further.
Security Model Overview
GBGBridge operates within the iOS WebKit security model. The bridge is a thin messaging layer β it does not bypass any platform security mechanisms. All communication between the web journey and the native host goes through WebKitβsWKScriptMessageHandler (incoming) and evaluateJavaScript (outgoing).
Trust Boundaries
- Native host code runs with full app permissions. Handlers can access any iOS API.
- Web content in WKWebView runs in a sandboxed web process. It cannot access native APIs except through the bridge message handler.
- The bridge is the controlled interface between these two zones.
Transport Security
Bridge messages never traverse the network β they ride on WebKitβs IPC channels β but the journey URL itself does, so transport security has two distinct concerns: how messages move between native and web (covered first) and how the journey is loaded over HTTPS (covered second).Message Channel
Messages travel over WebKitβs internal IPC mechanism:- Web β Native:
window.webkit.messageHandlers.gbgBridge.postMessage()β uses WebKitβs built-in script message handler. This is a same-process or inter-process call managed by WebKit, not a network request. - Native β Web:
webView.evaluateJavaScript()β executes JavaScript in the WebViewβs context.
Network Security (Journey Loading)
The web journey itself is loaded over the network. To ensure network security:- Always use HTTPS in production. iOS App Transport Security (ATS) enforces this by default.
- Do not disable ATS globally. If you need local development access, use the scoped exception:
- Pin certificates if your security requirements demand it. Implement
WKNavigationDelegate.webView(_:didReceive:completionHandler:)for custom certificate validation.
Content Security
Bootstrap Script Injection
The bridge bootstrap script is injected at document start viaWKUserScript. This runs before any web content loads, ensuring the window.GBGBridge namespace exists when the journey code initializes.
The default bootstrap script is minimal:
Custom Bootstrap Scripts
If you provide a custombootstrapScript in BridgeConfiguration, ensure it does not:
- Expose sensitive native data to the web context.
- Define functions that bypass the structured message protocol.
- Include inline secrets, tokens, or API keys.
Frame Isolation
By default,BridgeWebViewConfigurator injects the bootstrap script and message handler with forMainFrameOnly: true. This means only the top-level frame can access the bridge β iframes (including untrusted third-party content) cannot call window.webkit.messageHandlers.gbgBridge.postMessage() or invoke native capabilities.
If your journey architecture requires iframe bridging (e.g., the verification flow runs inside an iframe), you will need to build a custom configurator that sets forMainFrameOnly: false and add origin validation in your handlers to ensure only trusted frames can invoke capabilities.
Message Validation
Incoming Message Decoding
BridgeHost decodes incoming messages using JSONDecoder. If a message doesnβt conform to the BridgeMessage structure, it is rejected and lastError is set. Malformed messages never reach handlers or the delegate.
Action Validation
Handlers are routed by exact string match on theaction field. Register handlers only for actions you expect. Unexpected actions go to pendingRequests where you can inspect and respond to them.
Data Validation in Handlers
Always validate thedata payload in your handlers. The web content is a less-trusted zone β treat incoming data the same way you would treat user input.
Permission Management
Native Permissions
GBGBridge itself does not request any iOS permissions. Your capability handlers are responsible for requesting and checking permissions as needed.Info.plist Requirements
Add usage descriptions for every permission your handlers might request:| Permission | Key |
|---|---|
| Camera | NSCameraUsageDescription |
| NFC | NSNFCReaderUsageDescription |
| Photo Library | NSPhotoLibraryUsageDescription |
| Location | NSLocationWhenInUseUsageDescription |
Production Checklist
Before shipping your integration:- HTTPS only β Journey URL uses HTTPS. No global ATS exceptions.
- No secrets in bootstrap scripts β Custom bootstrap scripts contain no API keys or tokens.
- Input validation β All handlers validate incoming
datapayloads. - Permission handling β Handlers check and request permissions before accessing protected resources.
- Info.plist entries β Usage descriptions for all permissions handlers might request.
- Error information β Error responses do not leak internal implementation details.
- Frame policy β Considered whether
forMainFrameOnlyshould betruefor your use case. - Certificate pinning β Evaluated whether certificate pinning is required for your security posture.
Next Steps
- Troubleshooting Guide β Diagnosing security-related issues
- Embedding Guide β Secure WebView configuration
- API Reference β Configuration and setup API