Skip to content

Commit d4b5996

Browse files
committed
chore: add URL validation for subscription icon previews
1 parent e53940b commit d4b5996

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

dashboard/src/pages/_dashboard.settings.subscriptions.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,18 @@ export default function SubscriptionSettings() {
408408
const [newDescLang, setNewDescLang] = useState<'fa' | 'en' | 'ru' | 'zh'>('en')
409409
const [newAppDescription, setNewAppDescription] = useState<Record<'fa' | 'en' | 'ru' | 'zh', string>>({} as any)
410410

411+
const isValidIconUrl = (url: string): boolean => {
412+
if (!url || url.trim() === '') return false
413+
414+
try {
415+
const urlObj = new URL(url)
416+
// Only allow HTTP and HTTPS protocols
417+
return urlObj.protocol === 'http:' || urlObj.protocol === 'https:'
418+
} catch {
419+
return false
420+
}
421+
}
422+
411423
useEffect(() => {
412424
// reset icon error state when URL changes
413425
setNewAppIconBroken(false)
@@ -1211,7 +1223,7 @@ export default function SubscriptionSettings() {
12111223
<div className="flex items-center gap-2">
12121224
<Input value={newAppIconUrl} onChange={e => setNewAppIconUrl(e.target.value)} placeholder={t('settings.subscriptions.applications.iconUrlPlaceholder', { defaultValue: 'https://...' })} className="h-8 text-xs font-mono" dir="ltr" />
12131225
{/* live preview */}
1214-
{newAppIconUrl && !newAppIconBroken ? (
1226+
{newAppIconUrl && !newAppIconBroken && isValidIconUrl(newAppIconUrl) ? (
12151227
<img src={newAppIconUrl} alt="icon" className="h-6 w-6 rounded-sm object-cover" onError={() => setNewAppIconBroken(true)} />
12161228
) : (
12171229
<div className="h-6 w-6 rounded-sm bg-muted text-muted-foreground/80 inline-flex items-center justify-center">

0 commit comments

Comments
 (0)