From 76857f14e2f624572761a1ca4413021fbc9e1239 Mon Sep 17 00:00:00 2001 From: Shahzad Date: Fri, 25 Oct 2024 16:33:26 +0200 Subject: [PATCH] [Synthetics] URL validation softens to allow vars usage !! (#197797) ## Summary URL validation softens to allow vars usage !! For example ` should urls: "${url}" interpolate --params '{"url": "my-url"}'` (cherry picked from commit 3b05b6a7a83df7ff8b929dbbb60c639cc11101d8) --- .../project_monitor/normalizers/common_fields.test.ts | 8 ++++++++ .../project_monitor/normalizers/common_fields.ts | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/x-pack/plugins/observability_solution/synthetics/server/synthetics_service/project_monitor/normalizers/common_fields.test.ts b/x-pack/plugins/observability_solution/synthetics/server/synthetics_service/project_monitor/normalizers/common_fields.test.ts index b4dd34952c7a8..227fff690af53 100644 --- a/x-pack/plugins/observability_solution/synthetics/server/synthetics_service/project_monitor/normalizers/common_fields.test.ts +++ b/x-pack/plugins/observability_solution/synthetics/server/synthetics_service/project_monitor/normalizers/common_fields.test.ts @@ -21,6 +21,14 @@ describe('isValidUrl', () => { it('returns true for valid URL', () => { expect(isValidURL('https://elastic.co')).toBeTruthy(); }); + + it('returns skips validation vars', () => { + expect(isValidURL('${urlParam}')).toBeTruthy(); + }); + + it('returns skips validation vars with http', () => { + expect(isValidURL('http://${urlParam}')).toBeTruthy(); + }); }); describe('getUrlsField', () => { diff --git a/x-pack/plugins/observability_solution/synthetics/server/synthetics_service/project_monitor/normalizers/common_fields.ts b/x-pack/plugins/observability_solution/synthetics/server/synthetics_service/project_monitor/normalizers/common_fields.ts index 0a3aa8295a94d..c67e7decbe984 100644 --- a/x-pack/plugins/observability_solution/synthetics/server/synthetics_service/project_monitor/normalizers/common_fields.ts +++ b/x-pack/plugins/observability_solution/synthetics/server/synthetics_service/project_monitor/normalizers/common_fields.ts @@ -8,6 +8,7 @@ import { omit, uniqBy } from 'lodash'; import { i18n } from '@kbn/i18n'; import { isValidNamespace } from '@kbn/fleet-plugin/common'; +import { hasNoParams } from '../../formatters/formatting_utils'; import { formatLocation } from '../../../../common/utils/location_formatter'; import { BrowserFields, @@ -408,6 +409,10 @@ export const getOptionalListField = (value?: string[] | string): string[] => { * @returns `true` if `new URL` does not throw an error, `false` otherwise */ export const isValidURL = (url: string): boolean => { + if (!hasNoParams(url)) { + // this is done to avoid parsing urls with variables + return true; + } try { new URL(url); return true;