summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Release Tools Bot <robert+release-tools@gitlab.com>2019-11-26 17:03:30 +0000
committerGitLab Release Tools Bot <robert+release-tools@gitlab.com>2019-11-26 17:03:30 +0000
commit1fdceefabdb551523502dd79dc0e0eb67e96e520 (patch)
tree63ea64343cf52e9f79dcbf6e602373b6abf14873
parent17f98469c5c9fe5dcd38e4a2fc42587793abe739 (diff)
parent0159e0041cc7f0b0543e10e9cfc0cd97d669c361 (diff)
downloadgitlab-ce-1fdceefabdb551523502dd79dc0e0eb67e96e520.tar.gz
Merge branch 'security-dos-issue-and-commit-comments-12-3' into '12-3-stable'
Fix invalid byte sequence See merge request gitlab/gitlabhq!3549
-rw-r--r--changelogs/unreleased/security-dos-issue-and-commit-comments-master.yml5
-rw-r--r--lib/banzai/filter/relative_link_filter.rb2
-rw-r--r--spec/lib/banzai/filter/relative_link_filter_spec.rb5
3 files changed, 11 insertions, 1 deletions
diff --git a/changelogs/unreleased/security-dos-issue-and-commit-comments-master.yml b/changelogs/unreleased/security-dos-issue-and-commit-comments-master.yml
new file mode 100644
index 00000000000..c84cebdcca0
--- /dev/null
+++ b/changelogs/unreleased/security-dos-issue-and-commit-comments-master.yml
@@ -0,0 +1,5 @@
+---
+title: Fix 500 error caused by invalid byte sequences in links
+merge_request:
+author:
+type: security
diff --git a/lib/banzai/filter/relative_link_filter.rb b/lib/banzai/filter/relative_link_filter.rb
index e8001889ca3..f7311d52636 100644
--- a/lib/banzai/filter/relative_link_filter.rb
+++ b/lib/banzai/filter/relative_link_filter.rb
@@ -103,7 +103,7 @@ module Banzai
end
def relative_file_path(uri)
- path = Addressable::URI.unescape(uri.path).delete("\0")
+ path = Addressable::URI.unescape(uri.path).scrub.delete("\0")
request_path = Addressable::URI.unescape(context[:requested_path])
nested_path = build_relative_path(path, request_path)
file_exists?(nested_path) ? nested_path : path
diff --git a/spec/lib/banzai/filter/relative_link_filter_spec.rb b/spec/lib/banzai/filter/relative_link_filter_spec.rb
index f8b3748c663..d842e4f13a2 100644
--- a/spec/lib/banzai/filter/relative_link_filter_spec.rb
+++ b/spec/lib/banzai/filter/relative_link_filter_spec.rb
@@ -87,6 +87,11 @@ describe Banzai::Filter::RelativeLinkFilter do
expect { filter(act) }.not_to raise_error
end
+ it 'does not raise an exception on URIs containing invalid utf-8 byte sequences' do
+ act = link("%FF")
+ expect { filter(act) }.not_to raise_error
+ end
+
it 'does not raise an exception with a garbled path' do
act = link("open(/var/tmp/):%20/location%0Afrom:%20/test")
expect { filter(act) }.not_to raise_error