From aefe6486cf0d193067112b90145083d73b96bfef Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Fri, 4 Dec 2020 16:51:40 +0000 Subject: Add latest changes from gitlab-org/security/gitlab@13-6-stable-ee --- .../behaviors/markdown/render_mermaid.js | 32 +++++++++-- app/controllers/explore/projects_controller.rb | 4 +- app/controllers/search_controller.rb | 1 - app/finders/projects_finder.rb | 4 ++ app/graphql/types/user_type.rb | 6 +- app/presenters/user_presenter.rb | 14 +++++ app/views/explore/projects/_projects.html.haml | 6 +- .../security-296-private_profile_exposure.yml | 5 ++ changelogs/unreleased/security-mermaid-rc-13-6.yml | 5 ++ ...-prevent-short-searches-in-explore-projects.yml | 5 ++ .../unreleased/security-search-term-logged.yml | 5 ++ config/application.rb | 1 + spec/controllers/search_controller_spec.rb | 2 +- .../explore/user_explores_projects_spec.rb | 11 ++++ spec/features/markdown/mermaid_spec.rb | 65 ++++++++++++++++++++++ spec/finders/projects_finder_spec.rb | 23 ++++++++ spec/requests/api/graphql/user_query_spec.rb | 46 ++++++++++++++- 17 files changed, 220 insertions(+), 15 deletions(-) create mode 100644 changelogs/unreleased/security-296-private_profile_exposure.yml create mode 100644 changelogs/unreleased/security-mermaid-rc-13-6.yml create mode 100644 changelogs/unreleased/security-prevent-short-searches-in-explore-projects.yml create mode 100644 changelogs/unreleased/security-search-term-logged.yml diff --git a/app/assets/javascripts/behaviors/markdown/render_mermaid.js b/app/assets/javascripts/behaviors/markdown/render_mermaid.js index 233c5f84340..602f156dbf0 100644 --- a/app/assets/javascripts/behaviors/markdown/render_mermaid.js +++ b/app/assets/javascripts/behaviors/markdown/render_mermaid.js @@ -18,7 +18,13 @@ import { __, sprintf } from '~/locale'; // // This is an arbitrary number; Can be iterated upon when suitable. -const MAX_CHAR_LIMIT = 5000; +const MAX_CHAR_LIMIT = 2000; +// Max # of mermaid blocks that can be rendered in a page. +const MAX_MERMAID_BLOCK_LIMIT = 50; +// Keep a map of mermaid blocks we've already rendered. +const elsProcessingMap = new WeakMap(); +let renderedMermaidBlocks = 0; + let mermaidModule = {}; function importMermaidModule() { @@ -110,13 +116,22 @@ function renderMermaids($els) { let renderedChars = 0; $els.each((i, el) => { + // Skipping all the elements which we've already queued in requestIdleCallback + if (elsProcessingMap.has(el)) { + return; + } + const { source } = fixElementSource(el); /** - * Restrict the rendering to a certain amount of character to - * prevent mermaidjs from hanging up the entire thread and - * causing a DoS. + * Restrict the rendering to a certain amount of character + * and mermaid blocks to prevent mermaidjs from hanging + * up the entire thread and causing a DoS. */ - if ((source && source.length > MAX_CHAR_LIMIT) || renderedChars > MAX_CHAR_LIMIT) { + if ( + (source && source.length > MAX_CHAR_LIMIT) || + renderedChars > MAX_CHAR_LIMIT || + renderedMermaidBlocks >= MAX_MERMAID_BLOCK_LIMIT + ) { const html = `