Skip to content

Commit

Permalink
Make sure to validate recapta when doing a facet search. (#4858)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkinzer authored Jan 13, 2025
1 parent 840a92e commit efffefa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/controllers/primo_central_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ def recaptcha
return if request.referer.present? && URI.parse(request.referer).host == request.host

# skip if nothing to query.
return if params["q"].blank?
return if params["q"].blank? && params["f"].blank?

if !verify_recaptcha(action: @recaptcha_action)
if !verify_recaptcha(action: @recaptcha_action, minimum_score: 0.9)
raise Recaptcha::VerifyError.new("recaptcha verification failed for #{@recaptcha_action}")
end
end
Expand Down
17 changes: 13 additions & 4 deletions spec/controllers/primo_central_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,20 @@
end
end

describe "recaptcha" do
context "with recaptche enabled" do
describe "recaptcha enabled" do
before do
stub_const("ENV", ENV.to_h.merge("RECAPTCHA_SITE_KEY" => "foo"))
allow(controller).to receive(:verify_recaptcha).and_return(false)
end

context "with regular query" do
it "should not allow article searches" do
expect { get :index, params: { q: "foo " } }.to raise_error(Recaptcha::VerifyError)
end
end

context "with facet query" do
it "should not allow article searches" do
stub_const("ENV", ENV.to_h.merge("RECAPTCHA_SITE_KEY" => "foo"))
allow(controller).to receive(:verify_recaptcha).and_return(false)
expect { get :index, params: { q: "foo " } }.to raise_error(Recaptcha::VerifyError)
end
end
Expand Down

0 comments on commit efffefa

Please sign in to comment.