Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
358783ba
Commit
358783ba
authored
Jun 12, 2019
by
Heinrich Lee Yu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix color validation regex
Also prevents ReDoS vulnerability
parent
acfa84f0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
1 deletion
+49
-1
app/validators/color_validator.rb
app/validators/color_validator.rb
+1
-1
changelogs/unreleased/security-2858-fix-color-validation.yml
changelogs/unreleased/security-2858-fix-color-validation.yml
+5
-0
spec/validators/color_validator_spec.rb
spec/validators/color_validator_spec.rb
+43
-0
No files found.
app/validators/color_validator.rb
View file @
358783ba
...
...
@@ -12,7 +12,7 @@
# end
#
class
ColorValidator
<
ActiveModel
::
EachValidator
PATTERN
=
/\A\#
[0-9A-Fa-f]{3}{1,2}+
\Z/
.
freeze
PATTERN
=
/\A\#
(?:[0-9A-Fa-f]{3}){1,2}
\Z/
.
freeze
def
validate_each
(
record
,
attribute
,
value
)
unless
value
=~
PATTERN
...
...
changelogs/unreleased/security-2858-fix-color-validation.yml
0 → 100644
View file @
358783ba
---
title
:
Fix DoS vulnerability in color validation regex
merge_request
:
author
:
type
:
security
spec/validators/color_validator_spec.rb
0 → 100644
View file @
358783ba
# frozen_string_literal: true
require
'spec_helper'
describe
ColorValidator
do
using
RSpec
::
Parameterized
::
TableSyntax
subject
do
Class
.
new
do
include
ActiveModel
::
Model
include
ActiveModel
::
Validations
attr_accessor
:color
validates
:color
,
color:
true
end
.
new
end
where
(
:color
,
:is_valid
)
do
'#000abc'
|
true
'#aaa'
|
true
'#BBB'
|
true
'#cCc'
|
true
'#ffff'
|
false
'#000111222'
|
false
'invalid'
|
false
'000'
|
false
end
with_them
do
it
'only accepts valid colors'
do
subject
.
color
=
color
expect
(
subject
.
valid?
).
to
eq
(
is_valid
)
end
end
it
'fails fast for long invalid string'
do
subject
.
color
=
'#'
+
(
'0'
*
50_000
)
+
'xxx'
expect
do
Timeout
.
timeout
(
5
.
seconds
)
{
subject
.
valid?
}
end
.
not_to
raise_error
end
end
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