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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
5a0a9dab
Commit
5a0a9dab
authored
Nov 13, 2018
by
rpereira2
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
No redirects in prometheus service
Do not allow redirects in the prometheus service to prevent SSRFs.
parent
12397018
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
3 deletions
+20
-3
app/models/project_services/prometheus_service.rb
app/models/project_services/prometheus_service.rb
+1
-1
spec/models/project_services/prometheus_service_spec.rb
spec/models/project_services/prometheus_service_spec.rb
+17
-0
spec/support/helpers/prometheus_helpers.rb
spec/support/helpers/prometheus_helpers.rb
+2
-2
No files found.
app/models/project_services/prometheus_service.rb
View file @
5a0a9dab
...
...
@@ -71,7 +71,7 @@ class PrometheusService < MonitoringService
end
def
prometheus_client
RestClient
::
Resource
.
new
(
api_url
)
if
api_url
&&
manual_configuration?
&&
active?
RestClient
::
Resource
.
new
(
api_url
,
max_redirects:
0
)
if
api_url
&&
manual_configuration?
&&
active?
end
def
prometheus_available?
...
...
spec/models/project_services/prometheus_service_spec.rb
View file @
5a0a9dab
...
...
@@ -13,6 +13,23 @@ describe PrometheusService, :use_clean_rails_memory_store_caching do
it
{
is_expected
.
to
belong_to
:project
}
end
context
'redirects'
do
it
'does not follow redirects'
do
redirect_to
=
'https://redirected.example.com'
redirect_req_stub
=
stub_prometheus_request
(
prometheus_query_url
(
'1'
),
status:
302
,
headers:
{
location:
redirect_to
})
redirected_req_stub
=
stub_prometheus_request
(
redirect_to
,
body:
{
'status'
:
'success'
})
result
=
service
.
test
# result = { success: false, result: error }
expect
(
result
[
:success
]).
to
be_falsy
expect
(
result
[
:result
]).
to
be_instance_of
(
Gitlab
::
PrometheusClient
::
Error
)
expect
(
redirect_req_stub
).
to
have_been_requested
expect
(
redirected_req_stub
).
not_to
have_been_requested
end
end
describe
'Validations'
do
context
'when manual_configuration is enabled'
do
before
do
...
...
spec/support/helpers/prometheus_helpers.rb
View file @
5a0a9dab
...
...
@@ -49,11 +49,11 @@ module PrometheusHelpers
"https://prometheus.example.com/api/v1/series?
#{
query
}
"
end
def
stub_prometheus_request
(
url
,
body:
{},
status:
200
)
def
stub_prometheus_request
(
url
,
body:
{},
status:
200
,
headers:
{}
)
WebMock
.
stub_request
(
:get
,
url
)
.
to_return
({
status:
status
,
headers:
{
'Content-Type'
=>
'application/json'
},
headers:
{
'Content-Type'
=>
'application/json'
}
.
merge
(
headers
)
,
body:
body
.
to_json
})
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