overleaf/services/web/frontend/js/features/source-editor/utils/url.ts
Alf Eaton e7827fbd57 Validate URL protocol before opening from Visual Editor tooltip (#18393)
GitOrigin-RevId: 1da255d3e8ccd91e8c8774d140ec663906be948f
2024-05-21 08:04:26 +00:00

11 lines
305 B
TypeScript

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')
}