Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
0ea35096
Commit
0ea35096
authored
Feb 22, 2019
by
Rajat Jain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Limit number of characters allowed in mermaidjs
parent
9a4ef1e3
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
0 deletions
+27
-0
app/assets/javascripts/behaviors/markdown/render_mermaid.js
app/assets/javascripts/behaviors/markdown/render_mermaid.js
+19
-0
changelogs/unreleased/security-mermaid.yml
changelogs/unreleased/security-mermaid.yml
+5
-0
locale/gitlab.pot
locale/gitlab.pot
+3
-0
No files found.
app/assets/javascripts/behaviors/markdown/render_mermaid.js
View file @
0ea35096
import
flash
from
'
~/flash
'
;
import
flash
from
'
~/flash
'
;
import
{
sprintf
,
__
}
from
'
../../locale
'
;
// Renders diagrams and flowcharts from text using Mermaid in any element with the
// Renders diagrams and flowcharts from text using Mermaid in any element with the
// `js-render-mermaid` class.
// `js-render-mermaid` class.
...
@@ -14,6 +15,9 @@ import flash from '~/flash';
...
@@ -14,6 +15,9 @@ import flash from '~/flash';
// </pre>
// </pre>
//
//
// This is an arbitary number; Can be iterated upon when suitable.
const
MAX_CHAR_LIMIT
=
5000
;
export
default
function
renderMermaid
(
$els
)
{
export
default
function
renderMermaid
(
$els
)
{
if
(
!
$els
.
length
)
return
;
if
(
!
$els
.
length
)
return
;
...
@@ -34,6 +38,21 @@ export default function renderMermaid($els) {
...
@@ -34,6 +38,21 @@ export default function renderMermaid($els) {
$els
.
each
((
i
,
el
)
=>
{
$els
.
each
((
i
,
el
)
=>
{
const
source
=
el
.
textContent
;
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.
// Remove any extra spans added by the backend syntax highlighting.
Object
.
assign
(
el
,
{
textContent
:
source
});
Object
.
assign
(
el
,
{
textContent
:
source
});
...
...
changelogs/unreleased/security-mermaid.yml
0 → 100644
View file @
0ea35096
---
title
:
Limit mermaid rendering to 5K characters
merge_request
:
author
:
type
:
security
locale/gitlab.pot
View file @
0ea35096
...
@@ -1299,6 +1299,9 @@ msgstr ""
...
@@ -1299,6 +1299,9 @@ msgstr ""
msgid "Cannot modify managed Kubernetes cluster"
msgid "Cannot modify managed Kubernetes cluster"
msgstr ""
msgstr ""
msgid "Cannot render the image. Maximum character count (%{charLimit}) has been exceeded."
msgstr ""
msgid "Certificate"
msgid "Certificate"
msgstr ""
msgstr ""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment