Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/brave-singers-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"streamdown": patch
---

harden image security
3 changes: 3 additions & 0 deletions apps/website/app/components/styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export const Styles = () => (
<Section
description="Streamdown comes with built-in Tailwind classes for common Markdown components — headings, lists, code blocks, and more."
markdown={markdown}
streamdownProps={{
allowedImagePrefixes: ['https://placehold.co'],
}}
title="Built-in typography styles"
/>
);
11 changes: 9 additions & 2 deletions packages/streamdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,27 @@ export const Streamdown = memo(
() => () => rehypeKatex({ errorColor: 'var(--color-muted-foreground)' }),
[]
);
const origin = useMemo(() => {
if (typeof window === 'undefined') {
return;
}

return window.location.origin;
}, []);

return (
<ShikiThemeContext.Provider value={shikiTheme}>
<div className={cn('space-y-4', className)} {...props}>
{blocks.map((block, index) => (
<Block
allowedImagePrefixes={allowedImagePrefixes ?? ['*']}
allowedImagePrefixes={allowedImagePrefixes ?? ['self']}
allowedLinkPrefixes={allowedLinkPrefixes ?? ['*']}
components={{
...defaultComponents,
...components,
}}
content={block}
defaultOrigin={defaultOrigin}
defaultOrigin={defaultOrigin ?? origin}
// biome-ignore lint/suspicious/noArrayIndexKey: "required"
key={`${generatedId}-block_${index}`}
rehypePlugins={[rehypeKatexPlugin, ...(rehypePlugins ?? [])]}
Expand Down