feat: Allow All Safe Tags and Attributes When Sanitizing Chapter HTML (Closes #1715)

This commit is contained in:
Rajarshee Chatterjee
2026-01-20 09:26:32 +05:30
parent 3f9886a2e5
commit ab4eee31ce
+47 -15
View File
@@ -9,33 +9,65 @@ export const sanitizeChapterText = (
): string => {
const text = sanitizeHtml(html, {
allowedTags: sanitizeHtml.defaults.allowedTags.concat([
'html',
'head',
'body',
'link',
'style',
'meta',
'del',
'ins',
'img',
'i',
'em',
'b',
'a',
'div',
'ol',
'li',
'audio',
'video',
'source',
'object',
'svg',
'math',
'title',
'details',
'summary',
'ref',
]),
allowedAttributes: {
'*': ['data-*'],
a: ['href', 'class', 'id'],
div: ['class', 'id'],
img: ['src', 'class', 'id'],
'*': [
'data-*',
'class',
'id',
'lang',
'dir',
'title',
'epub:type',
'role',
'aria-label',
'aria-labelledby',
'aria-describedby',
],
a: ['href', 'name', 'target'],
img: ['src', 'srcset', 'alt', 'width', 'height', 'loading'],
ol: ['reversed', 'start', 'type'],
p: ['class', 'id'],
span: ['class', 'id'],
ref: ['href', 'class', 'id'],
ul: ['type'],
li: ['value'],
p: ['align'],
ref: ['href'],
blockquote: ['cite'],
table: ['border', 'cellpadding', 'cellspacing', 'width', 'summary'],
td: ['colspan', 'rowspan', 'align', 'valign'],
th: ['colspan', 'rowspan', 'align', 'valign', 'scope'],
audio: ['src', 'controls'],
video: ['src', 'controls', 'width', 'height'],
source: ['src', 'type', 'srcset'],
svg: ['width', 'height', 'viewBox', 'xmlns'],
q: ['cite'],
time: ['datetime'],
del: ['cite', 'datetime'],
ins: ['cite', 'datetime'],
link: ['rel', 'type', 'href', 'media'],
meta: ['charset', 'name', 'content', 'http-equiv'],
},
allowedSchemes: ['data', 'http', 'https', 'file'],
});
// Return the sanitized and updated HTML or an error message
return (
text ||
getString('readerScreen.emptyChapterMessage', {