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

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

Issue 2761173002: Disallow JS execution on WebUI pages. (Closed)
Patch Set: Addressed review comments 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 4a51fe0ab9c736797dd064c1accf28dad62ab408..bcc7afbd77b985b35613968e319d9c9ead935241 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
+ // 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];
}
« no previous file with comments | « ios/web/public/test/web_view_interaction_test_util.mm ('k') | ios/web/web_state/ui/crw_web_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698