aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/app/utils
diff options
context:
space:
mode:
authorWouter Admiraal <wouter.admiraal@sonarsource.com>2018-12-11 08:35:04 +0100
committersonartech <sonartech@sonarsource.com>2018-12-20 11:41:28 +0100
commit65e616ffa93f0e0029f792780ff8f3db0b830c2d (patch)
treea7495b271e05e44c328f19f1cc23689bfa6b3452 /server/sonar-web/src/main/js/app/utils
parent3a08c1730f3fe248414add8fa57a61c5670e04c9 (diff)
downloadsonarqube-65e616ffa93f0e0029f792780ff8f3db0b830c2d.tar.gz
sonarqube-65e616ffa93f0e0029f792780ff8f3db0b830c2d.zip
SONAR-11506, SSF-62 Handle XSS code in project links
Diffstat (limited to 'server/sonar-web/src/main/js/app/utils')
-rw-r--r--server/sonar-web/src/main/js/app/utils/isValidUri.ts24
1 files changed, 24 insertions, 0 deletions
diff --git a/server/sonar-web/src/main/js/app/utils/isValidUri.ts b/server/sonar-web/src/main/js/app/utils/isValidUri.ts
new file mode 100644
index 00000000000..115eaf60168
--- /dev/null
+++ b/server/sonar-web/src/main/js/app/utils/isValidUri.ts
@@ -0,0 +1,24 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 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.
+ */
+import { isWebUri } from 'valid-url';
+
+export default function(url: string): boolean {
+ return /^(\/|scm:)/.test(url) || !!isWebUri(url);
+}