Skip to content
Snippets Groups Projects
Commit eeb1974a authored by Yorick Peterse's avatar Yorick Peterse
Browse files

Merge branch 'security-mermaid-11-8' into '11-8-stable'

Limit number of characters allowed in mermaidjs

See merge request gitlab/gitlabhq!2978
parents ce138642 d50ad7e6
No related branches found
No related tags found
No related merge requests found
import flash from '~/flash';
import { sprintf, __ } from '../../locale';
 
// Renders diagrams and flowcharts from text using Mermaid in any element with the
// `js-render-mermaid` class.
Loading
Loading
@@ -14,6 +15,9 @@ import flash from '~/flash';
// </pre>
//
 
// This is an arbitary number; Can be iterated upon when suitable.
const MAX_CHAR_LIMIT = 5000;
export default function renderMermaid($els) {
if (!$els.length) return;
 
Loading
Loading
@@ -34,6 +38,21 @@ export default function renderMermaid($els) {
$els.each((i, el) => {
const source = el.textContent;
 
/**
* Restrict the rendering to a certain amount of character to
* prevent mermaidjs from hanging up the entire thread and
* causing a DoS.
*/
if (source && source.length > MAX_CHAR_LIMIT) {
el.textContent = sprintf(
__(
'Cannot render the image. Maximum character count (%{charLimit}) has been exceeded.',
),
{ charLimit: MAX_CHAR_LIMIT },
);
return;
}
// Remove any extra spans added by the backend syntax highlighting.
Object.assign(el, { textContent: source });
 
Loading
Loading
---
title: Limit mermaid rendering to 5K characters
merge_request:
author:
type: security
Loading
Loading
@@ -1293,6 +1293,9 @@ msgstr ""
msgid "Cannot modify managed Kubernetes cluster"
msgstr ""
 
msgid "Cannot render the image. Maximum character count (%{charLimit}) has been exceeded."
msgstr ""
msgid "Certificate"
msgstr ""
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment