Skip to content

Commit 1d28476

Browse files
authored
sanitize console urls (#1459)
1 parent 29d3402 commit 1d28476

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

www/src/components/create-cluster/steps/AuthenticationStep.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import styled, { CSSProp, useTheme } from 'styled-components'
1111

1212
import { useCreateClusterContext } from '../CreateClusterWizard'
13+
import { sanitizeConsoleUrl } from 'components/overview/clusters/all/AllClustersTableCols'
1314

1415
export function AuthenticationStep() {
1516
const theme = useTheme()
@@ -54,7 +55,7 @@ export function AuthenticationStep() {
5455
</span>
5556
<Button
5657
as="a"
57-
href={`https://${consoleUrl}`}
58+
href={sanitizeConsoleUrl(consoleUrl)}
5859
target="_blank"
5960
margin={`${theme.spacing.medium}px 0`}
6061
endIcon={<ArrowTopRightIcon />}

www/src/components/overview/clusters/SelfHostedTableCols.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ import { A, Div } from 'honorable'
1111
import { Link } from 'react-router-dom'
1212
import styled, { useTheme } from 'styled-components'
1313

14-
import { ClusterFragment, Source } from '../../../generated/graphql'
14+
import { Source } from '../../../generated/graphql'
1515
import { ProviderIcon } from '../../utils/ProviderIcon'
1616

1717
import ClusterHealth from './ClusterHealth'
1818
import ClusterOwner from './ClusterOwner'
19+
import { sanitizeConsoleUrl } from './all/AllClustersTableCols'
1920
import { ClusterListElement } from './clusterListUtils'
2021

2122
const clusterExists = (row: ClusterListElement): boolean =>
@@ -143,9 +144,10 @@ export const ColActions = columnHelper.accessor((row) => row.consoleUrl, {
143144
secondary
144145
startIcon={<ConsoleIcon color={theme.colors['icon-default']} />}
145146
as="a"
146-
href={`${row.consoleUrl}`}
147+
href={sanitizeConsoleUrl(row.consoleUrl)}
147148
target="_blank"
148149
rel="noopener noreferrer"
150+
onClick={(e) => e.stopPropagation()}
149151
>
150152
Go to Console
151153
</Button>

www/src/components/overview/clusters/all/AllClustersTableCols.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,10 @@ const ColActions = columnHelper.accessor((instance) => instance, {
121121
small
122122
startIcon={<ConsoleIcon color={theme.colors['icon-default']} />}
123123
as={Link}
124-
to={`https://${instance.consoleUrl}`}
124+
to={sanitizeConsoleUrl(instance.consoleUrl)}
125125
target="_blank"
126126
rel="noopener noreferrer"
127+
onClick={(e) => e.stopPropagation()}
127128
>
128129
Go to Console
129130
</Button>
@@ -144,3 +145,6 @@ export const allClustersCols = [
144145
ColOwner,
145146
ColActions,
146147
]
148+
149+
export const sanitizeConsoleUrl = (url: Nullable<string>) =>
150+
url ? `https://${url.replace(/^https?:\/\//, '')}` : ''

www/src/components/overview/clusters/plural-cloud/CloudInstanceTableCols.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { useTheme } from 'styled-components'
2222

2323
import { CellCaption, CellWrap } from '../SelfHostedTableCols'
2424
import { Link } from 'react-router-dom'
25+
import { sanitizeConsoleUrl } from '../all/AllClustersTableCols'
2526

2627
const columnHelper = createColumnHelper<ConsoleInstanceFragment>()
2728

@@ -172,9 +173,10 @@ const ColActions = columnHelper.accessor((instance) => instance, {
172173
small
173174
startIcon={<ConsoleIcon color={theme.colors['icon-default']} />}
174175
as={Link}
175-
to={`https://${instance.url}`}
176+
to={sanitizeConsoleUrl(instance.url)}
176177
target="_blank"
177178
rel="noopener noreferrer"
179+
onClick={(e) => e.stopPropagation()}
178180
>
179181
Go to Console
180182
</Button>

0 commit comments

Comments
 (0)