mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
* [ML] Set noopener feature for custom URLs which use absolute URLs * [ML] Add comments around regex testing for external URL
This commit is contained in:
parent
7c1ed64c03
commit
0468537fd0
1 changed files with 5 additions and 2 deletions
|
@ -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');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue