Skip to content

Commit 37627f3

Browse files
authored
Merge pull request #2633 from luukveenis/guest-token-http-only
Set HttpOnly flag when sending guest_token cookie
2 parents 64bb34a + c18eaa9 commit 37627f3

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

core/lib/spree/core/controller_helpers/auth.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ def redirect_back_or_default(default)
4242

4343
def set_guest_token
4444
unless cookies.signed[:guest_token].present?
45-
cookies.permanent.signed[:guest_token] = SecureRandom.urlsafe_base64(nil, false)
45+
cookies.permanent.signed[:guest_token] = {
46+
value: SecureRandom.urlsafe_base64(nil, false),
47+
httponly: true
48+
}
4649
end
4750
end
4851

core/spec/lib/spree/core/controller_helpers/auth_spec.rb

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def index
4040
end
4141
it 'sends cookie header' do
4242
get :index
43+
expect(response.headers["Set-Cookie"]).to match(/guest_token.*HttpOnly/)
4344
expect(response.cookies['guest_token']).not_to be_nil
4445
end
4546
end

0 commit comments

Comments
 (0)