BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
2ccee2bc
Commit
2ccee2bc
authored
Jul 20, 2017
by
Sean McGivern
Committed by
James Edwards-Jones
Jul 20, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge branch 'fix-re2-infinite-loop-nick' into 'security-9-3'
Fix an infinite loop in Gitlab:UntrustedRegexp See merge request !2146
parent
5fc5c818
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
8 deletions
+45
-8
fix-re2-infinite-loop-nick.yml
changelogs/unreleased/fix-re2-infinite-loop-nick.yml
+4
-0
untrusted_regexp.rb
lib/gitlab/untrusted_regexp.rb
+22
-7
untrusted_regexp_spec.rb
spec/lib/gitlab/untrusted_regexp_spec.rb
+19
-1
No files found.
changelogs/unreleased/fix-re2-infinite-loop-nick.yml
0 → 100644
View file @
2ccee2bc
---
title
:
Fix an infinite loop when handling user-supplied regular expressions
merge_request
:
author
:
lib/gitlab/untrusted_regexp.rb
View file @
2ccee2bc
...
...
@@ -22,13 +22,28 @@ module Gitlab
end
def
scan
(
text
)
scan_regexp
.
scan
(
text
).
map
do
|
match
|
if
regexp
.
number_of_capturing_groups
==
0
match
.
first
else
match
end
text
=
text
.
dup
# modified in-place
results
=
[]
loop
do
match
=
scan_regexp
.
match
(
text
)
break
unless
match
# Ruby scan returns empty strings, not nil
groups
=
match
.
to_a
.
map
(
&
:to_s
)
results
<<
if
regexp
.
number_of_capturing_groups
.
zero?
groups
[
0
]
else
groups
[
1
..-
1
]
end
text
.
slice!
(
0
,
match
.
end
(
0
)
||
1
)
break
unless
text
.
present?
end
results
end
def
replace
(
text
,
rewrite
)
...
...
@@ -43,7 +58,7 @@ module Gitlab
# groups, so work around it
def
scan_regexp
@scan_regexp
||=
if
regexp
.
number_of_capturing_groups
==
0
if
regexp
.
number_of_capturing_groups
.
zero?
RE2
::
Regexp
.
new
(
'('
+
regexp
.
source
+
')'
)
else
regexp
...
...
spec/lib/gitlab/untrusted_regexp_spec.rb
View file @
2ccee2bc
...
...
@@ -46,10 +46,28 @@ describe Gitlab::UntrustedRegexp do
context
'malicious regexp'
do
let
(
:text
)
{
malicious_text
}
let
(
:regexp
)
{
malicious_regexp
}
include_examples
'malicious regexp'
end
context
'empty regexp'
do
let
(
:regexp
)
{
''
}
let
(
:text
)
{
'foo'
}
it
'returns an array of empty matches'
do
is_expected
.
to
eq
([
''
,
''
,
''
])
end
end
context
'empty capture group regexp'
do
let
(
:regexp
)
{
'()'
}
let
(
:text
)
{
'foo'
}
it
'returns arrays of empty matches in an array'
do
is_expected
.
to
eq
([[
''
],
[
''
],
[
''
]])
end
end
context
'no capture group'
do
let
(
:regexp
)
{
'.+'
}
let
(
:text
)
{
'foo'
}
...
...
Write
Preview
Markdown
is supported
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