Validate URL protocol before opening from Visual Editor tooltip (#18393)

GitOrigin-RevId: 1da255d3e8ccd91e8c8774d140ec663906be948f
This commit is contained in:
Alf Eaton
2024-05-21 08:04:26 +00:00
committed by Copybot
parent e9d4d26fec
commit e7827fbd57
5 changed files with 23 additions and 10 deletions
@@ -0,0 +1,11 @@
const ALLOWED_PROTOCOLS = ['https:', 'http:']
export const openURL = (content: string) => {
const url = new URL(content, document.location.href)
if (!ALLOWED_PROTOCOLS.includes(url.protocol)) {
throw new Error(`Not opening URL with protocol ${url.protocol}`)
}
window.open(url, '_blank')
}