diff --git a/SoObjects/SOGo/NSString+Utilities.m b/SoObjects/SOGo/NSString+Utilities.m index bf90d3cbf..634f7c0b7 100644 --- a/SoObjects/SOGo/NSString+Utilities.m +++ b/SoObjects/SOGo/NSString+Utilities.m @@ -1031,28 +1031,30 @@ static int cssEscapingCount; newResult = [regex stringByReplacingMatchesInString:result options:0 range:NSMakeRange(0, [result length]) withTemplate:@"]+)" - options: NSRegularExpressionCaseInsensitive error: &error]; - newResult = [regex stringByReplacingMatchesInString: result options: 0 range: NSMakeRange(0, [result length]) withTemplate: @"on***=\"\""]; + // Remove onload + regex = [NSRegularExpression regularExpressionWithPattern:@"onload=" + options: NSRegularExpressionCaseInsensitive error:&error]; + newResult = [regex stringByReplacingMatchesInString:result options:0 range:NSMakeRange(0, [result length]) withTemplate:@"onl***="]; result = [NSString stringWithString: newResult]; + // Remove onmouseover + regex = [NSRegularExpression regularExpressionWithPattern:@"onmouseover=" + options: NSRegularExpressionCaseInsensitive error:&error]; + newResult = [regex stringByReplacingMatchesInString:result options:0 range:NSMakeRange(0, [result length]) withTemplate:@"onmouseo***="]; + result = [NSString stringWithString: newResult]; + + // Remove onrepeat + regex = [NSRegularExpression regularExpressionWithPattern:@"onrepeat=" + options: NSRegularExpressionCaseInsensitive error:&error]; + newResult = [regex stringByReplacingMatchesInString:result options:0 range:NSMakeRange(0, [result length]) withTemplate:@"onrep***="]; + result = [NSString stringWithString: newResult]; + + // Remove onerror + regex = [NSRegularExpression regularExpressionWithPattern:@"onerror=" + options: NSRegularExpressionCaseInsensitive error:&error]; + newResult = [regex stringByReplacingMatchesInString:result options:0 range:NSMakeRange(0, [result length]) withTemplate:@"onerr***="]; + result = [NSString stringWithString: newResult]; + // Remove @import css (in style tags) regex = [NSRegularExpression regularExpressionWithPattern:@"(<[\\s\\u200B \\\\0]*s[\\s\\u200B \\\\0]*t[\\s\\u200B \\\\0]*y[\\s\\u200B \\\\0]*l[\\s\\u200B \\\\0]*e.*)([\\s\\u200B \\\\0]*@[\\s\\u200B \\\\0]*i[\\s\\u200B \\\\0]*m[\\s\\u200B \\\\0]*p[\\s\\u200B \\\\0]*o[\\s\\u200B \\\\0]*r[\\s\\u200B \\\\0]*t)(.*<[\\s\\u200B \\\\0]*\\/[\\s\\u200B \\\\0]*s[\\s\\u200B \\\\0]*t[\\s\\u200B \\\\0]*y[\\s\\u200B \\\\0]*l[\\s\\u200B \\\\0]*e[\\s\\u200B \\\\0]*>)" options: NSRegularExpressionCaseInsensitive error:&error]; diff --git a/Tests/Unit/TestNSString+Utilities.m b/Tests/Unit/TestNSString+Utilities.m index 62b7df802..a4ecd03c0 100644 --- a/Tests/Unit/TestNSString+Utilities.m +++ b/Tests/Unit/TestNSString+Utilities.m @@ -107,8 +107,8 @@ testEquals([[NSString stringWithString:@"bar"] stringWithoutHTMLInjection: NO], @"foobar bar"); testEquals([[NSString stringWithString:@"foobar "] stringWithoutHTMLInjection: NO], @"foobar bar"); - testEquals([[NSString stringWithString:@"foobar
ABC
"] stringWithoutHTMLInjection: NO], @"
ABC
"); }