Skip to content
Snippets Groups Projects
Commit 4b229185 authored by GitLab Release Tools Bot's avatar GitLab Release Tools Bot
Browse files

Merge branch 'security-prevent_math_markdown_rendering_dos-14-7' into '14-7-stable-ee'

Prevent DOS when rendering math markdown

See merge request gitlab-org/security/gitlab!2200
parents f5fb8132 f01674f2
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -25,7 +25,14 @@ module Banzai
 
DOLLAR_SIGN = '$'
 
# Limit to how many nodes can be marked as math elements.
# Prevents timeouts for large notes.
# For more information check: https://gitlab.com/gitlab-org/gitlab/-/issues/341832
RENDER_NODES_LIMIT = 50
def call
nodes_count = 0
doc.xpath(XPATH_CODE).each do |code|
closing = code.next
opening = code.previous
Loading
Loading
@@ -41,6 +48,9 @@ module Banzai
code[STYLE_ATTRIBUTE] = 'inline'
closing.content = closing.content[1..]
opening.content = opening.content[0..-2]
nodes_count += 1
break if nodes_count >= RENDER_NODES_LIMIT
end
end
 
Loading
Loading
Loading
Loading
@@ -126,4 +126,12 @@ RSpec.describe Banzai::Filter::MathFilter do
expect(before.to_s).to eq '$'
expect(after.to_s).to eq '$'
end
it 'limits how many elements can be marked as math' do
stub_const('Banzai::Filter::MathFilter::RENDER_NODES_LIMIT', 2)
doc = filter('$<code>2+2</code>$ + $<code>3+3</code>$ + $<code>4+4</code>$')
expect(doc.search('.js-render-math').count).to eq(2)
end
end
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