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

Unified Diff: chrome/browser/chrome_browser_application_mac.mm

Issue 7661007: Don't load third-party code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chrome_browser_application_mac.mm
===================================================================
--- chrome/browser/chrome_browser_application_mac.mm (revision 96776)
+++ chrome/browser/chrome_browser_application_mac.mm (working copy)
@@ -125,6 +125,11 @@
static IMP gOriginalNSBundleLoadIMP = NULL;
@interface NSBundle (CrNSBundleSwizzle)
+// -crLoad swizzles -load. It refuses to load parasitic third-party code
+// located in certain directories, returning NO instead of attempting to load
+// the bundle. This circumvents some of the mechanisms that third-party code
+// attempts to use to inject itself into applications. Note that some of these
+// mechanisms are unavailable to 64-bit applications anyway.
- (BOOL)crLoad;
@end
@@ -133,12 +138,68 @@
// Method only called when swizzled.
DCHECK(_cmd == @selector(load));
- // MultiClutchInputManager is broken in Chrome on Lion.
- // http://crbug.com/90075.
- if (base::mac::IsOSLionOrLater() &&
- [[self bundleIdentifier]
- isEqualToString:@"net.wonderboots.multiclutchinputmanager"]) {
- return NO;
+ // ~/Library, /Library, and /Network/Library. Things in /System/Library
+ // aren't blacklisted.
+ NSArray* blockedPrefixes =
+ NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
+ NSUserDomainMask |
+ NSLocalDomainMask |
+ NSNetworkDomainMask,
+ YES);
+
+ // Everything in the suffix list has a trailing slash so as to only block
+ // loading things contained in these directories.
+ NSString* const blockedSuffixes[] = {
+ // SIMBL - http://code.google.com/p/simbl/source/browse/src/SIMBL.{h,m}.
+ // It attempts to inject itself via an AppleScript event.
+ // http://code.google.com/p/simbl/source/browse/SIMBL%20Agent/SIMBLAgent.m
+ @"Application Support/SIMBL/Plugins/",
+
+#if !defined(__LP64__)
+ // Contextual menu manager plug-ins are unavailable to 64-bit processes.
+ // http://developer.apple.com/library/mac/releasenotes/Cocoa/AppKitOlderNotes.html#NSMenu
+ @"Contextual Menu Items/",
+
+ // Input managers are deprecated, would only be loaded under specific
+ // circumstances, and are entirely unavailable to 64-bit processes.
+ // http://developer.apple.com/library/mac/releasenotes/Cocoa/AppKitOlderNotes.html#NSInputManager
+ @"Input Managers/",
+#endif // __LP64__
+
+ // Don't load third-party scripting additions either.
+ @"ScriptingAdditions/"
+
+ // This list is intentionally incomplete. For example, it doesn't block
+ // printer drivers or Internet plug-ins.
+ };
+
+ NSString* bundlePath = [self bundlePath];
+ NSUInteger bundlePathLength = [bundlePath length];
+
+ // Merge the prefix and suffix lists.
+ for (NSString* blockedPrefix in blockedPrefixes) {
+ for (size_t blockedSuffixIndex = 0;
+ blockedSuffixIndex < arraysize(blockedSuffixes);
+ ++blockedSuffixIndex) {
+ NSString* blockedSuffix = blockedSuffixes[blockedSuffixIndex];
+ NSString* blockedPath =
+ [blockedPrefix stringByAppendingPathComponent:blockedSuffix];
+ NSUInteger blockedPathLength = [blockedPath length];
+
+ // Do a case-insensitive comparison because most users will be on
+ // case-insensitive HFS+ filesystems and it's cheaper than asking the
+ // disk. This is like [bundlePath hasPrefix:blockedPath] but is
+ // case-insensitive.
+ if (bundlePathLength >= blockedPathLength &&
+ [bundlePath compare:blockedPath
+ options:NSCaseInsensitiveSearch
+ range:NSMakeRange(0, blockedPathLength)] ==
+ NSOrderedSame) {
+ // If bundlePath is inside blockedPath (it has blockedPath as a
+ // prefix), refuse to load it.
+ return NO;
+ }
+ }
}
return gOriginalNSBundleLoadIMP(self, _cmd) != nil;
@@ -226,7 +287,7 @@
@selector(initWithName:reason:userInfo:),
@selector(crInitWithName:reason:userInfo:));
- // Avoid loading broken input managers.
+ // Avoid loading broken input managers and other parasitic plug-ins.
gOriginalNSBundleLoadIMP =
ObjcEvilDoers::SwizzleImplementedInstanceMethods(
[NSBundle class],
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698