Skip to content

Commit

Permalink
Validate that callbackId is correctly formed
Browse files Browse the repository at this point in the history
  • Loading branch information
clelland committed Feb 19, 2014
1 parent 39e64c9 commit 26702cb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/ios/CDVInAppBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

@property (nonatomic, retain) CDVInAppBrowserViewController* inAppBrowserViewController;
@property (nonatomic, copy) NSString* callbackId;
@property (nonatomic, copy) NSRegularExpression *callbackIdPattern;

- (void)open:(CDVInvokedUrlCommand*)command;
- (void)close:(CDVInvokedUrlCommand*)command;
Expand Down
20 changes: 19 additions & 1 deletion src/ios/CDVInAppBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ - (CDVInAppBrowser*)initWithWebView:(UIWebView*)theWebView
self = [super initWithWebView:theWebView];
if (self != nil) {
_previousStatusBarStyle = -1;
_callbackIdPattern = nil;
}

return self;
Expand Down Expand Up @@ -297,6 +298,23 @@ - (void)injectStyleFile:(CDVInvokedUrlCommand*)command
[self injectDeferredObject:[command argumentAtIndex:0] withWrapper:jsWrapper];
}

- (BOOL)isValidCallbackId:(NSString *)callbackId
{
NSError *err = nil;
// Initialize on first use
if (self.callbackIdPattern == nil) {
self.callbackIdPattern = [NSRegularExpression regularExpressionWithPattern:@"^InAppBrowser[0-9]{1,10}$" options:0 error:&err];
if (err != nil) {
// Couldn't initialize Regex; No is safer than Yes.
return NO;
}
}
if ([self.callbackIdPattern firstMatchInString:callbackId options:0 range:NSMakeRange(0, [callbackId length])]) {
return YES;
}
return NO;
}

/**
* The iframe bridge provided for the InAppBrowser is capable of executing any oustanding callback belonging
* to the InAppBrowser plugin. Care has been taken that other callbacks cannot be triggered, and that no
Expand All @@ -323,7 +341,7 @@ - (BOOL)webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*
NSString* scriptCallbackId = [url host];
CDVPluginResult* pluginResult = nil;

if ([scriptCallbackId hasPrefix:@"InAppBrowser"]) {
if ([self isValidCallbackId:scriptCallbackId]) {
NSString* scriptResult = [url path];
NSError* __autoreleasing error = nil;

Expand Down

0 comments on commit 26702cb

Please sign in to comment.