Skip to content

Commit

Permalink
Dev: enable rails-8.0
Browse files Browse the repository at this point in the history
* enable 2-D cookies array (rack-v3+, sprockets-v4.2+)
* Rails.application.secrets is deprecated in favar of
  Rails.application.credentials (rails-v7.2+)
* :add, :remove are not supported in the only: section (rails-v8.0+)
Aleksei Burlakov committed Nov 27, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent c5ff432 commit 2ae19bf
Showing 3 changed files with 18 additions and 4 deletions.
12 changes: 10 additions & 2 deletions hawk/app/lib/hawk/secure_cookies.rb
Original file line number Diff line number Diff line change
@@ -13,11 +13,19 @@ def call(env)
if headers['Set-Cookie'].present?
cookies = headers['Set-Cookie'].split(COOKIE_SEPARATOR)

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

cookie << '; Secure ; HttpOnly'
# no matter what, always add Secure + HttpOnly
if not cookie.kind_of?(Array)
cookie << '; Secure ; HttpOnly'
else
cookie.each do |cookie_atom|
next if cookie_atom.blank?
cookie_atom << '; Secure ; HttpOnly'
end
end
end

headers['Set-Cookie'] = cookies.join(COOKIE_SEPARATOR)
8 changes: 7 additions & 1 deletion hawk/config/initializers/secret.rb
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you"ll be exposed to dictionary attacks.
Rails.application.secrets.secret_key_base = secret_file.open(
key_base = secret_file.open(
File::RDWR | File::CREAT,
0600
) do |f|
@@ -29,4 +29,10 @@

secret
end
if Gem.loaded_specs['rails'].version >= Gem::Version.new("7.2")
Rails.application.credentials.secret_key_base = key_base
else
# deprecated
Rails.application.secrets.secret_key_base = key_base
end
end
2 changes: 1 addition & 1 deletion hawk/config/routes.rb
Original file line number Diff line number Diff line change
@@ -139,7 +139,7 @@
get '/sim/intervals/:id', as: :sim_intervals, to: 'simulator#intervals', defaults: { format: 'json' }, constraints: {id: regex_safe_id }
get '/sim/help', as: :sim_help, to: 'simulator#help'

resource :dashboard, only: [:show, :add, :remove] do
resource :dashboard, only: [:show] do
member do
get :add
post :add

0 comments on commit 2ae19bf

Please sign in to comment.