Script origins control inline policy, all scripts allowed for tab

This commit is contained in:
James Magahern
2020-07-29 17:46:53 -07:00
parent f330293606
commit 32cdcf71f7
14 changed files with 301 additions and 57 deletions

View File

@@ -17,8 +17,10 @@
#import <WebKit/WKWebProcessPlugInLoadDelegate.h>
@interface SBRProcessPlugin () <WKWebProcessPlugInLoadDelegate, SBRWebProcessProxy>
@property (nonatomic, strong) id<SBRWebProcessDelegate> processDelegate;
@property (nonatomic, strong) NSMutableSet<NSString *> *allowedResourceOrigins;
@property (nonatomic, assign) BOOL allScriptsAllowed;
@end
@implementation SBRProcessPlugin
@@ -41,8 +43,20 @@
_allowedResourceOrigins = [NSMutableSet setWithArray:allowedOrigins];
}
- (void)setAllScriptsAllowed:(BOOL)allScriptsAllowed
{
_allScriptsAllowed = allScriptsAllowed;
}
#pragma mark <WKWebProcessPlugIn>
- (void)webProcessPlugIn:(WKWebProcessPlugInController *)plugInController initializeWithObject:(id)initializationObject
{
_allowedResourceOrigins = [[plugInController parameters] valueForKey:SBRGetAllowedOriginsKey()];
_allScriptsAllowed = [[[plugInController parameters] valueForKey:SBRGetAllScriptsAllowedKey()] boolValue];
NSLog(@"Got %lu allowed script origins at initialization", (unsigned long)_allowedResourceOrigins.count);
}
- (void)webProcessPlugIn:(WKWebProcessPlugInController *)plugInController didCreateBrowserContextController:(WKWebProcessPlugInBrowserContextController *)browserContextController
{
_WKRemoteObjectInterface *proxyInterface = [_WKRemoteObjectInterface remoteObjectInterfaceWithProtocol:@protocol(SBRWebProcessProxy)];
@@ -61,6 +75,9 @@
- (NSURLRequest *)webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController *)controller frame:(WKWebProcessPlugInFrame *)frame willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse
{
NSLog(@"SBRProcessPlugin: Sending request: %@", request);
if (_allowedResourceOrigins == nil) {
NSLog(@"Allowed resource origins should not be nil!!!!");
}
NSURL *requestURL = [request URL];
NSString *originString = [requestURL host];
@@ -68,7 +85,7 @@
if (requestExtension.length > 0 && [requestExtension isEqualToString:@"js"]) {
[[self processDelegate] webProcessDidLoadScriptWithOrigin:originString];
if ([_allowedResourceOrigins containsObject:originString]) {
if ([self allScriptsAllowed] || [_allowedResourceOrigins containsObject:originString]) {
NSLog(@"SBRProcessPlugin: Allowing whitelisted requestURL: %@", requestURL);
} else {
NSLog(@"SBRProcessPlugin: Blocking requestURL: %@", requestURL);

View File

@@ -7,9 +7,18 @@
#import <Foundation/Foundation.h>
static inline NSString* SBRGetAllowedOriginsKey() {
return @"allowedOrigins";
}
static inline NSString* SBRGetAllScriptsAllowedKey() {
return @"allScriptsAllowed";
}
@protocol SBRWebProcessProxy <NSObject>
- (void)hello;
- (void)syncAllowedResourceOrigins:(NSArray<NSString *> *)allowedOrigins;
- (void)setAllScriptsAllowed:(BOOL)allowed;
@end