Skip to content

Commit 1d325f4

Browse files
Merge pull request #292 from aleksei-burlakov/enable-rails-8.0
Dev: enable rails-8.0
2 parents c5ff432 + 2ae19bf commit 1d325f4

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

hawk/app/lib/hawk/secure_cookies.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,19 @@ def call(env)
1313
if headers['Set-Cookie'].present?
1414
cookies = headers['Set-Cookie'].split(COOKIE_SEPARATOR)
1515

16+
# cookies might be 2-D array in the rack-3 / sprockets-4.2
1617
cookies.each do |cookie|
1718
next if cookie.blank?
18-
next if cookie =~ /;\s*secure/i
1919

20-
cookie << '; Secure ; HttpOnly'
20+
# no matter what, always add Secure + HttpOnly
21+
if not cookie.kind_of?(Array)
22+
cookie << '; Secure ; HttpOnly'
23+
else
24+
cookie.each do |cookie_atom|
25+
next if cookie_atom.blank?
26+
cookie_atom << '; Secure ; HttpOnly'
27+
end
28+
end
2129
end
2230

2331
headers['Set-Cookie'] = cookies.join(COOKIE_SEPARATOR)

hawk/config/initializers/secret.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# If you change this key, all old signed cookies will become invalid!
99
# Make sure the secret is at least 30 characters and all random,
1010
# no regular words or you"ll be exposed to dictionary attacks.
11-
Rails.application.secrets.secret_key_base = secret_file.open(
11+
key_base = secret_file.open(
1212
File::RDWR | File::CREAT,
1313
0600
1414
) do |f|
@@ -29,4 +29,10 @@
2929

3030
secret
3131
end
32+
if Gem.loaded_specs['rails'].version >= Gem::Version.new("7.2")
33+
Rails.application.credentials.secret_key_base = key_base
34+
else
35+
# deprecated
36+
Rails.application.secrets.secret_key_base = key_base
37+
end
3238
end

hawk/config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
get '/sim/intervals/:id', as: :sim_intervals, to: 'simulator#intervals', defaults: { format: 'json' }, constraints: {id: regex_safe_id }
140140
get '/sim/help', as: :sim_help, to: 'simulator#help'
141141

142-
resource :dashboard, only: [:show, :add, :remove] do
142+
resource :dashboard, only: [:show] do
143143
member do
144144
get :add
145145
post :add

0 commit comments

Comments
 (0)