From f5c6fcc3508312d47cc581059d8f3a4fe0d426a2 Mon Sep 17 00:00:00 2001 From: smizrahi Date: Tue, 22 Nov 2022 17:37:00 +0100 Subject: [PATCH] fix(security): Security fix for WSTG-INPV-02. Fix build issue in ubuntu trusty --- SoObjects/SOGo/NSString+Utilities.h | 1 + SoObjects/SOGo/NSString+Utilities.m | 165 ++++++++++++++-------------- 2 files changed, 81 insertions(+), 85 deletions(-) diff --git a/SoObjects/SOGo/NSString+Utilities.h b/SoObjects/SOGo/NSString+Utilities.h index 07867adbd..f276b9687 100644 --- a/SoObjects/SOGo/NSString+Utilities.h +++ b/SoObjects/SOGo/NSString+Utilities.h @@ -26,6 +26,7 @@ @class NSCharacterSet; @class NSDictionary; @class NSObject; +@class NSRegularExpression; @interface NSString (SOGoURLExtension) diff --git a/SoObjects/SOGo/NSString+Utilities.m b/SoObjects/SOGo/NSString+Utilities.m index 92fb50a4c..62a0b367d 100644 --- a/SoObjects/SOGo/NSString+Utilities.m +++ b/SoObjects/SOGo/NSString+Utilities.m @@ -898,95 +898,90 @@ static int cssEscapingCount; */ - (NSString *) stringWithoutHTMLInjection: (BOOL)stripHTMLCode { - // NSRegularExpression is not implemented in old GNUStep versions (ubuntu trusty) - if (NSClassFromString(@"NSRegularExpression")) { - NSString *result, *text; - NSScanner *theScanner; - NSError *error; - NSUInteger numberOfMatches; - NSRegularExpression *regex; + NSString *result, *text; + NSScanner *theScanner; + NSError *error; + NSUInteger numberOfMatches; + NSRegularExpression *regex; - text = nil; - error = nil; - result = [NSString stringWithString: self]; - regex = nil; + text = nil; + error = nil; + result = [NSString stringWithString: self]; + regex = nil; - if (stripHTMLCode) { - // Author : https://www.codercrunch.com/question/1251681838/how-remove-html-tags-string-ios - theScanner = [NSScanner scannerWithString: result]; - while ([theScanner isAtEnd] == NO) { - // find start of tag - [theScanner scanUpToString: @"<" intoString: NULL]; - // find end of tag - [theScanner scanUpToString: @">" intoString: &text]; - - // Check that text is not ", text] - withString: @" "]; - } + if (stripHTMLCode) { + // Author : https://www.codercrunch.com/question/1251681838/how-remove-html-tags-string-ios + theScanner = [NSScanner scannerWithString: result]; + while ([theScanner isAtEnd] == NO) { + // find start of tag + [theScanner scanUpToString: @"<" intoString: NULL]; + // find end of tag + [theScanner scanUpToString: @">" intoString: &text]; + + // Check that text is not ", text] + withString: @" "]; } - } - } else { - // Clean XSS - // Examples of injection : https://cheatsheetseries.owasp.org/cheatsheets/XSS_Filter_Evasion_Cheat_Sheet.html#xss-locator-polygot - - // Remove javascript: - regex = [NSRegularExpression regularExpressionWithPattern:@"j[\\s\\u200B \\\\0]*a[\\s\\u200B \\\\0]*v[\\s\\u200B \\\\0]*a[\\s\\u200B \\\\0]*s[\\s\\u200B \\\\0]*c[\\s\\u200B \\\\0]*r[\\s\\u200B \\\\0]*i[\\s\\u200B \\\\0]*p[\\s\\u200B \\\\0]*t[\\s\\u200B \\\\0]*:" - options: NSRegularExpressionCaseInsensitive error:&error]; - result = [regex stringByReplacingMatchesInString:result options:0 range:NSMakeRange(0, [result length]) withTemplate:@""]; - - // Remove vbscript: - regex = [NSRegularExpression regularExpressionWithPattern:@"v[\\s\\u200B \\\\0]*b[\\s\\u200B \\\\0]*s[\\s\\u200B \\\\0]*r[\\s\\u200B \\\\0]*i[\\s\\u200B \\\\0]*p[\\s\\u200B \\\\0]*t[\\s\\u200B \\\\0]*:" - options: NSRegularExpressionCaseInsensitive error:&error]; - result = [regex stringByReplacingMatchesInString:result options:0 range:NSMakeRange(0, [result length]) withTemplate:@""]; - - // Remove livescript: - regex = [NSRegularExpression regularExpressionWithPattern:@"l[\\s\\u200B \\\\0]*i[\\s\\u200B \\\\0]*v[\\s\\u200B \\\\0]*e[\\s\\u200B \\\\0]*s[\\s\\u200B \\\\0]*c[\\s\\u200B \\\\0]*r[\\s\\u200B \\\\0]*i[\\s\\u200B \\\\0]*p[\\s\\u200B \\\\0]*t[\\s\\u200B \\\\0]*:" - options: NSRegularExpressionCaseInsensitive error:&error]; - result = [regex stringByReplacingMatchesInString:result options:0 range:NSMakeRange(0, [result length]) withTemplate:@""]; - - // Remove