CVE-2019-17579 (published 2019-10-14T15:15Z)

SonarSource SonarQube before 7.8 has XSS in project links on account/projects.

Severity: MEDIUM
CVSS v2 base score: 4.3 (AV:N/AC:M/Au:N/C:N/I:P/A:N)
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-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/SonarSource/sonarqube
commit_details: repo_url: https://github.com/SonarSource/sonarqube
author: Wouter Admiraal
author_date: 2019-03-27 13:19:14+01:00
msg: SONAR-11867, SSF-74 Fix XSS in project links on account/projects
repository: repo_url: https://github.com/SonarSource/sonarqube
repo_name: SonarSource/sonarqube
description: Continuous Inspection
repo_language: Java
owner: SonarSource
file_changes: filename: ProjectCard.tsx
change_type: ModificationType.MODIFY
diff: @@ -18,14 +18,14 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 import * as React from 'react';
-import { sortBy } from 'lodash';
 import { Link } from 'react-router';
 import DateFromNow from '../../../components/intl/DateFromNow';
 import DateTimeFormatter from '../../../components/intl/DateTimeFormatter';
 import HelpTooltip from '../../../components/controls/HelpTooltip';
 import Level from '../../../components/ui/Level';
-import ProjectLinkIcon from '../../../components/icons-components/ProjectLinkIcon';
 import Tooltip from '../../../components/controls/Tooltip';
+import MetaLink from '../../overview/meta/MetaLink';
+import { orderLinks } from '../../projectLinks/utils';
 import { translateWithParameters, translate } from '../../../helpers/l10n';
 
 interface Props {
@@ -33,7 +33,20 @@ interface Props {
 }
 
 export default function ProjectCard({ project }: Props) {
-  const links = sortBy(project.links, 'type');
+  const { links } = project;
+
+  const orderedLinks: T.ProjectLink[] = orderLinks(
+    links.map((link, i) => {
+      const { href, name, type } = link;
+      return {
+        id: `link-${i}`,
+        name,
+        type,
+        url: href
+      };
+    })
+  );
+
   const { lastAnalysisDate } = project;
 
   return (
@@ -72,20 +85,11 @@ export default function ProjectCard({ project }: Props) {
         <Link to={{ pathname: '/dashboard', query: { id: project.key } }}>{project.name}</Link>
       </h3>
 
-      {links.length > 0 && (
+      {orderedLinks.length > 0 && (
         <div className="account-project-links">
           <ul className="list-inline">
-            {links.map(link => (
-              <li key={link.type}>
-                <a
-                  className="link-with-icon"
-                  href={link.href}
-                  rel="nofollow"
-                  target="_blank"
-                  title={link.name}>
-                  <ProjectLinkIcon type={link.type} />
-                </a>
-              </li>
+            {orderedLinks.map(link => (
+              <MetaLink iconOnly={true} key={link.id} link={link} />
             ))}
           </ul>
         </div>

programming_language: TypeScript
filename: ProjectCard-test.tsx
change_type: ModificationType.MODIFY
diff: @@ -19,68 +19,60 @@
  */
 import * as React from 'react';
 import { shallow } from 'enzyme';
-import { Link } from 'react-router';
 import ProjectCard from '../ProjectCard';
-import Level from '../../../../components/ui/Level';
-
-const BASE = { key: 'key', links: [], name: 'name' };
 
 it('should render key and name', () => {
-  const project = { ...BASE };
-  const output = shallow(<ProjectCard project={project} />);
-  expect(output.find('.account-project-key').text()).toBe('key');
+  const wrapper = shallowRender();
+  expect(wrapper.find('.account-project-key').text()).toBe('key');
   expect(
-    output
+    wrapper
       .find('.account-project-name')
-      .find(Link)
+      .find('Link')
       .prop('children')
   ).toBe('name');
 });
 
 it('should render description', () => {
-  const project = { ...BASE, description: 'bla' };
-  const output = shallow(<ProjectCard project={project} />);
-  expect(output.find('.account-project-description').text()).toBe('bla');
+  const wrapper = shallowRender({ description: 'bla' });
+  expect(wrapper.find('.account-project-description').text()).toBe('bla');
 });
 
 it('should not render optional fields', () => {
-  const project = { ...BASE };
-  const output = shallow(<ProjectCard project={project} />);
-  expect(output.find('.account-project-description').length).toBe(0);
-  expect(output.find('.account-project-quality-gate').length).toBe(0);
-  expect(output.find('.account-project-links').length).toBe(0);
+  const wrapper = shallowRender();
+  expect(wrapper.find('.account-project-description').length).toBe(0);
+  expect(wrapper.find('.account-project-quality-gate').length).toBe(0);
+  expect(wrapper.find('.account-project-links').length).toBe(0);
 });
 
 it('should render analysis date', () => {
-  const project = { ...BASE, lastAnalysisDate: '2016-05-17' };
-  const output = shallow(<ProjectCard project={project} />);
-  expect(output.find('.account-project-analysis DateFromNow')).toHaveLength(1);
+  const wrapper = shallowRender({ lastAnalysisDate: '2016-05-17' });
+  expect(wrapper.find('.account-project-analysis DateFromNow')).toHaveLength(1);
 });
 
 it('should not render analysis date', () => {
-  const project = { ...BASE };
-  const output = shallow(<ProjectCard project={project} />);
-  expect(output.find('.account-project-analysis').text()).toContain(
+  const wrapper = shallowRender();
+  expect(wrapper.find('.account-project-analysis').text()).toContain(
     'my_account.projects.never_analyzed'
   );
 });
 
 it('should render quality gate status', () => {
-  const project = { ...BASE, qualityGate: 'ERROR' };
-  const output = shallow(<ProjectCard project={project} />);
+  const wrapper = shallowRender({ qualityGate: 'ERROR' });
   expect(
-    output
+    wrapper
       .find('.account-project-quality-gate')
-      .find(Level)
+      .find('Level')
       .prop('level')
   ).toBe('ERROR');
 });
 
 it('should render links', () => {
-  const project = {
-    ...BASE,
-    links: [{ name: 'n', type: 't', href: 'h' }]
-  };
-  const output = shallow(<ProjectCard project={project} />);
-  expect(output.find('.account-project-links').find('li').length).toBe(1);
+  const wrapper = shallowRender({
+    links: [{ name: 'name', type: 'type', href: 'href' }]
+  });
+  expect(wrapper.find('MetaLink').length).toBe(1);
 });
+
+function shallowRender(project: Partial<T.MyProject> = {}) {
+  return shallow(<ProjectCard project={{ key: 'key', links: [], name: 'name', ...project }} />);
+}

programming_language: JavaScript
filename: MetaLink.css
change_type: ModificationType.ADD
diff: @@ -0,0 +1,35 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+.copy-paste-link .overview-key {
+  width: 80%;
+}
+
+.copy-paste-link .close {
+  color: #000;
+  border-bottom: 0;
+  height: 100%;
+  display: inline-block;
+  margin-left: 5px;
+  box-sizing: border-box;
+}
+
+.copy-paste-link .close svg {
+  vertical-align: sub;
+}

programming_language: CSS
filename: MetaLink.tsx
change_type: ModificationType.MODIFY
diff: @@ -22,8 +22,10 @@ import { getLinkName } from '../../projectLinks/utils';
 import ProjectLinkIcon from '../../../components/icons-components/ProjectLinkIcon';
 import isValidUri from '../../../app/utils/isValidUri';
 import ClearIcon from '../../../components/icons-components/ClearIcon';
+import './MetaLink.css';
 
 interface Props {
+  iconOnly?: boolean;
   link: T.ProjectLink;
 }
 
@@ -42,7 +44,8 @@ export default class MetaLink extends React.PureComponent<Props, State> {
   };
 
   render() {
-    const { link } = this.props;
+    const { iconOnly, link } = this.props;
+    const linkTitle = getLinkName(link);
     return (
       <li>
         <a
@@ -50,9 +53,10 @@ export default class MetaLink extends React.PureComponent<Props, State> {
           href={link.url}
           onClick={!isValidUri(link.url) ? this.handleClick : undefined}
           rel="nofollow noreferrer noopener"
-          target="_blank">
+          target="_blank"
+          title={linkTitle}>
           <ProjectLinkIcon className="little-spacer-right" type={link.type} />
-          {getLinkName(link)}
+          {!iconOnly && linkTitle}
         </a>
         {this.state.expanded && (
           <div className="little-spacer-top copy-paste-link">

programming_language: TypeScript
filename: MetaLink-test.tsx
change_type: ModificationType.MODIFY
diff: @@ -31,6 +31,7 @@ it('should match snapshot', () => {
   };
 
   expect(shallow(<MetaLink link={link} />)).toMatchSnapshot();
+  expect(shallow(<MetaLink iconOnly={true} link={link} />)).toMatchSnapshot();
 });
 
 it('should render dangerous links as plaintext', () => {

programming_language: TypeScript
filename: MetaLink-test.tsx.snap
change_type: ModificationType.MODIFY
diff: @@ -7,6 +7,7 @@ exports[`should expand and collapse link 1`] = `
     href="scm:git:git@github.com"
     rel="nofollow noreferrer noopener"
     target="_blank"
+    title="Foo"
   >
     <ProjectLinkIcon
       className="little-spacer-right"
@@ -24,6 +25,7 @@ exports[`should expand and collapse link 2`] = `
     href="scm:git:git@github.com"
     rel="nofollow noreferrer noopener"
     target="_blank"
+    title="Foo"
   >
     <ProjectLinkIcon
       className="little-spacer-right"
@@ -41,6 +43,7 @@ exports[`should expand and collapse link 3`] = `
     href="scm:git:git@github.com"
     rel="nofollow noreferrer noopener"
     target="_blank"
+    title="Foo"
   >
     <ProjectLinkIcon
       className="little-spacer-right"
@@ -58,6 +61,7 @@ exports[`should match snapshot 1`] = `
     href="http://example.com"
     rel="nofollow noreferrer noopener"
     target="_blank"
+    title="Foo"
   >
     <ProjectLinkIcon
       className="little-spacer-right"
@@ -68,6 +72,23 @@ exports[`should match snapshot 1`] = `
 </li>
 `;
 
+exports[`should match snapshot 2`] = `
+<li>
+  <a
+    className="link-with-icon"
+    href="http://example.com"
+    rel="nofollow noreferrer noopener"
+    target="_blank"
+    title="Foo"
+  >
+    <ProjectLinkIcon
+      className="little-spacer-right"
+      type="foo"
+    />
+  </a>
+</li>
+`;
+
 exports[`should render dangerous links as plaintext 1`] = `
 <li>
   <a
@@ -76,6 +97,7 @@ exports[`should render dangerous links as plaintext 1`] = `
     onClick={[Function]}
     rel="nofollow noreferrer noopener"
     target="_blank"
+    title="Dangerous"
   >
     <ProjectLinkIcon
       className="little-spacer-right"

programming_language: CoffeeScript
filename: styles.css
change_type: ModificationType.MODIFY
diff: @@ -474,23 +474,6 @@
   background-color: transparent !important;
 }
 
-.copy-paste-link .overview-key {
-  width: 90%;
-}
-
-.copy-paste-link .close {
-  color: #000;
-  border-bottom: 0;
-  height: 100%;
-  display: inline-block;
-  margin-left: 5px;
-  box-sizing: border-box;
-}
-
-.copy-paste-link .close svg {
-  vertical-align: sub;
-}
-
 .overview-deleted-profile,
 .overview-deprecated-rules {
   margin: 4px -6px 4px;

programming_language: CSS
filename: utils.ts
change_type: ModificationType.MODIFY
diff: @@ -31,7 +31,7 @@ export function orderLinks<T extends NameAndType>(links: T[]) {
   const [provided, unknown] = partition<T>(links, isProvided);
   return [
     ...sortBy(provided, link => PROVIDED_TYPES.indexOf(link.type)),
-    ...sortBy(unknown, link => link.name!.toLowerCase())
+    ...sortBy(unknown, link => link.name && link.name.toLowerCase())
   ];
 }
 

programming_language: TypeScript