Skip to content

Commit

Permalink
Merge pull request #296 from anujdas/fix_secure_cookies
Browse files Browse the repository at this point in the history
Set secure cookies on interleaved http/https calls correctly
  • Loading branch information
oreoshake authored Oct 12, 2016
2 parents df03646 + 57e77b7 commit 530b6b5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2.3
2.2.5
2 changes: 1 addition & 1 deletion lib/secure_headers/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def initialize(&block)
# Returns a deep-dup'd copy of this configuration.
def dup
copy = self.class.new
copy.cookies = @cookies
copy.cookies = self.class.send(:deep_copy_if_hash, @cookies)
copy.csp = @csp.dup if @csp
copy.csp_report_only = @csp_report_only.dup if @csp_report_only
copy.cached_headers = self.class.send(:deep_copy_if_hash, @cached_headers)
Expand Down
12 changes: 12 additions & 0 deletions spec/lib/secure_headers/middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ module SecureHeaders
_, env = cookie_middleware.call request.env
expect(env['Set-Cookie']).to eq("foo=bar")
end

it "sets the secure cookie flag correctly on interleaved http/https requests" do
Configuration.default { |config| config.cookies = { secure: true } }

request = Rack::Request.new("HTTPS" => "off")
_, env = cookie_middleware.call request.env
expect(env['Set-Cookie']).to eq("foo=bar")

request = Rack::Request.new("HTTPS" => "on")
_, env = cookie_middleware.call request.env
expect(env['Set-Cookie']).to eq("foo=bar; secure")
end
end
end
end

0 comments on commit 530b6b5

Please sign in to comment.