Commit 8d89fb21 authored by Gary Holtz's avatar Gary Holtz Committed by Alex Kalderimis

Configurable setting for max text size for highlighting

parent 6d4e4385
---
title: Ensure highlighting limits are documented, configurable, and monitorable
merge_request: 60445
author:
type: added
......@@ -1270,6 +1270,10 @@ production: &base
# matomo_site_id: '_your_matomo_site_id'
# matomo_disable_cookies: false
## Maximum file size for syntax highlighting
## https://docs.gitlab.com/ee/user/project/highlighting.html
# maximum_text_highlight_size_kilobytes: 512
rack_attack:
git_basic_auth:
# Rack Attack IP banning enabled
......
......@@ -856,6 +856,7 @@ Settings['extra'] ||= Settingslogic.new({})
Settings.extra['matomo_site_id'] ||= Settings.extra['piwik_site_id'] if Settings.extra['piwik_site_id'].present?
Settings.extra['matomo_url'] ||= Settings.extra['piwik_url'] if Settings.extra['piwik_url'].present?
Settings.extra['matomo_disable_cookies'] = false if Settings.extra['matomo_disable_cookies'].nil?
Settings.extra['maximum_text_highlight_size_kilobytes'] = Settings.extra.fetch('maximum_text_highlight_size_kilobytes', 512).kilobytes
#
# Rack::Attack settings
......
......@@ -4,7 +4,6 @@ module Gitlab
class Highlight
TIMEOUT_BACKGROUND = 30.seconds
TIMEOUT_FOREGROUND = 1.5.seconds
MAXIMUM_TEXT_HIGHLIGHT_SIZE = 512.kilobytes
def self.highlight(blob_name, blob_content, language: nil, plain: false)
new(blob_name, blob_content, language: language)
......@@ -23,7 +22,7 @@ module Gitlab
def highlight(text, continue: false, plain: false, context: {})
@context = context
plain ||= text.length > MAXIMUM_TEXT_HIGHLIGHT_SIZE
plain ||= text.length > maximum_text_highlight_size
highlighted_text = highlight_text(text, continue: continue, plain: plain)
highlighted_text = link_dependencies(text, highlighted_text) if blob_name
......@@ -78,5 +77,9 @@ module Gitlab
def link_dependencies(text, highlighted_text)
Gitlab::DependencyLinker.link(blob_name, text, highlighted_text)
end
def maximum_text_highlight_size
Gitlab.config.extra['maximum_text_highlight_size_kilobytes']
end
end
end
......@@ -47,8 +47,9 @@ RSpec.describe Gitlab::Highlight do
end
it 'returns plain version for long content' do
stub_const('Gitlab::Highlight::MAXIMUM_TEXT_HIGHLIGHT_SIZE', 1)
result = described_class.highlight(file_name, content)
stub_config(extra: { 'maximum_text_highlight_size_kilobytes' => 0.0001 } ) # 1.024 bytes
result = described_class.highlight(file_name, content) # content is 44 bytes
expect(result).to eq(%[<span id="LC1" class="line" lang="">(make-pathname :defaults name</span>\n<span id="LC2" class="line" lang="">:type "assem")</span>])
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment