CVE-2022-23656 (published 2022-03-02T21:15Z)

Zulip is an open source team chat app. The `main` development branch of Zulip Server from June 2021 and later is vulnerable to a cross-site scripting vulnerability on the recent topics page. An attacker could maliciously craft a full name for their account and send messages to a topic with several participants; a victim who then opens an overflow tooltip including this full name on the recent topics page could trigger execution of JavaScript code controlled by the attacker. Users running a Zulip server from the main branch should upgrade from main (2022-03-01 or later) again to deploy this fix.

Severity: LOW
CVSS v2 base score: 3.5 (AV:N/AC:M/Au:S/C:N/I:P/A:N)
CVSS v3 base score: 5.4, MEDIUM (CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:L/I:L/A:N)

Weakness information:
cwe_id: CWE-79
cwe_name: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
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.
extended_description: 
            Cross-site scripting (XSS) vulnerabilities occur when:
            
               Untrusted data enters a web application, typically from a web request.
               The web application dynamically generates a web page that contains this untrusted data.
               During page generation, the application does not prevent the data from containing content that is executable by a web browser, such as JavaScript, HTML tags, HTML attributes, mouse events, Flash, ActiveX, etc.
               A victim visits the generated web page through a web browser, which contains malicious script that was injected using the untrusted data.
               Since the script comes from a web page that was sent by the web server, the victim's web browser executes the malicious script in the context of the web server's domain.
               This effectively violates the intention of the web browser's same-origin policy, which states that scripts in one domain should not be able to access resources or run code in a different domain.
            
            There are three main kinds of XSS:
            
               
                  Type 1: Reflected XSS (or Non-Persistent) - 
         			The server reads data directly from the HTTP request and reflects it back in the HTTP response. Reflected XSS exploits occur when an attacker causes a victim to supply dangerous content to a vulnerable web application, which is then reflected back to the victim and executed by the web browser. The most common mechanism for delivering malicious content is to include it as a parameter in a URL that is posted publicly or e-mailed directly to the victim. URLs constructed in this manner constitute the core of many phishing schemes, whereby an attacker convinces a victim to visit a URL that refers to a vulnerable site. After the site reflects the attacker's content back to the victim, the content is executed by the victim's browser.
               
                  Type 2: Stored XSS (or Persistent) - 
               The application stores dangerous data in a database, message forum, visitor log, or other trusted data store. At a later time, the dangerous data is subsequently read back into the application and included in dynamic content. From an attacker's perspective, the optimal place to inject malicious content is in an area that is displayed to either many users or particularly interesting users. Interesting users typically have elevated privileges in the application or interact with sensitive data that is valuable to the attacker. If one of these users executes malicious content, the attacker may be able to perform privileged operations on behalf of the user or gain access to sensitive data belonging to the user. For example, the attacker might inject XSS into a log message, which might not be handled properly when an administrator views the logs.
            
               
                  Type 0: DOM-Based XSS - 
               In DOM-based XSS, the client performs the injection of XSS into the page; in the other types, the server performs the injection. DOM-based XSS generally involves server-controlled, trusted script that is sent to the client, such as Javascript that performs sanity checks on a form before the user submits it. If the server-supplied script processes user-supplied data and then injects it back into the web page (such as with dynamic HTML), then DOM-based XSS is possible.
            
            
            Once the malicious script is injected, the attacker can perform a variety of malicious activities. The attacker could transfer private information, such as cookies that may include session information, from the victim's machine to the attacker. The attacker could send malicious requests to a web site on behalf of the victim, which could be especially dangerous to the site if the victim has administrator privileges to manage that site. Phishing attacks could be used to emulate trusted web sites and trick the victim into entering a password, allowing the attacker to compromise the victim's account on that web site. Finally, the script could exploit a vulnerability in the web browser itself possibly taking over the victim's machine, sometimes referred to as "drive-by hacking."
            In many cases, the attack can be launched without the victim even being aware of it. Even with careful users, attackers frequently use a variety of methods to encode the malicious portion of the attack, such as URL encoding or Unicode, so the request looks less suspicious.
         
         

Fix information:
repo_url: https://github.com/zulip/zulip
commit_details: repo_url: https://github.com/zulip/zulip
author: Anders Kaseorg
author_date: 2022-02-21 01:51:58-08:00
msg: CVE-2022-23656: Fix cross-site scripting vulnerability in tooltips.

An attacker could maliciously craft a full name for their account and
send messages to a topic with several participants; a victim who then
opens an overflow tooltip including this full name on the recent
topics page could trigger execution of JavaScript code controlled by
the attacker.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
repository: repo_url: https://github.com/zulip/zulip
repo_name: zulip/zulip
description: Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
repo_language: Python
owner: zulip
file_changes: filename: popover_menus.js
change_type: ModificationType.MODIFY
diff: @@ -32,7 +32,6 @@ const default_popover_props = {
     delay: 0,
     appendTo: () => document.body,
     trigger: "click",
-    allowHTML: true,
     interactive: true,
     hideOnClick: true,
     /* The light-border TippyJS theme is a bit of a misnomer; it
@@ -60,6 +59,7 @@ export function initialize() {
     delegate("body", {
         ...default_popover_props,
         target: "#streams_inline_icon",
+        allowHTML: true,
         onShow(instance) {
             const can_create_streams =
                 settings_data.user_can_create_private_streams() ||
@@ -89,6 +89,7 @@ export function initialize() {
         ...default_popover_props,
         target: ".compose_mobile_button",
         placement: "top",
+        allowHTML: true,
         onShow(instance) {
             on_show_prep(instance);
             instance.setContent(
@@ -125,6 +126,7 @@ export function initialize() {
         ...default_popover_props,
         target: ".compose_control_menu_wrapper",
         placement: "top",
+        allowHTML: true,
         onShow(instance) {
             instance.setContent(
                 render_compose_control_buttons_popover({
@@ -143,6 +145,7 @@ export function initialize() {
         ...default_popover_props,
         target: ".enter_sends",
         placement: "top",
+        allowHTML: true,
         onShow(instance) {
             on_show_prep(instance);
             instance.setContent(

programming_language: TypeScript
filename: recent_topics_ui.js
change_type: ModificationType.MODIFY
diff: @@ -1,4 +1,5 @@
 import $ from "jquery";
+import _ from "lodash";
 
 import render_recent_topic_row from "../templates/recent_topic_row.hbs";
 import render_recent_topics_filters from "../templates/recent_topics_filters.hbs";
@@ -291,7 +292,9 @@ function format_topic(topic_data) {
             ),
         );
     }
-    const other_sender_names = displayed_other_names.join("<br/>");
+    const other_sender_names_html = displayed_other_names
+        .map((name) => _.escape(name))
+        .join("<br />");
 
     return {
         // stream info
@@ -309,7 +312,7 @@ function format_topic(topic_data) {
         topic_url: hash_util.by_stream_topic_uri(stream_id, topic),
         senders: senders_info,
         other_senders_count: Math.max(0, all_senders.length - MAX_AVATAR),
-        other_sender_names,
+        other_sender_names_html,
         muted,
         topic_muted,
         participated: topic_data.participated,

programming_language: TypeScript
filename: rendered_markdown.js
change_type: ModificationType.MODIFY
diff: @@ -171,7 +171,9 @@ export const update_elements = (content) => {
                 text: rendered_time.text,
             });
             $(this).html(rendered_timestamp);
-            $(this).attr("data-tippy-content", rendered_time.tooltip_content);
+            $(this)
+                .attr("data-tippy-content", rendered_time.tooltip_content_html)
+                .attr("data-tippy-allowHTML", "true");
         } else {
             // This shouldn't happen. If it does, we're very interested in debugging it.
             blueslip.error(`Could not parse datetime supplied by backend: ${time_str}`);

programming_language: JavaScript
filename: timerender.ts
change_type: ModificationType.MODIFY
diff: @@ -226,17 +226,17 @@ export function render_date(time: Date, time_above: Date | undefined, today: Dat
 // Renders the timestamp returned by the <time:> Markdown syntax.
 export function render_markdown_timestamp(time: number | Date): {
     text: string;
-    tooltip_content: string;
+    tooltip_content_html: string;
 } {
     const hourformat = user_settings.twenty_four_hour_time ? "HH:mm" : "h:mm a";
     const timestring = format(time, "E, MMM d yyyy, " + hourformat);
 
     const tz_offset_str = get_tz_with_UTC_offset(time);
-    const tooltip_html_content = render_markdown_time_tooltip({tz_offset_str});
+    const tooltip_content_html = render_markdown_time_tooltip({tz_offset_str});
 
     return {
         text: timestring,
-        tooltip_content: tooltip_html_content,
+        tooltip_content_html: tooltip_content_html,
     };
 }
 

programming_language: TypeScript
filename: tippyjs.js
change_type: ModificationType.MODIFY
diff: @@ -35,7 +35,7 @@ tippy.setDefaultProps({
     appendTo: "parent",
 
     // html content is not supported by default
-    // enable it by passing data-tippy-allowHtml="true"
+    // enable it by passing data-tippy-allowHTML="true"
     // in the tag or a parameter.
 });
 
@@ -200,7 +200,6 @@ export function initialize() {
             ".rendered_markdown .copy_codeblock",
             "#compose_top_right [data-tippy-content]",
         ],
-        allowHTML: true,
         appendTo: () => document.body,
         onHidden(instance) {
             instance.destroy();

programming_language: TypeScript
filename: ui_init.js
change_type: ModificationType.MODIFY
diff: @@ -203,7 +203,7 @@ function initialize_compose_box() {
             embedded: $("#compose").attr("data-embedded") === "",
             file_upload_enabled: page_params.max_file_upload_size_mib > 0,
             giphy_enabled: giphy.is_giphy_enabled(),
-            scroll_to_bottom_key: common.has_mac_keyboard()
+            scroll_to_bottom_key_html: common.has_mac_keyboard()
                 ? "Fn + <span class='tooltip_right_arrow'>→</span>"
                 : "End",
         }),

programming_language: TypeScript
filename: compose.hbs
change_type: ModificationType.MODIFY
diff: @@ -4,7 +4,7 @@
     minimal css and no JS. We keep it `position: absolute` to prevent
     it changing compose box layout in any way. --}}
     <div id="scroll-to-bottom-button-container">
-        <div id="scroll-to-bottom-button-clickable-area"  data-tippy-content="{{t 'Scroll to bottom' }}  <span class='hotkey-hint'>({{scroll_to_bottom_key}})</span>" data-tippy-allowHtml="true">
+        <div id="scroll-to-bottom-button-clickable-area"  data-tippy-content="{{t 'Scroll to bottom' }}  &lt;span class='hotkey-hint'&gt;({{scroll_to_bottom_key_html}})&lt;/span&gt;" data-tippy-allowHTML="true">
             <div id="scroll-to-bottom-button">
                 <i class="fa fa-chevron-down"></i>
             </div>

programming_language: HTML
filename: compose_control_buttons.hbs
change_type: ModificationType.MODIFY
diff: @@ -7,7 +7,7 @@
     <a role="button" class="undo_markdown_preview compose_control_button fa fa-edit" aria-label="{{t 'Write' }}" tabindex=0 style="display:none;" data-tippy-content="{{t 'Write' }}"></a>
     <a role="button" class="compose_control_button fa fa-video-camera video_link" aria-label="{{t 'Add video call' }}" tabindex=0 data-tippy-content="{{t 'Add video call' }}"></a>
     <a role="button" class="compose_control_button fa fa-smile-o emoji_map" aria-label="{{t 'Add emoji' }}" tabindex=0 data-tippy-content="{{t 'Add emoji' }}"></a>
-    <a role="button" class="compose_control_button fa fa-clock-o time_pick" aria-label="{{t 'Add global time' }}" tabindex=0 data-tippy-content="{{t 'Add global time<br />Everyone sees global times in their own time zone.' }}" data-tippy-maxWidth="none" data-tippy-allowHtml="true"></a>
+    <a role="button" class="compose_control_button fa fa-clock-o time_pick" aria-label="{{t 'Add global time' }}" tabindex=0 data-tippy-content="{{t 'Add global time<br />Everyone sees global times in their own time zone.' }}" data-tippy-allowHTML="true" data-tippy-maxWidth="none"></a>
     <a role="button" class="compose_control_button compose_gif_icon {{#unless giphy_enabled }} hide {{/unless}} zulip-icon zulip-icon-gif" aria-label="{{t 'Add GIF' }}" tabindex=0 data-tippy-content="{{t 'Add GIF' }}"></a>
     <div class="divider hide-sm">|</div>
     <div class="{{#if message_id}}hide-lg{{else}}hide-sm{{/if}}">

programming_language: HTML
filename: recent_topic_row.hbs
change_type: ModificationType.MODIFY
diff: @@ -32,7 +32,7 @@
     <td class='recent_topic_users'>
         <ul class="recent_topics_participants">
             {{#if other_senders_count}}
-            <li class="recent_topics_participant_item tippy-zulip-tooltip" data-tippy-content="{{other_sender_names}}" data-tippy-allowHtml="true">
+            <li class="recent_topics_participant_item tippy-zulip-tooltip" data-tippy-content="{{other_sender_names_html}}" data-tippy-allowHTML="true">
                 <span class="recent_topics_participant_overflow">+{{other_senders_count}}</span>
             </li>
             {{/if}}

programming_language: HTML
filename: right_sidebar.hbs
change_type: ModificationType.MODIFY
diff: @@ -27,7 +27,7 @@
             <a id="invite-user-link" href="#invite"><i class="fa fa-user-plus" aria-hidden="true"></i>{{t 'Invite more users' }}</a>
             {{/if}}
             <a id="sidebar-keyboard-shortcuts" data-overlay-trigger="keyboard-shortcuts" class="hidden-for-spectators">
-                <i class="fa fa-keyboard-o fa-2x tippy-zulip-tooltip" id="keyboard-icon" data-tippy-allowHtml="true" data-tippy-content="{{t 'Keyboard shortcuts' }} <span class='hotkey-hint'>(?)</span>"></i>
+                <i class="fa fa-keyboard-o fa-2x tippy-zulip-tooltip" id="keyboard-icon" data-tippy-allowHTML="true" data-tippy-content="{{t 'Keyboard shortcuts' }} &lt;span class='hotkey-hint'&gt;(?)&lt;/span&gt;"></i>
             </a>
             <div class="only-visible-for-spectators">
                 <div class="realm-description">

programming_language: HTML