Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit 44833d7

Browse files
committed
Make the httponly-ness of the cookies configurable
default the configuration to false so that the default behavior matches the previous behavior.
1 parent f4a3517 commit 44833d7

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

app/helpers/casino/sessions_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def sign_in(authentication_result, options = {})
3939
end
4040

4141
def set_tgt_cookie(tgt)
42-
cookies[:tgt] = { value: tgt.ticket, httponly: true}.tap do |cookie|
42+
cookies[:tgt] = { value: tgt.ticket, httponly: !!CASino.config.httponly_tgt_cookies }.tap do |cookie|
4343
if tgt.long_term?
4444
cookie[:expires] = CASino.config.ticket_granting_ticket[:lifetime_long_term].seconds.from_now
4545
end

lib/casino.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module CASino
77
defaults = {
88
authenticators: HashWithIndifferentAccess.new,
99
require_service_rules: false,
10+
httponly_tgt_cookies: false,
1011
logger: Rails.logger,
1112
frontend: HashWithIndifferentAccess.new(
1213
sso_name: 'CASino',

spec/controllers/sessions_controller_spec.rb

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,24 @@
258258
tgt = CASino::TicketGrantingTicket.last
259259
tgt.long_term.should == true
260260
end
261+
262+
it 'creates a cookie that is not httponly by default' do
263+
post :create, params
264+
controller.cookies['tgt']['httponly'].should be(false)
265+
end
266+
267+
context 'when we are configured for http_only_tgt_cookies' do
268+
before do
269+
CASino.config.httponly_tgt_cookies = true
270+
end
271+
after do
272+
CASino.config.httponly_tgt_cookies = false
273+
end
274+
it 'creates an httponly cookie' do
275+
post :create, params
276+
controller.cookies['tgt']['httponly'].should be(true)
277+
end
278+
end
261279
end
262280

263281
context 'with two-factor authentication enabled' do
@@ -399,12 +417,6 @@
399417
ticket_granting_ticket.reload.should_not be_awaiting_two_factor_authentication
400418
end
401419

402-
it 'creates an httponly cookie' do
403-
controller.stub(:cookies).and_return(HashWithIndifferentAccess.new)
404-
post :validate_otp, params
405-
controller.cookies['tgt']['httponly'].should be(true)
406-
end
407-
408420
context 'with a long-term ticket-granting ticket' do
409421
let(:cookie_jar) { HashWithIndifferentAccess.new }
410422

0 commit comments

Comments
 (0)