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
261cd8b9
Commit
261cd8b9
authored
Mar 03, 2021
by
Alex Kalderimis
Committed by
James Lopez
Mar 03, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow the GraphQL controller to whitelist some expensive queries
parent
83af89ed
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
60 deletions
+91
-60
app/controllers/graphql_controller.rb
app/controllers/graphql_controller.rb
+13
-1
spec/requests/api/graphql/project/merge_requests_spec.rb
spec/requests/api/graphql/project/merge_requests_spec.rb
+78
-59
No files found.
app/controllers/graphql_controller.rb
View file @
261cd8b9
...
...
@@ -4,6 +4,8 @@ class GraphqlController < ApplicationController
# Unauthenticated users have access to the API for public data
skip_before_action
:authenticate_user!
WHITELIST_HEADER
=
'HTTP_X_GITLAB_QUERY_WHITELIST_ISSUE'
# If a user is using their session to access GraphQL, we need to have session
# storage, since the admin-mode check is session wide.
# We can't enable this for anonymous users because that would cause users using
...
...
@@ -21,6 +23,7 @@ class GraphqlController < ApplicationController
before_action
(
only:
[
:execute
])
{
authenticate_sessionless_user!
(
:api
)
}
before_action
:set_user_last_activity
before_action
:track_vs_code_usage
before_action
:whitelist_query!
# Since we deactivate authentication from the main ApplicationController and
# defer it to :authorize_access_api!, we need to override the bypass session
...
...
@@ -59,6 +62,14 @@ class GraphqlController < ApplicationController
private
# Tests may mark some queries as exempt from query limits
def
whitelist_query!
whitelist_issue
=
request
.
headers
[
WHITELIST_HEADER
]
return
unless
whitelist_issue
Gitlab
::
QueryLimiting
.
whitelist
(
whitelist_issue
)
end
def
set_user_last_activity
return
unless
current_user
...
...
@@ -66,7 +77,8 @@ class GraphqlController < ApplicationController
end
def
track_vs_code_usage
Gitlab
::
UsageDataCounters
::
VSCodeExtensionActivityUniqueCounter
.
track_api_request_when_trackable
(
user_agent:
request
.
user_agent
,
user:
current_user
)
Gitlab
::
UsageDataCounters
::
VSCodeExtensionActivityUniqueCounter
.
track_api_request_when_trackable
(
user_agent:
request
.
user_agent
,
user:
current_user
)
end
def
execute_multiplex
...
...
spec/requests/api/graphql/project/merge_requests_spec.rb
View file @
261cd8b9
This diff is collapsed.
Click to expand it.
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