summaryrefslogtreecommitdiff
path: root/lib/gitlab/template
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2018-12-04 15:59:01 +0000
committerNick Thomas <nick@gitlab.com>2018-12-05 14:12:35 +0000
commit69645389e925a106f00fed555fde54c38f26816a (patch)
treebaf7b8dd019934e8bf9d113566b4497d64c61437 /lib/gitlab/template
parent87186cbc922465875e299ed761ed4d6143ae501a (diff)
downloadgitlab-ce-69645389e925a106f00fed555fde54c38f26816a.tar.gz
Prevent a path traversal attack on global file templates
The API permits path traversal characters like '../' to be passed down to the template finder. Detect these requests and cause them to fail with a 500 response code.
Diffstat (limited to 'lib/gitlab/template')
-rw-r--r--lib/gitlab/template/finders/global_template_finder.rb4
-rw-r--r--lib/gitlab/template/finders/repo_template_finder.rb5
2 files changed, 9 insertions, 0 deletions
diff --git a/lib/gitlab/template/finders/global_template_finder.rb b/lib/gitlab/template/finders/global_template_finder.rb
index 76bb9eb611e..2dd4b7a4092 100644
--- a/lib/gitlab/template/finders/global_template_finder.rb
+++ b/lib/gitlab/template/finders/global_template_finder.rb
@@ -18,6 +18,10 @@ module Gitlab
def find(key)
file_name = "#{key}#{@extension}"
+ # The key is untrusted input, so ensure we can't be directed outside
+ # of base_dir
+ Gitlab::Utils.check_path_traversal!(file_name)
+
directory = select_directory(file_name)
directory ? File.join(category_directory(directory), file_name) : nil
end
diff --git a/lib/gitlab/template/finders/repo_template_finder.rb b/lib/gitlab/template/finders/repo_template_finder.rb
index b92cefefb8f..8e234148a63 100644
--- a/lib/gitlab/template/finders/repo_template_finder.rb
+++ b/lib/gitlab/template/finders/repo_template_finder.rb
@@ -26,6 +26,11 @@ module Gitlab
def find(key)
file_name = "#{key}#{@extension}"
+
+ # The key is untrusted input, so ensure we can't be directed outside
+ # of base_dir inside the repository
+ Gitlab::Utils.check_path_traversal!(file_name)
+
directory = select_directory(file_name)
raise FileNotFoundError if directory.nil?