From fc7380ed21903018bf6f46ad1d295d8764457fef Mon Sep 17 00:00:00 2001 From: James Magahern Date: Thu, 21 Oct 2021 13:24:58 -0700 Subject: [PATCH] Implement actual policy --- ...BrowserViewController+WebKitDelegate.swift | 2 +- .../SBRProcessBundleBridge.m | 2 + .../SBRScriptPolicy.h | 6 ++ .../SBRScriptPolicy.m | 84 +++++++++++++++++++ SBrowser.xcodeproj/project.pbxproj | 2 + SBrowserProcessBundle/SBRProcessPlugin.m | 20 +++-- 6 files changed, 109 insertions(+), 7 deletions(-) diff --git a/App/Browser View/BrowserViewController+WebKitDelegate.swift b/App/Browser View/BrowserViewController+WebKitDelegate.swift index f9c6843..fff3b03 100644 --- a/App/Browser View/BrowserViewController+WebKitDelegate.swift +++ b/App/Browser View/BrowserViewController+WebKitDelegate.swift @@ -91,7 +91,7 @@ extension BrowserViewController: WKNavigationDelegate, WKUIDelegate var allowJavaScript = tab.javaScriptEnabled if !allowJavaScript, let host = navigationAction.request.url?.host { // Check origin policy - allowJavaScript = policyManager.allowedOriginsForScriptResources().contains(host) + allowJavaScript = policyManager.scriptPolicy(forOrigin: host).allowsEmbeddedJavaScript() } preferences.allowsContentJavaScript = allowJavaScript diff --git a/App/Web Process Bundle Bridge/SBRProcessBundleBridge.m b/App/Web Process Bundle Bridge/SBRProcessBundleBridge.m index 98cf639..6475ea7 100644 --- a/App/Web Process Bundle Bridge/SBRProcessBundleBridge.m +++ b/App/Web Process Bundle Bridge/SBRProcessBundleBridge.m @@ -84,9 +84,11 @@ _processPool = [[WKProcessPool alloc] _initWithConfiguration:poolConfiguration]; // Initialize allowed origins now + NSDictionary *policies = [_policyDataSource scriptPolicyTypeByOrigin]; NSArray *allowedOrigins = [[_policyDataSource allowedOriginsForScriptResources] allObjects]; [_processPool _setObject:allowedOrigins forBundleParameter:SBRGetAllowedOriginsKey()]; [_processPool _setObject:@(_allowAllScripts) forBundleParameter:SBRGetAllScriptsAllowedKey()]; + [_processPool _setObject:policies forBundleParameter:SBRGetPolicyTypeByOriginKey()]; webViewConfiguration.processPool = _processPool; } diff --git a/App/Web Process Bundle Bridge/SBRScriptPolicy.h b/App/Web Process Bundle Bridge/SBRScriptPolicy.h index 8fbcb61..673f647 100644 --- a/App/Web Process Bundle Bridge/SBRScriptPolicy.h +++ b/App/Web Process Bundle Bridge/SBRScriptPolicy.h @@ -35,6 +35,12 @@ NS_SWIFT_NAME(ScriptPolicy) - (instancetype)initWithSecurityOrigin:(NSString *)origin policyType:(SBRScriptOriginPolicyType)policyType; +/// Returns YES if policy type allows embedded (