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
492e543a
Commit
492e543a
authored
Jan 20, 2022
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clarify regexp syntax allowed for use in CI config
parent
dd3c2f30
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
7 deletions
+28
-7
lib/gitlab/config/entry/validators.rb
lib/gitlab/config/entry/validators.rb
+19
-2
lib/gitlab/untrusted_regexp/ruby_syntax.rb
lib/gitlab/untrusted_regexp/ruby_syntax.rb
+1
-1
spec/lib/gitlab/ci/yaml_processor_spec.rb
spec/lib/gitlab/ci/yaml_processor_spec.rb
+8
-4
No files found.
lib/gitlab/config/entry/validators.rb
View file @
492e543a
...
...
@@ -213,7 +213,7 @@ module Gitlab
def
validate_each
(
record
,
attribute
,
value
)
unless
validate_regexp
(
value
)
record
.
errors
.
add
(
attribute
,
'must be a regular expression'
)
record
.
errors
.
add
(
attribute
,
'must be a regular expression
with re2 syntax
'
)
end
end
...
...
@@ -238,12 +238,16 @@ module Gitlab
class
ArrayOfStringsOrRegexpsValidator
<
RegexpValidator
def
validate_each
(
record
,
attribute
,
value
)
unless
validate_array_of_strings_or_regexps
(
value
)
record
.
errors
.
add
(
attribute
,
'should be an array of strings or regexps'
)
record
.
errors
.
add
(
attribute
,
validation_message
)
end
end
private
def
validation_message
'should be an array of strings or regexps using re2 syntax'
end
def
validate_array_of_strings_or_regexps
(
values
)
values
.
is_a?
(
Array
)
&&
values
.
all?
(
&
method
(
:validate_string_or_regexp
))
end
...
...
@@ -259,6 +263,19 @@ module Gitlab
class
ArrayOfStringsOrRegexpsWithFallbackValidator
<
ArrayOfStringsOrRegexpsValidator
protected
# TODO
#
# Remove ArrayOfStringsOrRegexpsWithFallbackValidator class too when
# you are removing the `:allow_unsafe_ruby_regexp` feature flag.
#
def
validation_message
if
::
Feature
.
enabled?
(
:allow_unsafe_ruby_regexp
,
default_enabled: :yaml
)
'should be an array of strings or regexps'
else
super
end
end
def
fallback
true
end
...
...
lib/gitlab/untrusted_regexp/ruby_syntax.rb
View file @
492e543a
...
...
@@ -36,7 +36,7 @@ module Gitlab
create_untrusted_regexp
(
matches
[
:regexp
],
matches
[
:flags
])
rescue
RegexpError
raise
unless
fallback
&&
Feature
.
enabled?
(
:allow_unsafe_ruby_regexp
,
default_enabled:
false
)
Feature
.
enabled?
(
:allow_unsafe_ruby_regexp
,
default_enabled:
:yaml
)
if
Feature
.
enabled?
(
:ci_unsafe_regexp_logger
,
type: :ops
,
default_enabled: :yaml
)
Gitlab
::
AppJsonLogger
.
info
(
...
...
spec/lib/gitlab/ci/yaml_processor_spec.rb
View file @
492e543a
...
...
@@ -9,6 +9,10 @@ module Gitlab
subject
{
described_class
.
new
(
config
,
user:
nil
).
execute
}
before
do
stub_feature_flags
(
allow_unsafe_ruby_regexp:
false
)
end
shared_examples
'returns errors'
do
|
error_message
|
it
'adds a message when an error is encountered'
do
expect
(
subject
.
errors
).
to
include
(
error_message
)
...
...
@@ -609,13 +613,13 @@ module Gitlab
context
'when it is an array of integers'
do
let
(
:only
)
{
[
1
,
1
]
}
it_behaves_like
'returns errors'
,
'jobs:rspec:only config should be an array of strings or regexps'
it_behaves_like
'returns errors'
,
'jobs:rspec:only config should be an array of strings or regexps
using re2 syntax
'
end
context
'when it is invalid regex'
do
let
(
:only
)
{
[
"/*invalid/"
]
}
it_behaves_like
'returns errors'
,
'jobs:rspec:only config should be an array of strings or regexps'
it_behaves_like
'returns errors'
,
'jobs:rspec:only config should be an array of strings or regexps
using re2 syntax
'
end
end
...
...
@@ -633,13 +637,13 @@ module Gitlab
context
'when it is an array of integers'
do
let
(
:except
)
{
[
1
,
1
]
}
it_behaves_like
'returns errors'
,
'jobs:rspec:except config should be an array of strings or regexps'
it_behaves_like
'returns errors'
,
'jobs:rspec:except config should be an array of strings or regexps
using re2 syntax
'
end
context
'when it is invalid regex'
do
let
(
:except
)
{
[
"/*invalid/"
]
}
it_behaves_like
'returns errors'
,
'jobs:rspec:except config should be an array of strings or regexps'
it_behaves_like
'returns errors'
,
'jobs:rspec:except config should be an array of strings or regexps
using re2 syntax
'
end
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