Skip to content

Commit fd795a2

Browse files
committed
fix: escape HTML in image, link, and media components to prevent XSS vulnerabilities
1 parent f8ec7ac commit fd795a2

3 files changed

Lines changed: 9 additions & 7 deletions

File tree

src/core/render/compiler/image.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getAndRemoveConfig } from '../utils.js';
1+
import { escapeHtml, getAndRemoveConfig } from '../utils.js';
22
import { isAbsolutePath, getPath, getParentPath } from '../../router/util.js';
33

44
export const imageCompiler = ({ renderer, contentBase, router }) =>
@@ -42,7 +42,7 @@ export const imageCompiler = ({ renderer, contentBase, router }) =>
4242
url = getPath(contentBase, getParentPath(router.getCurrentPath()), href);
4343
}
4444

45-
return /* html */ `<img src="${url}" data-origin="${href}" alt="${text}" ${attrs.join(
45+
return /* html */ `<img src="${escapeHtml(url)}" data-origin="${escapeHtml(href)}" alt="${text}" ${attrs.join(
4646
' ',
4747
)} />`;
4848
});

src/core/render/compiler/link.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getAndRemoveConfig } from '../utils.js';
1+
import { escapeHtml, getAndRemoveConfig } from '../utils.js';
22
import { isAbsolutePath } from '../../router/util.js';
33

44
export const linkCompiler = ({
@@ -68,5 +68,5 @@ export const linkCompiler = ({
6868
attrs.push(`title="${title}"`);
6969
}
7070

71-
return /* html */ `<a href="${href}" ${attrs.join(' ')}>${text}</a>`;
71+
return /* html */ `<a href="${escapeHtml(href)}" ${attrs.join(' ')}>${text}</a>`;
7272
});

src/core/render/compiler/media.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { escapeHtml } from '../utils';
2+
13
export const compileMedia = {
24
markdown(url) {
35
return {
@@ -11,19 +13,19 @@ export const compileMedia = {
1113
},
1214
iframe(url, title) {
1315
return {
14-
html: `<iframe src="${url}" ${
16+
html: `<iframe src="${escapeHtml(url)}" ${
1517
title || 'width=100% height=400'
1618
}></iframe>`,
1719
};
1820
},
1921
video(url, title) {
2022
return {
21-
html: `<video src="${url}" ${title || 'controls'}>Not Supported</video>`,
23+
html: `<video src="${escapeHtml(url)}" ${title || 'controls'}>Not Supported</video>`,
2224
};
2325
},
2426
audio(url, title) {
2527
return {
26-
html: `<audio src="${url}" ${title || 'controls'}>Not Supported</audio>`,
28+
html: `<audio src="${escapeHtml(url)}" ${title || 'controls'}>Not Supported</audio>`,
2729
};
2830
},
2931
code(url, title) {

0 commit comments

Comments
 (0)