refac: validate the citation embed URL before use (#29701)

A citation's embed_url now has to be an http or https URL, or protocol-relative, before it is opened or handed to the embed panel. Anything else falls back to the citation modal, which already renders the source.
This commit is contained in:
Classic298 2026-09-06 22:54:44 +02:00 committed by GitHub
parent cb942bb94c
commit 831b3b0df2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,6 +1,7 @@
<script lang="ts">
import { getContext } from 'svelte';
import { embed, showControls, showEmbeds } from '$lib/stores';
import { isValidHttpUrl } from '$lib/utils';
import CitationModal from './Citations/CitationModal.svelte';
@ -43,7 +44,11 @@
if (citations[index]?.source?.embed_url) {
const embedUrl = citations[index].source.embed_url;
if (embedUrl) {
// The embed panel renders anything it cannot read as a URL as raw HTML
if (
typeof embedUrl === 'string' &&
(isValidHttpUrl(embedUrl) || embedUrl.startsWith('//'))
) {
if (readOnly) {
// Open in new tab if readOnly
window.open(embedUrl, '_blank');