summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2018-02-14 15:53:59 +0000
committerKamil Trzciński <ayufan@ayufan.eu>2018-02-14 15:53:59 +0000
commit5d1088c2a899f709cc9bdf30af0bdbfea81be09e (patch)
tree34b03a54d96f8e0aeb7a5b4b06e3412d17661209
parent1d2a8cb75643160a0b565e41c80dd9b3b08a592d (diff)
parentba78465a264c64a742f83d797d63c38ef9ed083d (diff)
downloadgitlab-ce-5d1088c2a899f709cc9bdf30af0bdbfea81be09e.tar.gz
Merge branch '39885-ensure-users-cannot-create-environments-with-leading-slashes' into 'master'
Resolve "Environment with starting slash in name causes error" Closes #39885 See merge request gitlab-org/gitlab-ce!17071
-rw-r--r--changelogs/unreleased/issue-39885.yml5
-rw-r--r--lib/gitlab/regex.rb8
-rw-r--r--spec/lib/gitlab/regex_spec.rb5
3 files changed, 16 insertions, 2 deletions
diff --git a/changelogs/unreleased/issue-39885.yml b/changelogs/unreleased/issue-39885.yml
new file mode 100644
index 00000000000..75bf9434152
--- /dev/null
+++ b/changelogs/unreleased/issue-39885.yml
@@ -0,0 +1,5 @@
+---
+title: 'Ensure users cannot create environments with leading or trailing slashes (Fixes #39885)'
+merge_request: 15273
+author:
+type: fixed
diff --git a/lib/gitlab/regex.rb b/lib/gitlab/regex.rb
index 7ab85e1c35c..ac3de2a8f71 100644
--- a/lib/gitlab/regex.rb
+++ b/lib/gitlab/regex.rb
@@ -40,12 +40,16 @@ module Gitlab
'a-zA-Z0-9_/\\$\\{\\}\\. \\-'
end
+ def environment_name_regex_chars_without_slash
+ 'a-zA-Z0-9_\\$\\{\\}\\. -'
+ end
+
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
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
def kubernetes_namespace_regex
diff --git a/spec/lib/gitlab/regex_spec.rb b/spec/lib/gitlab/regex_spec.rb
index 8b54d72d6f7..a1079e54975 100644
--- a/spec/lib/gitlab/regex_spec.rb
+++ b/spec/lib/gitlab/regex_spec.rb
@@ -18,6 +18,7 @@ describe Gitlab::Regex do
subject { described_class.environment_name_regex }
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') }
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('foo-^') }
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
describe '.environment_slug_regex' do