This commit is contained in:
Timothy Jaeryang Baek committed 2026-07-17 06:28:07 -04:00
1 parent ff49217206
commit 890bfd0d97
3 files changed
+9 -6

No files matched your search

@@ -96,7 +96,7 @@
> >
{/if} {/if}
{:else if token.type === 'image'} {:else if token.type === 'image'}
<Image src={token.href} alt={token.text} /> <Image src={token.href} alt={token.text} allowExternal={true} />
{:else if token.type === 'strong'} {:else if token.type === 'strong'}
<strong><svelte:self id={`${id}-strong`} tokens={token.tokens} {onSourceClick} /></strong> <strong><svelte:self id={`${id}-strong`} tokens={token.tokens} {onSourceClick} /></strong>
{:else if token.type === 'em'} {:else if token.type === 'em'}
+2 -1
View File
@@ -9,6 +9,7 @@
export let src = ''; export let src = '';
export let alt = ''; export let alt = '';
export let allowExternal = false;
export let className = ` w-full ${($settings?.highContrastMode ?? false) ? '' : 'outline-hidden focus:outline-hidden'}`; export let className = ` w-full ${($settings?.highContrastMode ?? false) ? '' : 'outline-hidden focus:outline-hidden'}`;
@@ -20,7 +21,7 @@
const i18n = getContext('i18n'); const i18n = getContext('i18n');
let _src = ''; let _src = '';
$: _src = safeImageUrl(src.startsWith('/') ? `${WEBUI_BASE_URL}${src}` : src); $: _src = safeImageUrl(src.startsWith('/') ? `${WEBUI_BASE_URL}${src}` : src, allowExternal);
let showImagePreview = false; let showImagePreview = false;
</script> </script>
+6 -4
View File
@@ -11,18 +11,20 @@ const PLACEHOLDER_IMAGE = '/favicon.png';
* - data:image/* URIs * - data:image/* URIs
* - Same-origin URLs (starting with WEBUI_BASE_URL) * - Same-origin URLs (starting with WEBUI_BASE_URL)
* - Gravatar URLs (https://www.gravatar.com/avatar/) * - Gravatar URLs (https://www.gravatar.com/avatar/)
* - External HTTP(S) URLs when allowExternal is true
* *
* All other URLs (including arbitrary http(s):// origins) are rejected to * All other URLs (including arbitrary http(s):// origins by default) are
* prevent client-side IP/UA/Referer leaks to attacker-controlled servers. * rejected to prevent client-side IP/UA/Referer leaks to attacker-controlled servers.
*/ */
export function safeImageUrl(url: string): string { export function safeImageUrl(url: string, allowExternal = false): string {
if (!url || url === '') { if (!url || url === '') {
return `${WEBUI_BASE_URL}${PLACEHOLDER_IMAGE}`; return `${WEBUI_BASE_URL}${PLACEHOLDER_IMAGE}`;
} }
if ( if (
url.startsWith(WEBUI_BASE_URL) || (WEBUI_BASE_URL && url.startsWith(WEBUI_BASE_URL)) ||
url.startsWith('https://www.gravatar.com/avatar/') || url.startsWith('https://www.gravatar.com/avatar/') ||
(allowExternal && /^https?:\/\//i.test(url)) ||
url.startsWith('data:') || url.startsWith('data:') ||
url.startsWith('/') url.startsWith('/')
) { ) {