Made it check the path of the url and not the full url to prevent it from allowing urls with the parameters of an image extension. Made it not embed images from people that are strangers unless you set a default to allow images by strangers.

This commit is contained in:
GRMrGecko 2011-02-10 11:26:13 -06:00
parent 1bc7849cee
commit 1002a9616f
2 changed files with 44 additions and 35 deletions

View File

@ -10,13 +10,15 @@
#import <Adium/AIPlugin.h> #import <Adium/AIPlugin.h>
#import <Adium/AISharedAdium.h> #import <Adium/AISharedAdium.h>
#import <Adium/AIChat.h> #import <Adium/AIChat.h>
#import <Adium/AIListObject.h>
#import <Adium/AIContactControllerProtocol.h>
#import <Adium/AICorePluginLoader.h> #import <Adium/AICorePluginLoader.h>
#import <Adium/AIContentControllerProtocol.h> #import <Adium/AIContentControllerProtocol.h>
#import <Adium/AIInterfaceControllerProtocol.h> #import <Adium/AIInterfaceControllerProtocol.h>
#import "WebKit Message View/AIWebKitMessageViewController.h" #import "WebKit Message View/AIWebKitMessageViewController.h"
@interface MGMAdinline : AIPlugin <AIHTMLContentFilter> { @interface MGMAdinline : AIPlugin <AIHTMLContentFilter> {
BOOL allowsStrangers;
} }
@end @end

View File

@ -9,6 +9,8 @@
#import "MGMAdinline.h" #import "MGMAdinline.h"
#import <WebKit/Webkit.h> #import <WebKit/Webkit.h>
NSString * const MGMAIAllowStrangers = @"MGMAIAllowStrangers";
@protocol MGMChatViewController <AIChatViewController> @protocol MGMChatViewController <AIChatViewController>
- (AIWebKitMessageViewController *)messageDisplayController; - (AIWebKitMessageViewController *)messageDisplayController;
@end @end
@ -19,6 +21,7 @@
} }
- (void)installPlugin { - (void)installPlugin {
allowsStrangers = [[NSUserDefaults standardUserDefaults] boolForKey:MGMAIAllowStrangers];
[[adium contentController] registerHTMLContentFilter:self direction:AIFilterIncoming]; [[adium contentController] registerHTMLContentFilter:self direction:AIFilterIncoming];
[[adium contentController] registerHTMLContentFilter:self direction:AIFilterOutgoing]; [[adium contentController] registerHTMLContentFilter:self direction:AIFilterOutgoing];
} }
@ -28,6 +31,8 @@
} }
- (NSString *)filterHTMLString:(NSString *)theHTMLString content:(AIContentObject *)theContent { - (NSString *)filterHTMLString:(NSString *)theHTMLString content:(AIContentObject *)theContent {
AIListObject *source = [theContent source];
if (allowsStrangers || ![source isStranger]) {
NSArray *imageExtensions = [NSArray arrayWithObjects:@"png", @"jpg", @"jpeg", @"tif", @"tiff", @"gif", @"bmp", nil]; NSArray *imageExtensions = [NSArray arrayWithObjects:@"png", @"jpg", @"jpeg", @"tif", @"tiff", @"gif", @"bmp", nil];
NSMutableString *html = [[theHTMLString mutableCopy] autorelease]; NSMutableString *html = [[theHTMLString mutableCopy] autorelease];
NSRange range = NSMakeRange(0, [html length]); NSRange range = NSMakeRange(0, [html length]);
@ -50,7 +55,7 @@
range.length = [html length]-range.location; range.length = [html length]-range.location;
linkRange = NSMakeRange(linkStartRange.location+linkStartRange.length, linkEndRange.location-(linkStartRange.location+linkStartRange.length)); linkRange = NSMakeRange(linkStartRange.location+linkStartRange.length, linkEndRange.location-(linkStartRange.location+linkStartRange.length));
NSString *link = [html substringWithRange:linkRange]; NSString *link = [html substringWithRange:linkRange];
if ([imageExtensions containsObject:[[link pathExtension] lowercaseString]]) { if ([imageExtensions containsObject:[[[[NSURL URLWithString:link] path] pathExtension] lowercaseString]]) {
if (shouldScroll==nil) { if (shouldScroll==nil) {
WebView *webview = (WebView *)[[(id<MGMChatViewController>)[[[theContent chat] chatContainer] chatViewController] messageDisplayController] messageView]; WebView *webview = (WebView *)[[(id<MGMChatViewController>)[[[theContent chat] chatContainer] chatViewController] messageDisplayController] messageView];
shouldScroll = [webview stringByEvaluatingJavaScriptFromString:@"nearBottom();"]; shouldScroll = [webview stringByEvaluatingJavaScriptFromString:@"nearBottom();"];
@ -67,6 +72,8 @@
} }
return html; return html;
} }
return theHTMLString;
}
- (CGFloat)filterPriority { - (CGFloat)filterPriority {
return (CGFloat)LOWEST_FILTER_PRIORITY; return (CGFloat)LOWEST_FILTER_PRIORITY;
} }