diff --git a/x-pack/plugins/ml/public/util/custom_url_utils.js b/x-pack/plugins/ml/public/util/custom_url_utils.js index 14e96fb6f9247a..45ca9d2870b696 100644 --- a/x-pack/plugins/ml/public/util/custom_url_utils.js +++ b/x-pack/plugins/ml/public/util/custom_url_utils.js @@ -67,10 +67,13 @@ export function getUrlForRecord(urlConfig, record) { // fullUrl is the complete URL, including the base path, with any dollar delimited tokens // from the urlConfig having been substituted with values from an anomaly record. export function openCustomUrlWindow(fullUrl, urlConfig) { - if (isKibanaUrl(urlConfig) === true) { + // Run through a regex to test whether the url_value starts with a protocol scheme. + if (/^(?:[a-z]+:)?\/\//i.test(urlConfig.url_value) === false) { window.open(fullUrl, '_blank'); } else { + // Add noopener and noreferrr properties for external URLs. const newWindow = window.open(fullUrl, '_blank', 'noopener,noreferrer'); + // Expect newWindow to be null, but just in case if not, reset the opener link. if (newWindow !== undefined && newWindow !== null) { newWindow.opener = null; @@ -79,7 +82,7 @@ export function openCustomUrlWindow(fullUrl, urlConfig) { } // Returns whether the url_value of the supplied config is for -// a Kibana page running on the same server as this ML plugin. +// a Kibana Discover or Dashboard page running on the same server as this ML plugin. function isKibanaUrl(urlConfig) { const urlValue = urlConfig.url_value; return urlValue.startsWith('kibana#/discover') || urlValue.startsWith('kibana#/dashboard');