Skip to content

Commit 9fd979e

Browse files
fixed defanged urls
1 parent 506d75a commit 9fd979e

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

src/utils/get-cipp-formatting.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,17 +1063,33 @@ export const getCippFormatting = (data, cellName, type, canReceive, flatten = tr
10631063
)
10641064
}
10651065

1066-
//if string starts with http, return a link
1066+
//if string starts with http, return a link - but only when it parses as a real
1067+
//absolute http(s) URL. Defanged URLs (e.g. https[:]//bad.com from Check) fail to
1068+
//parse and would otherwise render as a link relative to the CIPP instance, so
1069+
//those are shown as plain text with only the copy button.
10671070
if (typeof data === 'string' && data.toLowerCase().startsWith('http')) {
1068-
return isText ? (
1069-
data
1070-
) : (
1071+
let isValidUrl = false
1072+
try {
1073+
const parsedUrl = new URL(data)
1074+
isValidUrl = parsedUrl.protocol === 'http:' || parsedUrl.protocol === 'https:'
1075+
} catch {
1076+
isValidUrl = false
1077+
}
1078+
if (isText) {
1079+
return data
1080+
}
1081+
return isValidUrl ? (
10711082
<>
10721083
<Link href={data} target="_blank" rel="noreferrer">
10731084
URL
10741085
</Link>
10751086
<CippCopyToClipBoard text={data} />
10761087
</>
1088+
) : (
1089+
<>
1090+
{data}
1091+
<CippCopyToClipBoard text={data} />
1092+
</>
10771093
)
10781094
}
10791095

0 commit comments

Comments
 (0)