mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-11-21 06:52:40 +00:00
#3119: prevent unsafe tag to load
This commit is contained in:
1 parent
2d03465f34
commit
440c19fd94
2 files changed
+76
-27
No files matched your search
@@ -576,28 +576,21 @@ static NSString *_sanitizeHtmlForDisplay(NSString *content)
|
|||||||
}
|
}
|
||||||
else if ([lowerName isEqualToString: @"img"])
|
else if ([lowerName isEqualToString: @"img"])
|
||||||
{
|
{
|
||||||
/* [resultPart appendString:
|
// Defer remote images until the user allows them. A
|
||||||
@"src=\"/SOGo.woa/WebServerResources/empty.gif\""]; */
|
// data: src is inline. srcset is always deferred: it is
|
||||||
|
// a list of candidates that may contain remote ones,
|
||||||
//Check if the image is base64 ant not url
|
// whatever the src is.
|
||||||
NSUInteger i, c;
|
if ([name isEqualToString: @"srcset"]
|
||||||
BOOL isBase64 = NO;
|
|| !([value length] > 4
|
||||||
for (i = 0, c = [_attributes count]; i < c; i++) {
|
&& [[value substringToIndex: 4] isEqualToString: @"data"]))
|
||||||
NSString *type, *value;
|
|
||||||
type = [_attributes nameAtIndex:i];
|
|
||||||
if ([type isEqualToString:@"src"])
|
|
||||||
{
|
|
||||||
value = [_attributes valueAtIndex:i];
|
|
||||||
if([value length] > 4 && [[value substringToIndex: 4] isEqualToString:@"data"])
|
|
||||||
{
|
|
||||||
isBase64 = YES;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!isBase64)
|
|
||||||
name = [NSString stringWithFormat: @"unsafe-%@", name];
|
name = [NSString stringWithFormat: @"unsafe-%@", name];
|
||||||
}
|
}
|
||||||
|
else if ([lowerName isEqualToString: @"source"]
|
||||||
|
&& [name isEqualToString: @"srcset"])
|
||||||
|
{
|
||||||
|
// <picture><source srcset>: deferred like <img srcset>
|
||||||
|
name = @"unsafe-srcset";
|
||||||
|
}
|
||||||
else
|
else
|
||||||
skipAttribute = YES;
|
skipAttribute = YES;
|
||||||
}
|
}
|
||||||
@@ -894,6 +887,66 @@ static NSString *_sanitizeHtmlForDisplay(NSString *content)
|
|||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
/*
|
||||||
|
Returns the <style> elements for the CSS of the mail's <style> blocks.
|
||||||
|
Top-level rules that may load remote content (see UnsafeStyleNeedles) are
|
||||||
|
put in a separate <style> element that browsers ignore (type="text/plain")
|
||||||
|
until the user allows remote content: the front then restores its type from
|
||||||
|
the unsafe-type attribute.
|
||||||
|
*/
|
||||||
|
static NSString *_styleElementsForCSS (NSString *css)
|
||||||
|
{
|
||||||
|
NSMutableString *safeCSS, *unsafeCSS, *elements;
|
||||||
|
NSString *rule, *lowerRule;
|
||||||
|
NSUInteger i, max, start, depth, n, count;
|
||||||
|
unichar c;
|
||||||
|
BOOL ruleEnd, unsafe;
|
||||||
|
|
||||||
|
safeCSS = [NSMutableString string];
|
||||||
|
unsafeCSS = [NSMutableString string];
|
||||||
|
max = [css length];
|
||||||
|
start = 0;
|
||||||
|
depth = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < max; i++)
|
||||||
|
{
|
||||||
|
c = [css characterAtIndex: i];
|
||||||
|
ruleEnd = NO;
|
||||||
|
if (c == '{')
|
||||||
|
depth++;
|
||||||
|
else if (c == '}')
|
||||||
|
{
|
||||||
|
if (depth > 0)
|
||||||
|
depth--;
|
||||||
|
ruleEnd = (depth == 0);
|
||||||
|
}
|
||||||
|
else if (c == ';' && depth == 0)
|
||||||
|
ruleEnd = YES; // at-rule statement, eg. @import ...;
|
||||||
|
|
||||||
|
if (ruleEnd || i == max - 1)
|
||||||
|
{
|
||||||
|
rule = [css substringWithRange: NSMakeRange (start, i + 1 - start)];
|
||||||
|
lowerRule = [[rule lowercaseString] stringByReplacingString: @"\""
|
||||||
|
withString: @""];
|
||||||
|
unsafe = NO;
|
||||||
|
for (n = 0, count = [UnsafeStyleNeedles count]; !unsafe && n < count; n++)
|
||||||
|
unsafe = ([lowerRule rangeOfString: [UnsafeStyleNeedles objectAtIndex: n]].location
|
||||||
|
!= NSNotFound);
|
||||||
|
[(unsafe ? unsafeCSS : safeCSS) appendString: rule];
|
||||||
|
start = i + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
elements = [NSMutableString string];
|
||||||
|
if ([safeCSS length])
|
||||||
|
[elements appendFormat: @"<style type=\"text/css\">%@</style>", safeCSS];
|
||||||
|
if ([unsafeCSS length])
|
||||||
|
[elements appendFormat: @"<style type=\"text/plain\" unsafe-type=\"text/css\">%@</style>",
|
||||||
|
unsafeCSS];
|
||||||
|
|
||||||
|
return elements;
|
||||||
|
}
|
||||||
|
|
||||||
@implementation UIxMailPartHTMLViewer
|
@implementation UIxMailPartHTMLViewer
|
||||||
|
|
||||||
- (id) init
|
- (id) init
|
||||||
@@ -1061,9 +1114,7 @@ static NSString *_sanitizeHtmlForDisplay(NSString *content)
|
|||||||
|
|
||||||
css = [handler css];
|
css = [handler css];
|
||||||
if ([css length])
|
if ([css length])
|
||||||
cssContent
|
cssContent = _styleElementsForCSS (css);
|
||||||
= [NSString stringWithFormat: @"<style type=\"text/css\">%@</style>",
|
|
||||||
[handler css]];
|
|
||||||
else
|
else
|
||||||
cssContent = @"";
|
cssContent = @"";
|
||||||
|
|
||||||
@@ -1233,9 +1284,7 @@ static NSString *_sanitizeHtmlForDisplay(NSString *content)
|
|||||||
|
|
||||||
css = [handler css];
|
css = [handler css];
|
||||||
if ([css length])
|
if ([css length])
|
||||||
cssContent
|
cssContent = _styleElementsForCSS (css);
|
||||||
= [NSString stringWithFormat: @"<style type=\"text/css\">%@</style>",
|
|
||||||
[handler css]];
|
|
||||||
else
|
else
|
||||||
cssContent = @"";
|
cssContent = @"";
|
||||||
|
|
||||||
|
|||||||
@@ -429,7 +429,7 @@
|
|||||||
if (angular.isUndefined(part.unsafeContent)) {
|
if (angular.isUndefined(part.unsafeContent)) {
|
||||||
part.unsafeContent = document.createElement('div');
|
part.unsafeContent = document.createElement('div');
|
||||||
part.unsafeContent.innerHTML = part.safeContent;
|
part.unsafeContent.innerHTML = part.safeContent;
|
||||||
angular.forEach(['src', 'srcset', 'data', 'classid', 'background', 'style', 'poster'], function (suffix) {
|
angular.forEach(['src', 'srcset', 'data', 'classid', 'background', 'style', 'poster', 'type'], function (suffix) {
|
||||||
var elements = part.unsafeContent.querySelectorAll('[unsafe-' + suffix + ']'),
|
var elements = part.unsafeContent.querySelectorAll('[unsafe-' + suffix + ']'),
|
||||||
element,
|
element,
|
||||||
value,
|
value,
|
||||||
|
|||||||
Reference in new issue
Block a user