From 2df5c9d355491ed6c3fe34659bb9db39be47d871 Mon Sep 17 00:00:00 2001 From: Jean-Louis Leysens Date: Mon, 22 Jun 2020 12:05:29 +0200 Subject: [PATCH] [7.8] [Ingest Pipelines] Encode URI component pipeline names (#69489) (#69549) * [Ingest Pipelines] Encode URI component pipeline names (#69489) * Properly encode URI component pipeline names * safely URI decode to handle % case # Conflicts: # x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_list/table.tsx * lint Co-authored-by: Elastic Machine --- .../sections/pipelines_clone/pipelines_clone.tsx | 4 +++- .../pipelines_create/pipelines_create.tsx | 2 +- .../sections/pipelines_edit/pipelines_edit.tsx | 6 ++++-- .../application/sections/pipelines_list/table.tsx | 5 ++++- .../sections/shared/attempt_to_uri_decode.ts | 15 +++++++++++++++ .../public/application/sections/shared/index.ts | 7 +++++++ 6 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 x-pack/plugins/ingest_pipelines/public/application/sections/shared/attempt_to_uri_decode.ts create mode 100644 x-pack/plugins/ingest_pipelines/public/application/sections/shared/index.ts diff --git a/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_clone/pipelines_clone.tsx b/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_clone/pipelines_clone.tsx index 4c857dc9c74f7..6dc7769ac02a9 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_clone/pipelines_clone.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_clone/pipelines_clone.tsx @@ -12,6 +12,7 @@ import { FormattedMessage } from '@kbn/i18n/react'; import { SectionLoading, useKibana } from '../../../shared_imports'; import { PipelinesCreate } from '../pipelines_create'; +import { attemptToURIDecode } from '../shared'; export interface ParamProps { sourceName: string; @@ -25,8 +26,9 @@ export const PipelinesClone: FunctionComponent> const { sourceName } = props.match.params; const { services } = useKibana(); + const decodedSourceName = attemptToURIDecode(sourceName); const { error, data: pipeline, isLoading, isInitialRequest } = services.api.useLoadPipeline( - decodeURIComponent(sourceName) + decodedSourceName ); useEffect(() => { diff --git a/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_create/pipelines_create.tsx b/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_create/pipelines_create.tsx index b495e142561fa..acca1c4e03f40 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_create/pipelines_create.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_create/pipelines_create.tsx @@ -50,7 +50,7 @@ export const PipelinesCreate: React.FunctionComponent { diff --git a/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_edit/pipelines_edit.tsx b/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_edit/pipelines_edit.tsx index e1a7e5d6d1a36..e09cf4820771f 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_edit/pipelines_edit.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_edit/pipelines_edit.tsx @@ -22,6 +22,8 @@ import { Pipeline } from '../../../../common/types'; import { useKibana, SectionLoading } from '../../../shared_imports'; import { PipelineForm } from '../../components'; +import { attemptToURIDecode } from '../shared'; + interface MatchParams { name: string; } @@ -37,7 +39,7 @@ export const PipelinesEdit: React.FunctionComponent(false); const [saveError, setSaveError] = useState(null); - const decodedPipelineName = decodeURI(decodeURIComponent(name)); + const decodedPipelineName = attemptToURIDecode(name); const { error, data: pipeline, isLoading } = services.api.useLoadPipeline(decodedPipelineName); @@ -54,7 +56,7 @@ export const PipelinesEdit: React.FunctionComponent { diff --git a/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_list/table.tsx b/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_list/table.tsx index 30b9ee7a0a4ed..80cc5048b58d9 100644 --- a/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_list/table.tsx +++ b/x-pack/plugins/ingest_pipelines/public/application/sections/pipelines_list/table.tsx @@ -91,7 +91,10 @@ export const PipelineTable: FunctionComponent = ({ }), sortable: true, render: (name: string) => ( - + {name} ), diff --git a/x-pack/plugins/ingest_pipelines/public/application/sections/shared/attempt_to_uri_decode.ts b/x-pack/plugins/ingest_pipelines/public/application/sections/shared/attempt_to_uri_decode.ts new file mode 100644 index 0000000000000..fe5a0d7932cbb --- /dev/null +++ b/x-pack/plugins/ingest_pipelines/public/application/sections/shared/attempt_to_uri_decode.ts @@ -0,0 +1,15 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export const attemptToURIDecode = (value: string) => { + let result: string; + try { + result = decodeURI(decodeURIComponent(value)); + } catch (e) { + result = value; + } + return result; +}; diff --git a/x-pack/plugins/ingest_pipelines/public/application/sections/shared/index.ts b/x-pack/plugins/ingest_pipelines/public/application/sections/shared/index.ts new file mode 100644 index 0000000000000..9326d13851387 --- /dev/null +++ b/x-pack/plugins/ingest_pipelines/public/application/sections/shared/index.ts @@ -0,0 +1,7 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export { attemptToURIDecode } from './attempt_to_uri_decode';