Skip to content

Commit 90df609

Browse files
fix: disable open link button for unsafe link
Signed-off-by: Luka Trovic <luka@nextcloud.com>
1 parent 1e47bd1 commit 90df609

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

src/components/Link/LinkBubbleView.vue

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
</div>
1313
<!-- open link -->
1414
<NcButton
15-
:title="t('text', 'Open link')"
16-
:aria-label="t('text', 'Open link')"
15+
:disabled="!isSafeHref"
16+
:title="openLinkTitle"
17+
:aria-label="openLinkTitle"
1718
variant="tertiary"
1819
@click="openLink(href)">
1920
<template #icon>
@@ -101,6 +102,7 @@ import { useOpenLinkHandler } from '../../composables/useOpenLinkHandler.ts'
101102
import PreviewOptions from '../Editor/PreviewOptions.vue'
102103
103104
const PROTOCOLS_WITH_PREVIEW = ['http:', 'https:']
105+
const SAFE_PROTOCOLS = ['http:', 'https:', 'mailto:', 'tel:']
104106
105107
export default {
106108
name: 'LinkBubbleView',
@@ -170,6 +172,27 @@ export default {
170172
return false
171173
}
172174
},
175+
176+
isSafeHref() {
177+
try {
178+
const url = new URL(this.href, window.location)
179+
return !!this.href && SAFE_PROTOCOLS.includes(url.protocol)
180+
} catch {
181+
return false
182+
}
183+
},
184+
185+
openLinkTitle() {
186+
if (this.isSafeHref) {
187+
return t('text', 'Open link')
188+
}
189+
190+
if (!this.href) {
191+
return t('text', 'No link available to open')
192+
}
193+
194+
return t('text', 'Cannot open links with unsafe protocols')
195+
},
173196
},
174197
175198
watch: {

0 commit comments

Comments
 (0)