CVE-2014-125089: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') (CWE-79)
value: A vulnerability was found in cention-chatserver 3.8.0-rc1. It has been declared as problematic. Affected by this vulnerability is the function _formatBody of the file lib/InternalChatProtocol.fe. The manipulation of the argument body leads to cross site scripting. The attack can be launched remotely. Upgrading to version 3.9 is able to address this issue. The identifier of the patch is c4c0258bbd18f6915f97f91d5fee625384096a26. It is recommended to upgrade the affected component. The identifier VDB-221497 was assigned to this vulnerability.
CWE description: The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
CVSS v3 base score: 6.1
Published: 2023-02-21T03:15Z
Repository: https://github.com/cention-mujibur-rahman/cention-chatserver
Language: Other
Files changed: lib/InternalChatProtocol.fe
Commit date: 2014-10-29 17:03:28 +0100
Commit message: Fix for XSS vulnerability

ClearIT informed us about a video from customer ComHem that showed
how a carefully constructed message which includes a as of right
now unknown Javascript file that allowed the customer from the External.app chat
see the agents username and password.

The code now escapes a few characters with HTML entity encoding to prevent this sort of attack.
The code escapes the following characters

& into &amp;
< into &lt;
> into &gt;
" into &quot;
' into &#x27;
/ into &#x2F;

This has been done according to the recommendation found here:
https://www.owasp.org/index.php/XSS_%28Cross_Site_Scripting%29_Prevention_Cheat_Sheet

Diff: diff --git a/lib/InternalChatProtocol.fe b/lib/InternalChatProtocol.fe
index 18039de..18568e2 100644
--- a/lib/InternalChatProtocol.fe
+++ b/lib/InternalChatProtocol.fe
@@ -89,12 +89,20 @@ namespace ChatMCAM {
 			'colour' => (message.user ? '#0000FF' : '#FF0000')
 		];
 	}
 	
 	function _formatBody( string body ) {
-		object r = new Regexp('(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])', 'i');
-		return r.replaceAll(body, '<a style="color:#333399;" target="_blank" href="\1">\1</a>');
+		object r;
+		body = Regexp.replaceAll('&', body, '&amp;');
+		body = Regexp.replaceAll('<', body, '&lt;');
+		body = Regexp.replaceAll('>', body, '&gt;');
+		body = Regexp.replaceAll('"', body, '&quot;');
+		body = Regexp.replaceAll("'", body, '&#x27;');
+		body = Regexp.replaceAll('/', body, '&#x2F;');
+		r = new Regexp('(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])', 'i');
+		body = r.replaceAll(body, '<a style="color:#333399;" target="_blank" href="\1">\1</a>');
+		return body;
 	}
 	
 	function _getList( array area_ids, array user_ids) {
 		array list = [];
 		array order = [];

Vulnerable code: 		object r = new Regexp('(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])', 'i');
		return r.replaceAll(body, '<a style="color:#333399;" target="_blank" href="\1">\1</a>');
Fixed code: 		object r;
		body = Regexp.replaceAll('&', body, '&amp;');
		body = Regexp.replaceAll('<', body, '&lt;');
		body = Regexp.replaceAll('>', body, '&gt;');
		body = Regexp.replaceAll('"', body, '&quot;');
		body = Regexp.replaceAll("'", body, '&#x27;');
		body = Regexp.replaceAll('/', body, '&#x2F;');
		r = new Regexp('(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])', 'i');
		body = r.replaceAll(body, '<a style="color:#333399;" target="_blank" href="\1">\1</a>');
		return body;