Skip to content

Commit 6cc1919

Browse files
authored
Fix query params being clobbered by Clearance::BackDoor (#1041)
In rack 3.1.x Setting Rack::RACK_REQUEST_QUERY_STRING causes rack to think that the query string has already been parsed (see https://github.com/rack/rack/blob/v3.1.7/lib/rack/request.rb#L487) This was introduced in #2703 but wasn't actually necessary - the warning mentioned in that PR is only triggered if only Rack::RACK_REQUEST_QUERY_STRING is updated, but the correct behaviour is to only set Rack::QUERY_STRING, not to set both Fixes #1040
1 parent 704ba2a commit 6cc1919

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

lib/clearance/back_door.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ def sign_in_through_the_back_door(env)
5454
if user_param.present?
5555
query_string = Rack::Utils.build_query(params)
5656
env[Rack::QUERY_STRING] = query_string
57-
env[Rack::RACK_REQUEST_QUERY_STRING] = query_string
5857
user = find_user(user_param)
5958
env[:clearance].sign_in(user)
6059
end

spec/dummy/app/controllers/application_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ class ApplicationController < ActionController::Base
22
include Clearance::Controller
33

44
def show
5-
render inline: "Hello user #<%= current_user.id %>", layout: false
5+
render inline: "Hello user #<%= current_user.id %> #{params.to_json}", layout: false
66
end
77
end

spec/requests/backdoor_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,12 @@
88

99
expect(cookies["remember_token"]).to eq user.remember_token
1010
end
11+
12+
it "removes the `as` param but leaves other parameters unchanged" do
13+
user = create(:user)
14+
15+
get root_path(as: user.to_param, foo: 'bar')
16+
17+
expect(response.body).to include('{"foo":"bar","controller":"application","action":"show"}')
18+
end
1119
end

0 commit comments

Comments
 (0)