Skip to content

Commit

Permalink
[ML] Set noopener feature for custom URLs which use absolute URLs (el…
Browse files Browse the repository at this point in the history
…astic#39161) (elastic#39243)

* [ML] Set noopener feature for custom URLs which use absolute URLs

* [ML] Add comments around regex testing for external URL
  • Loading branch information
peteharverson committed Jun 19, 2019
1 parent 7c1ed64 commit 0468537
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions x-pack/plugins/ml/public/util/custom_url_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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');
Expand Down

0 comments on commit 0468537

Please sign in to comment.