Skip to content

Commit 8e42fc5

Browse files
taoyuantaoyuan
andauthored
fix: allow data:image/* URLs in markdown renderer (anomalyco#491)
The isSafeUrl function was blocking all data: URLs including data:image/jpeg;base64,... returned by AI image generation models. This caused markdown images like ![image](data:image/jpeg;base64,...) to render with empty src, showing only the alt text 'Image'. Now data:image/* URIs are whitelisted while other data: schemes (e.g. data:text/html) remain blocked to prevent XSS. Co-authored-by: taoyuan <[email protected]>
1 parent 6120ad5 commit 8e42fc5

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

‎packages/app/src/app/components/part-view.tsx‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,12 @@ function createCustomRenderer(tone: "light" | "dark") {
5656
s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
5757

5858
const isSafeUrl = (url: string) => {
59-
const protocol = (url || "").trim().toLowerCase();
60-
return !protocol.startsWith("javascript:") && !protocol.startsWith("data:");
59+
const normalized = (url || "").trim().toLowerCase();
60+
if (normalized.startsWith("javascript:")) return false;
61+
// Allow data:image/* URIs (base64-encoded images from AI models) but block
62+
// other data: schemes (e.g. data:text/html) which could be used for XSS.
63+
if (normalized.startsWith("data:")) return normalized.startsWith("data:image/");
64+
return true;
6165
};
6266

6367
renderer.html = ({ text }) => escapeHtml(text);

0 commit comments

Comments
 (0)