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
3e8b902d
Commit
3e8b902d
authored
Sep 10, 2020
by
alinamihaila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add CSRF check in UsageData API
parent
88f43c7d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
2 deletions
+16
-2
doc/development/telemetry/usage_ping.md
doc/development/telemetry/usage_ping.md
+3
-2
lib/api/usage_data.rb
lib/api/usage_data.rb
+1
-0
spec/requests/api/usage_data_spec.rb
spec/requests/api/usage_data_spec.rb
+12
-0
No files found.
doc/development/telemetry/usage_ping.md
View file @
3e8b902d
...
...
@@ -330,9 +330,10 @@ Implemented using Redis methods [PFADD](https://redis.io/commands/pfadd) and [PF
Return 200 if tracking failed for any reason.
-
`401 Unauthorized`
if user is not authenticated
-
`400 Bad request`
if event parameter is missing
-
`200`
if event was tracked or any errors
-
`400 Bad request`
if event parameter is missing
-
`401 Unauthorized`
if user is not authenticated
-
`403 Forbidden`
for invalid CSRF token provided
1.
Track event using base module
`Gitlab::UsageDataCounters::HLLRedisCounter.track_event(entity_id, event_name)`
.
...
...
lib/api/usage_data.rb
View file @
3e8b902d
...
...
@@ -7,6 +7,7 @@ module API
namespace
'usage_data'
do
before
do
not_found!
unless
Feature
.
enabled?
(
:usage_data_api
)
forbidden!
(
'Invalid CSRF token is provided'
)
unless
verified_request?
end
desc
'Track usage data events'
do
...
...
spec/requests/api/usage_data_spec.rb
View file @
3e8b902d
...
...
@@ -10,6 +10,17 @@ RSpec.describe API::UsageData do
let
(
:known_event
)
{
'g_compliance_dashboard'
}
let
(
:unknown_event
)
{
'unknown'
}
context
'without CSRF token'
do
it
'returns forbidden'
do
stub_feature_flags
(
usage_data_api:
true
)
allow
(
Gitlab
::
RequestForgeryProtection
).
to
receive
(
:verified?
).
and_return
(
false
)
post
api
(
endpoint
,
user
),
params:
{
event:
known_event
}
expect
(
response
).
to
have_gitlab_http_status
(
:forbidden
)
end
end
context
'usage_data_api feature not enabled'
do
it
'returns not_found'
do
stub_feature_flags
(
usage_data_api:
false
)
...
...
@@ -33,6 +44,7 @@ RSpec.describe API::UsageData do
stub_feature_flags
(
usage_data_api:
true
)
stub_feature_flags
(
"usage_data_
#{
known_event
}
"
=>
true
)
stub_application_setting
(
usage_ping_enabled:
true
)
allow
(
Gitlab
::
RequestForgeryProtection
).
to
receive
(
:verified?
).
and_return
(
true
)
end
context
'when event is missing from params'
do
...
...
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