Ensure users can't create environments with leading or trailing slashes (Fixes #39885)
This commit is contained in:
parent
498ade4801
commit
06c111ca8f
3 changed files with 16 additions and 2 deletions
5
changelogs/unreleased/issue-39885.yml
Normal file
5
changelogs/unreleased/issue-39885.yml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: 'Ensure users cannot create environments with leading or trailing slashes (Fixes #39885)'
|
||||||
|
merge_request: !15273
|
||||||
|
author: Dylan Griffith
|
||||||
|
type: fixed
|
|
@ -40,12 +40,16 @@ module Gitlab
|
||||||
'a-zA-Z0-9_/\\$\\{\\}\\. \\-'
|
'a-zA-Z0-9_/\\$\\{\\}\\. \\-'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def environment_name_regex_chars_without_slash
|
||||||
|
'a-zA-Z0-9_\\$\\{\\}\\. -'
|
||||||
|
end
|
||||||
|
|
||||||
def environment_name_regex
|
def environment_name_regex
|
||||||
@environment_name_regex ||= /\A[#{environment_name_regex_chars}]+\z/.freeze
|
@environment_name_regex ||= /\A[#{environment_name_regex_chars_without_slash}]([#{environment_name_regex_chars}]*[#{environment_name_regex_chars_without_slash}])?\z/.freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
def environment_name_regex_message
|
def environment_name_regex_message
|
||||||
"can contain only letters, digits, '-', '_', '/', '$', '{', '}', '.', and spaces"
|
"can contain only letters, digits, '-', '_', '/', '$', '{', '}', '.', and spaces, but it cannot start or end with '/'"
|
||||||
end
|
end
|
||||||
|
|
||||||
def kubernetes_namespace_regex
|
def kubernetes_namespace_regex
|
||||||
|
|
|
@ -18,6 +18,7 @@ describe Gitlab::Regex do
|
||||||
subject { described_class.environment_name_regex }
|
subject { described_class.environment_name_regex }
|
||||||
|
|
||||||
it { is_expected.to match('foo') }
|
it { is_expected.to match('foo') }
|
||||||
|
it { is_expected.to match('a') }
|
||||||
it { is_expected.to match('foo-1') }
|
it { is_expected.to match('foo-1') }
|
||||||
it { is_expected.to match('FOO') }
|
it { is_expected.to match('FOO') }
|
||||||
it { is_expected.to match('foo/1') }
|
it { is_expected.to match('foo/1') }
|
||||||
|
@ -25,6 +26,10 @@ describe Gitlab::Regex do
|
||||||
it { is_expected.not_to match('9&foo') }
|
it { is_expected.not_to match('9&foo') }
|
||||||
it { is_expected.not_to match('foo-^') }
|
it { is_expected.not_to match('foo-^') }
|
||||||
it { is_expected.not_to match('!!()()') }
|
it { is_expected.not_to match('!!()()') }
|
||||||
|
it { is_expected.not_to match('/foo') }
|
||||||
|
it { is_expected.not_to match('foo/') }
|
||||||
|
it { is_expected.not_to match('/foo/') }
|
||||||
|
it { is_expected.not_to match('/') }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '.environment_slug_regex' do
|
describe '.environment_slug_regex' do
|
||||||
|
|
Loading…
Reference in a new issue