mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-11-19 20:24:16 +01:00
fix: Use DOMPurify to sanitize HTML content
on-behalf-of: @Mermaid-Chart <hello@mermaidchart.com>
This commit is contained in:
@@ -26,6 +26,7 @@ import type {
|
|||||||
} from './classTypes.js';
|
} from './classTypes.js';
|
||||||
import type { Node, Edge } from '../../rendering-util/types.js';
|
import type { Node, Edge } from '../../rendering-util/types.js';
|
||||||
import type { DiagramDB } from '../../diagram-api/types.js';
|
import type { DiagramDB } from '../../diagram-api/types.js';
|
||||||
|
import DOMPurify from 'dompurify';
|
||||||
|
|
||||||
const MERMAID_DOM_ID_PREFIX = 'classId-';
|
const MERMAID_DOM_ID_PREFIX = 'classId-';
|
||||||
let classCounter = 0;
|
let classCounter = 0;
|
||||||
@@ -504,7 +505,7 @@ export class ClassDB implements DiagramDB {
|
|||||||
const rect = (event.currentTarget as Element).getBoundingClientRect();
|
const rect = (event.currentTarget as Element).getBoundingClientRect();
|
||||||
tooltipElem.transition().duration(200).style('opacity', '.9');
|
tooltipElem.transition().duration(200).style('opacity', '.9');
|
||||||
tooltipElem
|
tooltipElem
|
||||||
.html(this.escapeHtml(title).replace(/<br\/>/g, '<br/>'))
|
.html(DOMPurify.sanitize(title))
|
||||||
.style('left', `${window.scrollX + rect.left + rect.width / 2}px`)
|
.style('left', `${window.scrollX + rect.left + rect.width / 2}px`)
|
||||||
.style('top', `${window.scrollY + rect.bottom + 4}px`);
|
.style('top', `${window.scrollY + rect.bottom + 4}px`);
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import type {
|
|||||||
FlowVertex,
|
FlowVertex,
|
||||||
FlowVertexTypeParam,
|
FlowVertexTypeParam,
|
||||||
} from './types.js';
|
} from './types.js';
|
||||||
|
import DOMPurify from 'dompurify';
|
||||||
interface LinkData {
|
interface LinkData {
|
||||||
id: string;
|
id: string;
|
||||||
}
|
}
|
||||||
@@ -596,7 +596,7 @@ You have to call mermaid.initialize.`
|
|||||||
.text(el.attr('title'))
|
.text(el.attr('title'))
|
||||||
.style('left', window.scrollX + rect.left + (rect.right - rect.left) / 2 + 'px')
|
.style('left', window.scrollX + rect.left + (rect.right - rect.left) / 2 + 'px')
|
||||||
.style('top', window.scrollY + rect.bottom + 'px');
|
.style('top', window.scrollY + rect.bottom + 'px');
|
||||||
tooltipElem.html(tooltipElem.html().replace(/<br\/>/g, '<br/>'));
|
tooltipElem.html(DOMPurify.sanitize(title));
|
||||||
el.classed('hover', true);
|
el.classed('hover', true);
|
||||||
})
|
})
|
||||||
.on('mouseout', (e: MouseEvent) => {
|
.on('mouseout', (e: MouseEvent) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user