CVE-2022-4558 (published 2022-12-16T17:15Z)

A vulnerability was found in Alinto SOGo up to 5.7.1. It has been classified as problematic. This affects an unknown part of the file SoObjects/SOGo/NSString+Utilities.m of the component Folder/Mail Handler. The manipulation leads to cross site scripting. It is possible to initiate the attack remotely. Upgrading to version 5.8.0 is able to address this issue. The name of the patch is 1e0f5f00890f751e84d67be4f139dd7f00faa5f3. It is recommended to upgrade the affected component. The identifier VDB-215961 was assigned to this vulnerability.

CVSS v3 base score: 6.1, MEDIUM (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N)

Weakness information:
cwe_id: CWE-707
cwe_name: Improper Neutralization
description: The product does not ensure or incorrectly ensures that structured messages or data are well-formed and that certain security properties are met before being read from an upstream component or sent to a downstream component.
extended_description: 
            If a message is malformed, it may cause the message to be incorrectly interpreted.
            Neutralization is an abstract term for any technique that ensures that input (and output) conforms with expectations and is "safe."  This can be done by:
	    
	      checking that the input/output is already "safe" (e.g. validation)
	      transformation of the input/output to be "safe" using techniques such as filtering, encoding/decoding, escaping/unescaping, quoting/unquoting, or canonicalization
	      preventing the input/output from being directly provided by an attacker (e.g. "indirect selection" that maps externally-provided values to internally-controlled values)
	      preventing the input/output from being processed at all
	    
            This weakness typically applies in cases where the product prepares a control message that another process must act on, such as a command or query, and malicious input that was intended as data, can enter the control plane instead. However, this weakness also applies to more general cases where there are not always control implications.
         
         

Fix information:
repo_url: https://github.com/Alinto/sogo
commit_details: repo_url: https://github.com/Alinto/sogo
author: smizrahi
author_date: 2022-11-22 10:09:41+01:00
msg: fix(security): Security fix for WSTG-INPV-02. Add XSS protection on folders and mail title / content
repository: repo_url: https://github.com/Alinto/sogo
repo_name: Alinto/sogo
description: SOGo is a very fast and scalable modern collaboration suite (groupware). It offers calendaring, address book management, and a full-featured Webmail client along with resource sharing and permission handling. It also makes use of documented standards (IMAP, CalDAV, CardDAV, etc.) and thereby provides native connectivity (without plugins) to many clients such as Microsoft Outlook, Apple iCal, the iPhone, Mozilla Lightning, and a plethora of mobile devices.
repo_language: Objective-C
owner: Alinto
file_changes: filename: NSString+Utilities.m
change_type: ModificationType.MODIFY
diff: @@ -898,35 +898,49 @@ static int cssEscapingCount;
  */
 - (NSString *) stringWithoutHTMLInjection: (BOOL)stripHTMLCode
 {
-  NSString *result, *text;
-  NSScanner *theScanner;
-  NSError *error;
-
-  text = nil;
-  error = nil;
-  result = [NSString stringWithString: self];
-
-  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];
-      // replace the found tag with a space
-      //(you can filter multi-spaces out later if you wish)
-      result = [result stringByReplacingOccurrencesOfString:
-              [NSString stringWithFormat: @"%@>", text]
-              withString: @" "];
-    } 
-  } else {
-    // Clean XSS
-    // Examples of injection : https://cheatsheetseries.owasp.org/cheatsheets/XSS_Filter_Evasion_Cheat_Sheet.html#xss-locator-polygot
-
-    // NSRegularExpression is not implemented in old GNUStep versions (ubuntu trusty)
-    if (NSClassFromString(@"NSRegularExpression")) {
-      NSRegularExpression *regex = nil;
+  // NSRegularExpression is not implemented in old GNUStep versions (ubuntu trusty)
+  if (NSClassFromString(@"NSRegularExpression")) {
+    NSString *result, *text;
+    NSScanner *theScanner;
+    NSError *error;
+    NSUInteger numberOfMatches;
+    NSRegularExpression *regex;
+
+    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 <xxx@xx.net
+        regex = [NSRegularExpression regularExpressionWithPattern:@"^<[a-zA-Z.\\-_]+@[a-zA-Z.\\-_]+.[a-zA-Z]+$"
+                                    options: NSRegularExpressionCaseInsensitive error:&error];
+        numberOfMatches = 0;
+        
+        if (text && !error) {
+          numberOfMatches = [regex numberOfMatchesInString: text 
+                                                      options:0 
+                                                      range:NSMakeRange(0, [text length])];
+          if (0 == numberOfMatches) {
+            // replace the found tag with a space
+            //(you can filter multi-spaces out later if you wish)
+            result = [result stringByReplacingOccurrencesOfString:
+                    [NSString stringWithFormat: @"%@>", 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&#x09;&#x0A;&#x0D;\\\\0]*a[\\s\\u200B&#x09;&#x0A;&#x0D;\\\\0]*v[\\s\\u200B&#x09;&#x0A;&#x0D;\\\\0]*a[\\s\\u200B&#x09;&#x0A;&#x0D;\\\\0]*s[\\s\\u200B&#x09;&#x0A;&#x0D;\\\\0]*c[\\s\\u200B&#x09;&#x0A;&#x0D;\\\\0]*r[\\s\\u200B&#x09;&#x0A;&#x0D;\\\\0]*i[\\s\\u200B&#x09;&#x0A;&#x0D;\\\\0]*p[\\s\\u200B&#x09;&#x0A;&#x0D;\\\\0]*t[\\s\\u200B&#x09;&#x0A;&#x0D;\\\\0]*:"
@@ -967,10 +981,12 @@ static int cssEscapingCount;
       regex = [NSRegularExpression regularExpressionWithPattern:@"onmouseover=" 
                                   options: NSRegularExpressionCaseInsensitive error:&error];
       result = [regex stringByReplacingMatchesInString:result options:0 range:NSMakeRange(0, [result length]) withTemplate:@"onmouseo***="];
-    }
-  }  
-  
-  return result;
+    }  
+    
+    return result;
+  } else {
+    return self;
+  }
 }
 
 @end

programming_language: Objective-C