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
75434bcb
Commit
75434bcb
authored
Jun 15, 2020
by
Kirstie Cook
Committed by
Peter Leitzen
Jun 15, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Block invalid urls in metrics dashboard links
parent
eca17ef7
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
2 deletions
+49
-2
app/services/metrics/dashboard/base_service.rb
app/services/metrics/dashboard/base_service.rb
+2
-1
changelogs/unreleased/219074-safe-link-validation.yml
changelogs/unreleased/219074-safe-link-validation.yml
+5
-0
lib/gitlab/metrics/dashboard/stages/url_validator.rb
lib/gitlab/metrics/dashboard/stages/url_validator.rb
+19
-0
spec/lib/gitlab/metrics/dashboard/processor_spec.rb
spec/lib/gitlab/metrics/dashboard/processor_spec.rb
+23
-1
No files found.
app/services/metrics/dashboard/base_service.rb
View file @
75434bcb
...
...
@@ -13,7 +13,8 @@ module Metrics
STAGES
::
EndpointInserter
,
STAGES
::
PanelIdsInserter
,
STAGES
::
Sorter
,
STAGES
::
AlertsInserter
STAGES
::
AlertsInserter
,
STAGES
::
UrlValidator
].
freeze
def
get_dashboard
...
...
changelogs/unreleased/219074-safe-link-validation.yml
0 → 100644
View file @
75434bcb
---
title
:
Add validation step on backend for metrics dashboard links
merge_request
:
34204
author
:
type
:
added
lib/gitlab/metrics/dashboard/stages/url_validator.rb
0 → 100644
View file @
75434bcb
# frozen_string_literal: true
module
Gitlab
module
Metrics
module
Dashboard
module
Stages
class
UrlValidator
<
BaseStage
def
transform!
dashboard
[
:links
]
&
.
each
do
|
link
|
Gitlab
::
UrlBlocker
.
validate!
(
link
[
:url
])
rescue
Gitlab
::
UrlBlocker
::
BlockedUrlError
link
[
:url
]
=
''
end
end
end
end
end
end
end
spec/lib/gitlab/metrics/dashboard/processor_spec.rb
View file @
75434bcb
...
...
@@ -16,7 +16,8 @@ describe Gitlab::Metrics::Dashboard::Processor do
Gitlab
::
Metrics
::
Dashboard
::
Stages
::
EndpointInserter
,
Gitlab
::
Metrics
::
Dashboard
::
Stages
::
Sorter
,
Gitlab
::
Metrics
::
Dashboard
::
Stages
::
AlertsInserter
,
Gitlab
::
Metrics
::
Dashboard
::
Stages
::
PanelIdsInserter
Gitlab
::
Metrics
::
Dashboard
::
Stages
::
PanelIdsInserter
,
Gitlab
::
Metrics
::
Dashboard
::
Stages
::
UrlValidator
]
end
...
...
@@ -201,6 +202,27 @@ describe Gitlab::Metrics::Dashboard::Processor do
it_behaves_like
'errors with message'
,
'Each "metric" must define one of :query or :query_range'
end
describe
'validating links'
do
context
'when the links contain a blocked url'
do
let
(
:dashboard_yml_links
)
do
[{
'url'
=>
'http://1.1.1.1.1'
},
{
'url'
=>
'https://gitlab.com'
}]
end
let
(
:expected
)
do
[{
url:
''
},
{
url:
'https://gitlab.com'
}]
end
before
do
stub_env
(
'RSPEC_ALLOW_INVALID_URLS'
,
'false'
)
dashboard_yml
[
'links'
]
=
dashboard_yml_links
end
it
'replaces the blocked url with an empty string'
do
expect
(
dashboard
[
:links
]).
to
eq
(
expected
)
end
end
end
end
private
...
...
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