Skip to content
Snippets Groups Projects
Commit 0b7db931 authored by Yorick Peterse's avatar Yorick Peterse
Browse files

Merge branch 'security-fix-regex-dos-11-5' into 'security-11-5'

[11.5] Fix DoS in reference extraction regexes

See merge request gitlab/gitlabhq!2779

(cherry picked from commit 9f3dc81480d4b72a201e3517335c4f18235a1f7d)

0a37ec23 Fix slow project reference pattern regex
parent 7f0ce1ea
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -492,6 +492,7 @@ class Project < ActiveRecord::Base
 
def reference_pattern
%r{
(?<!#{Gitlab::PathRegex::PATH_START_CHAR})
((?<namespace>#{Gitlab::PathRegex::FULL_NAMESPACE_FORMAT_REGEX})\/)?
(?<project>#{Gitlab::PathRegex::PROJECT_PATH_FORMAT_REGEX})
}x
Loading
Loading
---
title: Fix slow regex in project reference pattern
merge_request:
author:
type: security
Loading
Loading
@@ -125,7 +125,8 @@ module Gitlab
# allow non-regex validations, etc), `NAMESPACE_FORMAT_REGEX_JS` serves as a Javascript-compatible version of
# `NAMESPACE_FORMAT_REGEX`, with the negative lookbehind assertion removed. This means that the client-side validation
# will pass for usernames ending in `.atom` and `.git`, but will be caught by the server-side validation.
PATH_REGEX_STR = '[a-zA-Z0-9_\.][a-zA-Z0-9_\-\.]*'.freeze
PATH_START_CHAR = '[a-zA-Z0-9_\.]'.freeze
PATH_REGEX_STR = PATH_START_CHAR + '[a-zA-Z0-9_\-\.]*'.freeze
NAMESPACE_FORMAT_REGEX_JS = PATH_REGEX_STR + '[a-zA-Z0-9_\-]|[a-zA-Z0-9_]'.freeze
 
NO_SUFFIX_REGEX = /(?<!\.git|\.atom)/.freeze
Loading
Loading
Loading
Loading
@@ -26,6 +26,12 @@ describe Banzai::Filter::ProjectReferenceFilter do
expect(reference_filter(act).to_html).to eq(CGI.escapeHTML(exp))
end
 
it 'fails fast for long invalid string' do
expect do
Timeout.timeout(5.seconds) { reference_filter("A" * 50000).to_html }
end.not_to raise_error
end
it 'allows references with text after the > character' do
doc = reference_filter("Hey #{reference}foo")
expect(doc.css('a').first.attr('href')).to eq urls.project_url(subject)
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment