Skip to content

Commit 10661ef

Browse files
committed
Preserve safe data image sources
1 parent 19688b3 commit 10661ef

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

src/render/mdx.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ const sanitizeSchema: Schema = {
3838
h5: [...(defaultSchema.attributes?.h5 ?? []), "id"],
3939
h6: [...(defaultSchema.attributes?.h6 ?? []), "id"],
4040
code: [...(defaultSchema.attributes?.code ?? []), ["className", /^language-[\w-]+$/]]
41+
},
42+
protocols: {
43+
...defaultSchema.protocols,
44+
src: [...(defaultSchema.protocols?.src ?? []), "data"]
4145
}
4246
};
4347

test/mdx-images.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { renderMdxToHtml } from "../src/render/mdx.js";
2+
3+
describe("MDX image rendering", () => {
4+
it("keeps safe data image sources", async () => {
5+
const html = await renderMdxToHtml(
6+
"![tiny red dot](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJ)",
7+
"Image Test"
8+
);
9+
10+
expect(html).toContain('src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJ"');
11+
expect(html).toContain('alt="tiny red dot"');
12+
});
13+
});

0 commit comments

Comments
 (0)