summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-02-25 16:30:40 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-02-25 16:30:40 +0000
commitb485c8c3723dc5aaba15ab9fa258010d1ec66d61 (patch)
tree36cd2260b2f31bc77ad313b644e5784160ce9104
parent479d579719c36f1b8706165c20f4525bc32bb451 (diff)
downloadgitlab-ce-b485c8c3723dc5aaba15ab9fa258010d1ec66d61.tar.gz
Add latest changes from gitlab-org/security/gitlab@14-8-stable-ee
-rw-r--r--app/assets/javascripts/mirrors/mirror_repos.js10
-rw-r--r--app/services/members/create_service.rb13
-rw-r--r--app/views/projects/mirrors/_authentication_method.html.haml2
-rw-r--r--lib/banzai/filter/math_filter.rb10
-rw-r--r--spec/lib/banzai/filter/math_filter_spec.rb8
-rw-r--r--spec/services/members/create_service_spec.rb24
6 files changed, 62 insertions, 5 deletions
diff --git a/app/assets/javascripts/mirrors/mirror_repos.js b/app/assets/javascripts/mirrors/mirror_repos.js
index e59da18fb77..5bf08be1ead 100644
--- a/app/assets/javascripts/mirrors/mirror_repos.js
+++ b/app/assets/javascripts/mirrors/mirror_repos.js
@@ -6,6 +6,8 @@ import { __ } from '~/locale';
import { hide } from '~/tooltips';
import SSHMirror from './ssh_mirror';
+const PASSWORD_FIELD_SELECTOR = '.js-mirror-password-field';
+
export default class MirrorRepos {
constructor(container) {
this.$container = $(container);
@@ -27,7 +29,6 @@ export default class MirrorRepos {
this.$passwordGroup = $('.js-password-group', this.$container);
this.$password = $('.js-password', this.$passwordGroup);
this.$authMethod = $('.js-auth-method', this.$form);
-
this.$keepDivergentRefsInput.on('change', () => this.updateKeepDivergentRefs());
this.$authMethod.on('change', () => this.togglePassword());
this.$password.on('input.updateUrl', () => this.debouncedUpdateUrl());
@@ -35,6 +36,13 @@ export default class MirrorRepos {
this.initMirrorSSH();
this.updateProtectedBranches();
this.updateKeepDivergentRefs();
+ MirrorRepos.resetPasswordField();
+ }
+
+ static resetPasswordField() {
+ if (document.querySelector(PASSWORD_FIELD_SELECTOR)) {
+ document.querySelector(PASSWORD_FIELD_SELECTOR).value = '';
+ }
}
initMirrorSSH() {
diff --git a/app/services/members/create_service.rb b/app/services/members/create_service.rb
index dc29bb2c6da..758fa2e67f1 100644
--- a/app/services/members/create_service.rb
+++ b/app/services/members/create_service.rb
@@ -19,6 +19,8 @@ module Members
end
def execute
+ raise Gitlab::Access::AccessDeniedError unless can?(current_user, create_member_permission(source), source)
+
validate_invite_source!
validate_invitable!
@@ -156,6 +158,17 @@ module Members
})
)
end
+
+ def create_member_permission(source)
+ case source
+ when Group
+ :admin_group_member
+ when Project
+ :admin_project_member
+ else
+ raise "Unknown source type: #{source.class}!"
+ end
+ end
end
end
diff --git a/app/views/projects/mirrors/_authentication_method.html.haml b/app/views/projects/mirrors/_authentication_method.html.haml
index e9e3645d7f2..28b433b2514 100644
--- a/app/views/projects/mirrors/_authentication_method.html.haml
+++ b/app/views/projects/mirrors/_authentication_method.html.haml
@@ -13,4 +13,4 @@
.form-group
.well-password-auth.collapse.js-well-password-auth
= f.label :password, _("Password"), class: "label-bold"
- = f.password_field :password, class: 'form-control gl-form-input qa-password', autocomplete: 'new-password'
+ = f.password_field :password, class: 'form-control gl-form-input qa-password js-mirror-password-field', autocomplete: 'off'
diff --git a/lib/banzai/filter/math_filter.rb b/lib/banzai/filter/math_filter.rb
index 6859d67c9d8..0ac506776be 100644
--- a/lib/banzai/filter/math_filter.rb
+++ b/lib/banzai/filter/math_filter.rb
@@ -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
@@ -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
diff --git a/spec/lib/banzai/filter/math_filter_spec.rb b/spec/lib/banzai/filter/math_filter_spec.rb
index 6d22fa3a001..128f8532d39 100644
--- a/spec/lib/banzai/filter/math_filter_spec.rb
+++ b/spec/lib/banzai/filter/math_filter_spec.rb
@@ -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
diff --git a/spec/services/members/create_service_spec.rb b/spec/services/members/create_service_spec.rb
index 4d9e69719b4..4396a0d3ec3 100644
--- a/spec/services/members/create_service_spec.rb
+++ b/spec/services/members/create_service_spec.rb
@@ -11,19 +11,37 @@ RSpec.describe Members::CreateService, :aggregate_failures, :clean_gitlab_redis_
let(:additional_params) { { invite_source: '_invite_source_' } }
let(:params) { { user_ids: user_ids, access_level: access_level }.merge(additional_params) }
+ let(:current_user) { user }
- subject(:execute_service) { described_class.new(user, params.merge({ source: source })).execute }
+ subject(:execute_service) { described_class.new(current_user, params.merge({ source: source })).execute }
before do
- if source.is_a?(Project)
+ case source
+ when Project
source.add_maintainer(user)
OnboardingProgress.onboard(source.namespace)
- else
+ when Group
source.add_owner(user)
OnboardingProgress.onboard(source)
end
end
+ context 'when the current user does not have permission to create members' do
+ let(:current_user) { create(:user) }
+
+ it 'raises a Gitlab::Access::AccessDeniedError' do
+ expect { execute_service }.to raise_error(Gitlab::Access::AccessDeniedError)
+ end
+ end
+
+ context 'when passing an invalid source' do
+ let_it_be(:source) { Object.new }
+
+ it 'raises a RuntimeError' do
+ expect { execute_service }.to raise_error(RuntimeError, 'Unknown source type: Object!')
+ end
+ end
+
context 'when passing valid parameters' do
it 'adds a user to members' do
expect(execute_service[:status]).to eq(:success)