Sanitizsation of incoming variables that are added to the userStyles

This commit is contained in:
Knut Sveidqvist
2022-06-21 21:46:37 +02:00
parent ec2da8e85d
commit 610f154c74
3 changed files with 38 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
<html>
<script>
// %%{ init: { "logLevel":0, "themeVariables" : { "primaryColor": "#fff000","textColor": "green","apa":"} #target { background-color: crimson }" } } }%%
</script>
<body>
<div id="target">
<h1>This element does not belong to the SVG but we can style it</h1>
</div>
<svg id="diagram">
</svg>
<script src="./mermaid.js"></script>
<script>
mermaid.initialize({ startOnLoad: false, logLevel: 0 });
const graph = `
%%{ init: { "fontFamily" : "&125; * { background: red }" } }%%
graph TD
A[Goose]
`;
const diagram = document.getElementById('diagram');
const svg = mermaid.render('diagram-svg', graph);
diagram.innerHTML = svg;
</script>
</body>
</html>

View File

@@ -385,6 +385,8 @@ const render = function (id, _txt, cb, container) {
let userStyles = ''; let userStyles = '';
// user provided theme CSS // user provided theme CSS
// If you add more configuration driven data into the user styles make sure that the value is
// sanitized bye the santiizeCSS function
if (cnf.themeCSS !== undefined) { if (cnf.themeCSS !== undefined) {
userStyles += `\n${cnf.themeCSS}`; userStyles += `\n${cnf.themeCSS}`;
} }

View File

@@ -1032,6 +1032,14 @@ export const directiveSanitizer = (args) => {
log.debug('sanitizing themeCss option'); log.debug('sanitizing themeCss option');
args[key] = sanitizeCss(args[key]); args[key] = sanitizeCss(args[key]);
} }
if (key.indexOf('fontFamily') >= 0) {
log.debug('sanitizing fontFamily option');
args[key] = sanitizeCss(args[key]);
}
if (key.indexOf('altFontFamily') >= 0) {
log.debug('sanitizing altFontFamily option');
args[key] = sanitizeCss(args[key]);
}
if (configKeys.indexOf(key) < 0) { if (configKeys.indexOf(key) < 0) {
log.debug('sanitize deleting option', key); log.debug('sanitize deleting option', key);
delete args[key]; delete args[key];