Add access control for all JSAPI calls by configuring a custom plugin that intercepts and validates page URLs.
-
Set up a custom access control plugin.
-
Create a custom plugin to listen for JSAPI call events and intercept them.
-
After the plugin intercepts an event, retrieve the current page URL and verify it by matching the host and scheme.
@interface MPPlugin4WebView : NBPluginBase @end @implementation MPPlugin4WebView - (void)pluginDidLoad { self.scope = kPSDScope_Scene; // Intercept the information of the invoked JSAPI. [self.target addEventListener:kEvent_Invocation_Event_Start withListener:self useCapture:NO]; [self.target addEventListener:kEvent_Invocation_Invoke withListener:self useCapture:NO]; [super pluginDidLoad]; } - (void)handleEvent:(PSDEvent *)event { [super handleEvent:event]; if([kEvent_Invocation_Event_Start isEqualToString:event.eventType] || [kEvent_Invocation_Invoke isEqualToString:event.eventType]){ PSDInvocationEvent *invocationEvent = (PSDInvocationEvent *)event; NSString *apiName = invocationEvent.invocationName; NSDictionary *data = invocationEvent.invocationData; // Get the URL of the current page and perform string match verification based on the scheme and host. NSURL *url = event.context.currentViewController.url; if (![url.host isEqualToString:@"xxx"] || ![url.scheme isEqualToString:@"xxx"]) { [event preventDefault]; [event stopPropagation]; return; } } } - (int)priority { return PSDPluginPriority_High+1; }ImportantMatch the URL precisely. At a minimum, match the scheme and host of the URI. Avoid using regex matching. Strictly avoid imprecise functions such as contains, startsWith, endsWith, or indexOf.
-
-
Register the plugin.
-
During the mPaaS container initialization, specify the path to the custom plugin.
-
In the plist file of the custom plugin's bundle, register the plugin from the previous step. For more information, see Register a plugin.

-