Fix crash, stale allowAllScripts and allowedOrigins

This commit is contained in:
James Magahern
2020-07-29 18:58:31 -07:00
parent 663dfcd2bb
commit c96cafd1ca
5 changed files with 38 additions and 17 deletions

View File

@@ -54,7 +54,7 @@
{
_allowedResourceOrigins = [[plugInController parameters] valueForKey:SBRGetAllowedOriginsKey()];
_allScriptsAllowed = [[[plugInController parameters] valueForKey:SBRGetAllScriptsAllowedKey()] boolValue];
NSLog(@"Got %lu allowed script origins at initialization", (unsigned long)_allowedResourceOrigins.count);
NSLog(@"SBRProcessPlugin: %lu origins allowed, all scripts allowed: %@ ", (unsigned long)_allowedResourceOrigins.count, _allScriptsAllowed ? @"YES" : @"NO");
}
- (void)webProcessPlugIn:(WKWebProcessPlugInController *)plugInController didCreateBrowserContextController:(WKWebProcessPlugInBrowserContextController *)browserContextController
@@ -83,12 +83,13 @@
NSString *originString = [requestURL host];
NSString *requestExtension = [requestURL pathExtension];
if (requestExtension.length > 0 && [requestExtension isEqualToString:@"js"]) {
[[self processDelegate] webProcessDidLoadScriptWithOrigin:originString];
if ([self allScriptsAllowed] || [_allowedResourceOrigins containsObject:originString]) {
NSLog(@"SBRProcessPlugin: Allowing whitelisted requestURL: %@", requestURL);
[[self processDelegate] webProcessDidAllowScriptWithOrigin:originString];
} else {
NSLog(@"SBRProcessPlugin: Blocking requestURL: %@", requestURL);
[[self processDelegate] webProcessDidBlockScriptWithOrigin:originString];
request = nil;
}
}