about summary refs log tree commit diff
path: root/app/controllers/api/v2
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2022-10-31 18:25:34 +0100
committerGitHub <noreply@github.com>2022-10-31 18:25:34 +0100
commit968f34300681d8082cf2f824722a3945fc604b2d (patch)
tree910675cc3b8d9022f65bcfa9bee1acee6af8d0e4 /app/controllers/api/v2
parent371563b0e249b6369e04709fb974a8e57413529f (diff)
parent1fe4e5e38c17a726e6aea5d6033139653e89a379 (diff)
Merge pull request #1876 from ClearlyClaire/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/controllers/api/v2')
-rw-r--r--app/controllers/api/v2/search_controller.rb14
1 files changed, 12 insertions, 2 deletions
diff --git a/app/controllers/api/v2/search_controller.rb b/app/controllers/api/v2/search_controller.rb
index 77eeab5b0..b084eae42 100644
--- a/app/controllers/api/v2/search_controller.rb
+++ b/app/controllers/api/v2/search_controller.rb
@@ -5,8 +5,8 @@ class Api::V2::SearchController < Api::BaseController
 
   RESULTS_LIMIT = (ENV['MAX_SEARCH_RESULTS'] || 20).to_i
 
-  before_action -> { doorkeeper_authorize! :read, :'read:search' }
-  before_action :require_user!
+  before_action -> { authorize_if_got_token! :read, :'read:search' }
+  before_action :validate_search_params!
 
   def index
     @search = Search.new(search_results)
@@ -19,6 +19,16 @@ class Api::V2::SearchController < Api::BaseController
 
   private
 
+  def validate_search_params!
+    params.require(:q)
+
+    return if user_signed_in?
+
+    return render json: { error: 'Search queries pagination is not supported without authentication' }, status: 401 if params[:offset].present?
+
+    render json: { error: 'Search queries that resolve remote resources are not supported without authentication' }, status: 401 if truthy_param?(:resolve)
+  end
+
   def search_results
     SearchService.new.call(
       params[:q],