Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1212)

Unified Diff: ios/web/web_state/ui/crw_web_controller.mm

Issue 2761173002: Disallow JS execution on WebUI pages. (Closed)
Patch Set: Actually fixed ToolbarTestCase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/web/web_state/ui/crw_web_controller.mm
diff --git a/ios/web/web_state/ui/crw_web_controller.mm b/ios/web/web_state/ui/crw_web_controller.mm
index 4452fed22046f6e61a63a78c8d0c5e3b4c7b6357..34c2dfab192a89fd782e372f482e0dbed8af79b8 100644
--- a/ios/web/web_state/ui/crw_web_controller.mm
+++ b/ios/web/web_state/ui/crw_web_controller.mm
@@ -2296,6 +2296,22 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5;
- (void)executeUserJavaScript:(NSString*)script
completionHandler:(web::JavaScriptResultBlock)completion {
+ // For security reasons executing JavaScript on pages with app-specific URLs
lpromero 2017/03/23 12:43:48 Nit: Add a comma after "reasons".
Eugene But (OOO till 7-30) 2017/03/23 17:45:08 Done.
+ // is not allowed, because those pages may have elevated privileges.
+ GURL lastCommittedURL = self.webState->GetLastCommittedURL();
+ if (web::GetWebClient()->IsAppSpecificURL(lastCommittedURL)) {
+ if (completion) {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ base::scoped_nsobject<NSError> error([[NSError alloc]
+ initWithDomain:web::kJSEvaluationErrorDomain
+ code:web::JS_EVALUATION_ERROR_CODE_NO_WEB_VIEW
+ userInfo:nil]);
+ completion(nil, error);
+ });
+ }
+ return;
+ }
+
[self setUserInteractionRegistered:YES];
[self executeJavaScript:script completionHandler:completion];
}

Powered by Google App Engine
This is Rietveld 408576698