fix(mail): Removed invalid HTML tags in mail body. Fixes #5755

This commit is contained in:
smizrahi
2023-06-07 14:42:21 +02:00
parent f22672cef8
commit f9fdad251d
4 changed files with 21 additions and 1 deletions
+3
View File
@@ -92,6 +92,9 @@
- (NSString *) encryptWithKey: (NSString *) theKey;
- (NSString *) decryptWithKey: (NSString *) theKey;
/* HTML */
- (NSString *) cleanInvalidHTMLTags;
@end
#endif /* NSSTRING_URL_H */
+11
View File
@@ -1001,4 +1001,15 @@ static int cssEscapingCount;
return result;
}
- (NSString *) cleanInvalidHTMLTags {
// Clean HTML invalid tags as reported in https://bugs.sogo.nu/view.php?id=5755
NSString *s;
s = [NSString stringWithString: self];
s = [s stringByReplacingOccurrencesOfString:@"<!-->" withString:@""];
s = [s stringByReplacingOccurrencesOfString:@"<!--<!" withString:@"<!--"];
return s;
}
@end
+6
View File
@@ -110,5 +110,11 @@
testEquals([[NSString stringWithString:@"foobar <img onmouseover=foo bar"] stringWithoutHTMLInjection: NO], @"foobar <img onmouseo***=foo bar");
}
- (void) test_stringCleanInvalidHTMLTags
{
testEquals([[NSString stringWithString:@"<div>Test<!--></div>"] cleanInvalidHTMLTags], @"<div>Test</div>");
testEquals([[NSString stringWithString:@"<div><!--[if !mso]><span>Test</span><!--<![endif]--></div>"] cleanInvalidHTMLTags], @"<div><!--[if !mso]><span>Test</span><!--[endif]--></div>");
}
@end
+1 -1
View File
@@ -845,7 +845,7 @@ _xmlCharsetForCharset (NSString *charset)
if (!s)
s = [[NSString alloc] initWithData: preparsedContent encoding: NSISOLatin1StringEncoding];
preparsedContent = [[s safeString] dataUsingEncoding: NSUTF8StringEncoding];
preparsedContent = [[[s cleanInvalidHTMLTags] safeString] dataUsingEncoding: NSUTF8StringEncoding];
RELEASE(s);
}