From 65e616ffa93f0e0029f792780ff8f3db0b830c2d Mon Sep 17 00:00:00 2001 From: Wouter Admiraal Date: Tue, 11 Dec 2018 08:35:04 +0100 Subject: SONAR-11506, SSF-62 Handle XSS code in project links --- .../src/main/js/apps/projectLinks/LinkRow.tsx | 11 +++-- .../apps/projectLinks/__tests__/LinkRow-test.tsx | 11 +++++ .../__tests__/__snapshots__/LinkRow-test.tsx.snap | 49 +++++++++++++++++++++- 3 files changed, 66 insertions(+), 5 deletions(-) (limited to 'server/sonar-web/src/main/js/apps/projectLinks') diff --git a/server/sonar-web/src/main/js/apps/projectLinks/LinkRow.tsx b/server/sonar-web/src/main/js/apps/projectLinks/LinkRow.tsx index 9ca2a8f6906..c3f83b718f6 100644 --- a/server/sonar-web/src/main/js/apps/projectLinks/LinkRow.tsx +++ b/server/sonar-web/src/main/js/apps/projectLinks/LinkRow.tsx @@ -23,6 +23,7 @@ import ConfirmButton from '../../components/controls/ConfirmButton'; import ProjectLinkIcon from '../../components/icons-components/ProjectLinkIcon'; import { Button } from '../../components/ui/buttons'; import { translate, translateWithParameters } from '../../helpers/l10n'; +import isValidUri from '../../app/utils/isValidUri'; interface Props { link: T.ProjectLink; @@ -90,9 +91,13 @@ export default class LinkRow extends React.PureComponent { {this.renderName(link)} - - {link.url} - + {isValidUri(link.url) ? ( + + {link.url} + + ) : ( + link.url + )} {this.renderDeleteButton(link)} diff --git a/server/sonar-web/src/main/js/apps/projectLinks/__tests__/LinkRow-test.tsx b/server/sonar-web/src/main/js/apps/projectLinks/__tests__/LinkRow-test.tsx index 19cff23dd62..3c93017c8ae 100644 --- a/server/sonar-web/src/main/js/apps/projectLinks/__tests__/LinkRow-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectLinks/__tests__/LinkRow-test.tsx @@ -42,3 +42,14 @@ it('should render custom link', () => { ) ).toMatchSnapshot(); }); + +it('should render dangerous code as plain text', () => { + expect( + shallow( + + ) + ).toMatchSnapshot(); +}); diff --git a/server/sonar-web/src/main/js/apps/projectLinks/__tests__/__snapshots__/LinkRow-test.tsx.snap b/server/sonar-web/src/main/js/apps/projectLinks/__tests__/__snapshots__/LinkRow-test.tsx.snap index c76c3e13aef..e05b8f94f91 100644 --- a/server/sonar-web/src/main/js/apps/projectLinks/__tests__/__snapshots__/LinkRow-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/projectLinks/__tests__/__snapshots__/LinkRow-test.tsx.snap @@ -28,7 +28,7 @@ exports[`should render custom link 1`] = ` > http://example.com @@ -51,6 +51,51 @@ exports[`should render custom link 1`] = ` `; +exports[`should render dangerous code as plain text 1`] = ` + + +
+ +
+ + dangerous + +
+
+ + + javascript:alert("Hello") + + + + + + + +`; + exports[`should render provided link 1`] = `
http://example.com -- cgit v1.2.3