mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-08-12 10:23:19 +00:00
fix(mail): escape angularJS directive for description
This commit is contained in:
@@ -78,7 +78,8 @@
|
||||
|
||||
/* XSS protection */
|
||||
- (NSString *) removeHTMLTagsExceptAnchorTags;
|
||||
- (NSString *) stringWithoutHTMLInjection: (BOOL)stripHTMLCode;
|
||||
- (NSString *) stringWithoutHTMLInjection: (BOOL)stripHTMLCode
|
||||
stripAngular: (BOOL)stripAngular;
|
||||
|
||||
#ifndef GNUSTEP_BASE_LIBRARY
|
||||
- (BOOL) boolValue;
|
||||
|
||||
@@ -936,7 +936,7 @@ static int cssEscapingCount;
|
||||
* @param stripHTMLCode Remove all HTML code from content
|
||||
* @return A safe string
|
||||
*/
|
||||
- (NSString *) stringWithoutHTMLInjection: (BOOL)stripHTMLCode
|
||||
- (NSString *) stringWithoutHTMLInjection: (BOOL)stripHTMLCode stripAngular: (BOOL)stripAngular
|
||||
{
|
||||
NSString *result, *text, *newResult;
|
||||
NSScanner *theScanner;
|
||||
@@ -1058,6 +1058,22 @@ static int cssEscapingCount;
|
||||
// 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];
|
||||
newResult = [regex stringByReplacingMatchesInString:result options:0 range:NSMakeRange(0, [result length]) withTemplate:@"onrep***="];
|
||||
result = [NSString stringWithString: newResult];
|
||||
|
||||
|
||||
if(stripAngular) {
|
||||
// Remove {{ and }} as they are interprated by angularJS with no way of escaping
|
||||
regex = [NSRegularExpression regularExpressionWithPattern:@"(\\{\\{)|({{)"
|
||||
options: NSRegularExpressionCaseInsensitive error:&error];
|
||||
newResult = [regex stringByReplacingMatchesInString:result options:0 range:NSMakeRange(0, [result length]) withTemplate:@"{\\\\{"];
|
||||
result = [NSString stringWithString: newResult];
|
||||
regex = [NSRegularExpression regularExpressionWithPattern:@"(\\}\\})|(}})"
|
||||
options: NSRegularExpressionCaseInsensitive error:&error];
|
||||
newResult = [regex stringByReplacingMatchesInString:result options:0 range:NSMakeRange(0, [result length]) withTemplate:@"}/}"];
|
||||
result = [NSString stringWithString: newResult];
|
||||
}
|
||||
|
||||
newResult = result;
|
||||
while([regex numberOfMatchesInString:newResult options:0 range:NSMakeRange(0, [newResult length])] > 0) {
|
||||
newResult = [regex stringByReplacingMatchesInString:newResult options:0 range:NSMakeRange(0, [newResult length]) withTemplate:@"$1@im****$3"];
|
||||
|
||||
@@ -93,7 +93,7 @@ static const NSString *kCacheMotdKey = @"admin-motd";
|
||||
NSException *error;
|
||||
NSString *safeMotd;
|
||||
|
||||
safeMotd = [motd stringWithoutHTMLInjection: NO];
|
||||
safeMotd = [motd stringWithoutHTMLInjection: NO stripAngular: NO];
|
||||
error = [[[GCSFolderManager defaultFolderManager] adminFolder] writeMotd: safeMotd];
|
||||
if (!error) {
|
||||
[[SOGoCache sharedCache] setValue:safeMotd forKey:kCacheMotdKey];
|
||||
|
||||
@@ -152,7 +152,7 @@ NSString *SOGoPasswordRecoverySecondaryEmail = @"SecondaryEmail";
|
||||
rc = NO;
|
||||
|
||||
if ([fullName length])
|
||||
[identity setObject: [fullName stringWithoutHTMLInjection: YES] forKey: @"fullName"];
|
||||
[identity setObject: [fullName stringWithoutHTMLInjection: YES stripAngular:NO] forKey: @"fullName"];
|
||||
if ([email length])
|
||||
[identity setObject: email forKey: @"email"];
|
||||
if ([replyTo length])
|
||||
@@ -864,7 +864,7 @@ NSString *SOGoPasswordRecoverySecondaryEmail = @"SecondaryEmail";
|
||||
if (mailIdentity && [mailIdentity objectForKey: @"fullName"]) {
|
||||
fullName = [NSString stringWithString: [mailIdentity objectForKey: @"fullName"]];
|
||||
if (fullName) {
|
||||
[mailIdentity setObject: [fullName stringWithoutHTMLInjection: YES] forKey: @"fullName"];
|
||||
[mailIdentity setObject: [fullName stringWithoutHTMLInjection: YES stripAngular:NO] forKey: @"fullName"];
|
||||
[mailIdentities setObject: mailIdentity atIndexedSubscript: i];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user