Skip to content

Commit

Permalink
[7.8] [Ingest Pipelines] Encode URI component pipeline names (#69489) (
Browse files Browse the repository at this point in the history
…#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 <elasticmachine@users.noreply.github.com>
  • Loading branch information
jloleysens and elasticmachine authored Jun 22, 2020
1 parent 59e6a6b commit 2df5c9d
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,8 +26,9 @@ export const PipelinesClone: FunctionComponent<RouteComponentProps<ParamProps>>
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(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const PipelinesCreate: React.FunctionComponent<RouteComponentProps & Prop
return;
}

history.push(BASE_PATH + `?pipeline=${pipeline.name}`);
history.push(BASE_PATH + `?pipeline=${encodeURIComponent(pipeline.name)}`);
};

const onCancel = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -37,7 +39,7 @@ export const PipelinesEdit: React.FunctionComponent<RouteComponentProps<MatchPar
const [isSaving, setIsSaving] = useState<boolean>(false);
const [saveError, setSaveError] = useState<any>(null);

const decodedPipelineName = decodeURI(decodeURIComponent(name));
const decodedPipelineName = attemptToURIDecode(name);

const { error, data: pipeline, isLoading } = services.api.useLoadPipeline(decodedPipelineName);

Expand All @@ -54,7 +56,7 @@ export const PipelinesEdit: React.FunctionComponent<RouteComponentProps<MatchPar
return;
}

history.push(BASE_PATH + `?pipeline=${updatedPipeline.name}`);
history.push(BASE_PATH + `?pipeline=${encodeURIComponent(updatedPipeline.name)}`);
};

const onCancel = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ export const PipelineTable: FunctionComponent<Props> = ({
}),
sortable: true,
render: (name: string) => (
<EuiLink href={`#${BASE_PATH}?pipeline=${name}`} data-test-subj="pipelineDetailsLink">
<EuiLink
href={`#${BASE_PATH}?pipeline=${encodeURIComponent(name)}`}
data-test-subj="pipelineDetailsLink"
>
{name}
</EuiLink>
),
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
};
Original file line number Diff line number Diff line change
@@ -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';

0 comments on commit 2df5c9d

Please sign in to comment.