Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
b9d6bb0e50d7
Commit
b9d6bb0e
authored
Jan 09, 2019
by
Heinrich Lee Yu
Browse files
Fix slow project reference pattern regex
parent
a1e28b5881c3
Changes
4
Hide whitespace changes
Inline
Side-by-side
app/models/project.rb
View file @
b9d6bb0e
...
...
@@ -530,6 +530,7 @@
def
reference_pattern
%r{
(?<!
#{
Gitlab
::
PathRegex
::
PATH_START_CHAR
}
)
((?<namespace>
#{
Gitlab
::
PathRegex
::
FULL_NAMESPACE_FORMAT_REGEX
}
)
\/
)?
(?<project>
#{
Gitlab
::
PathRegex
::
PROJECT_PATH_FORMAT_REGEX
}
)
}x
...
...
changelogs/unreleased/security-fix-regex-dos.yml
0 → 100644
View file @
b9d6bb0e
---
title
:
Fix slow regex in project reference pattern
merge_request
:
author
:
type
:
security
lib/gitlab/path_regex.rb
View file @
b9d6bb0e
...
...
@@ -125,7 +125,8 @@
# 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
...
...
spec/lib/banzai/filter/project_reference_filter_spec.rb
View file @
b9d6bb0e
...
...
@@ -26,6 +26,12 @@
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
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment