secu(graphql): without a token, only persisted queries are allowed
This commit is contained in:
parent
c31321d695
commit
d6f9e57e77
4 changed files with 28 additions and 2 deletions
|
@ -10,6 +10,7 @@ class API::V2::BaseController < ApplicationController
|
|||
before_action :authenticate_from_token
|
||||
before_action :ensure_authorized_network, if: -> { @api_token.present? }
|
||||
before_action :ensure_token_is_not_expired, if: -> { @api_token.present? }
|
||||
before_action :allow_only_persisted_queries, if: -> { @api_token.blank? }
|
||||
|
||||
before_action do
|
||||
Current.browser = 'api'
|
||||
|
@ -55,6 +56,12 @@ class API::V2::BaseController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def allow_only_persisted_queries
|
||||
if params[:queryId].blank?
|
||||
render json: graphql_error('Without a token, only persisted queries are allowed', :forbidden), status: :forbidden
|
||||
end
|
||||
end
|
||||
|
||||
def ensure_authorized_network
|
||||
if @api_token.forbidden_network?(request.remote_ip)
|
||||
address = IPAddr.new(request.remote_ip)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue