CVE-2022-4556: Improper Neutralization (CWE-707)
value: A vulnerability was found in Alinto SOGo up to 5.7.1 and classified as problematic. Affected by this issue is the function _migrateMailIdentities of the file SoObjects/SOGo/SOGoUserDefaults.m of the component Identity Handler. The manipulation of the argument fullName leads to cross site scripting. The attack may be launched remotely. Upgrading to version 5.8.0 is able to address this issue. The name of the patch is efac49ae91a4a325df9931e78e543f707a0f8e5e. It is recommended to upgrade the affected component. The identifier of this vulnerability is VDB-215960.
CWE 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.
CVSS v3 base score: 6.1
Published: 2022-12-16T17:15Z
Repository: https://github.com/Alinto/sogo
Language: Objective-C
Files changed: SoObjects/SOGo/SOGoUserDefaults.m
Commit date: 2022-11-22 10:54:06 +0100
Commit message: fix(security): Security fix for WSTG-INPV-02. Add XSS protection on identity fullName. Fixes #5642.

Diff: diff --git a/SoObjects/SOGo/SOGoUserDefaults.m b/SoObjects/SOGo/SOGoUserDefaults.m
index 7eac80fae..99dc81b45 100644
--- a/SoObjects/SOGo/SOGoUserDefaults.m
+++ b/SoObjects/SOGo/SOGoUserDefaults.m
@@ -145,11 +145,11 @@ - (BOOL) _migrateMailIdentities
       replyTo = [self stringForKey: @"SOGoMailReplyTo"];
       signature = [self stringForKey: @"SOGoMailSignature"];
       rc = NO;
 
       if ([fullName length])
-        [identity setObject: fullName forKey: @"fullName"];
+        [identity setObject: [fullName stringWithoutHTMLInjection: YES] forKey: @"fullName"];
       if ([email length])
         [identity setObject: email forKey: @"email"];
       if ([replyTo length])
         [identity setObject: replyTo forKey: @"replyTo"];
       if ([signature length])
@@ -795,11 +795,25 @@ - (void) setMailIdentities: (NSArray *) newIdentites
   [self setObject: newIdentites forKey: @"SOGoMailIdentities"];
 }
 
 - (NSArray *) mailIdentities
 {
-  return [self arrayForKey: @"SOGoMailIdentities"];
+  NSMutableArray *mailIdentities;
+  NSMutableDictionary *mailIdentity;
+  NSUInteger i;
+
+  // Remove possible XSS injection
+  mailIdentities = [NSMutableArray arrayWithArray: [self arrayForKey: @"SOGoMailIdentities"]];
+  for (i = 0 ; i < [mailIdentities length] ; i++) {
+    mailIdentity = [mailIdentities objectAtIndex: i];
+    if ([mailIdentity objectForKey: @"fullName"]) {
+      [mailIdentity setObject: [[mailIdentity objectForKey: @"fullName"] stringWithoutHTMLInjection: YES] forKey: @"fullName"];
+      [mailIdentities setObject: mailIdentity atIndexedSubscript: i];
+    }
+  }
+
+  return mailIdentities;
 }
 
 - (void) setMailForceDefaultIdentity: (BOOL) newValue
 {
   [self setBool: newValue forKey: @"SOGoMailForceDefaultIdentity"];

Vulnerable code:         [identity setObject: fullName forKey: @"fullName"];
  return [self arrayForKey: @"SOGoMailIdentities"];
Fixed code:         [identity setObject: [fullName stringWithoutHTMLInjection: YES] forKey: @"fullName"];
  NSMutableArray *mailIdentities;
  NSMutableDictionary *mailIdentity;
  NSUInteger i;

  // Remove possible XSS injection
  mailIdentities = [NSMutableArray arrayWithArray: [self arrayForKey: @"SOGoMailIdentities"]];
  for (i = 0 ; i < [mailIdentities length] ; i++) {
    mailIdentity = [mailIdentities objectAtIndex: i];
    if ([mailIdentity objectForKey: @"fullName"]) {
      [mailIdentity setObject: [[mailIdentity objectForKey: @"fullName"] stringWithoutHTMLInjection: YES] forKey: @"fullName"];
      [mailIdentities setObject: mailIdentity atIndexedSubscript: i];
    }
  }

  return mailIdentities;