Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop dependency on secure_headers, fix response headers #15712

Merged
merged 3 commits into from
Feb 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,3 @@ gem 'connection_pool', require: false

gem 'xorcist', '~> 1.1'
gem 'pluck_each', '~> 0.1.3'

gem 'secure_headers', '~> 3.5'
4 changes: 0 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,6 @@ GEM
scenic (1.5.4)
activerecord (>= 4.0.0)
railties (>= 4.0.0)
secure_headers (3.9.0)
useragent
securecompare (1.0.0)
semantic_range (2.3.0)
sidekiq (6.1.3)
Expand Down Expand Up @@ -654,7 +652,6 @@ GEM
unf_ext (0.0.7.7)
unicode-display_width (1.7.0)
uniform_notifier (1.13.2)
useragent (0.16.10)
warden (1.2.9)
rack (>= 2.0.9)
webauthn (3.0.0.alpha1)
Expand Down Expand Up @@ -798,7 +795,6 @@ DEPENDENCIES
ruby-progressbar (~> 1.11)
sanitize (~> 5.2)
scenic (~> 1.5)
secure_headers (~> 3.5)
sidekiq (~> 6.1)
sidekiq-bulk (~> 0.2.0)
sidekiq-scheduler (~> 3.0)
Expand Down
1 change: 1 addition & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
require_relative '../lib/chewy/strategy/custom_sidekiq'
require_relative '../lib/webpacker/manifest_extensions'
require_relative '../lib/webpacker/helper_extensions'
require_relative '../lib/action_dispatch/cookie_jar_extensions'
require_relative '../lib/rails/engine_extensions'

Dotenv::Railtie.load
Expand Down
6 changes: 6 additions & 0 deletions config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
value: session_id,
expires: 1.year.from_now,
httponly: true,
secure: (Rails.env.production? || ENV['LOCAL_HTTPS'] == 'true'),
same_site: :lax,
}
end
Expand All @@ -19,6 +20,7 @@
value: warden.cookies.signed['_session_id'] || warden.raw_session['auth_id'],
expires: 1.year.from_now,
httponly: true,
secure: (Rails.env.production? || ENV['LOCAL_HTTPS'] == 'true'),
same_site: :lax,
}
else
Expand Down Expand Up @@ -227,6 +229,10 @@ def valid?
# If true, extends the user's remember period when remembered via cookie.
# config.extend_remember_period = false

# Options to be passed to the created cookie. For instance, you can set
# secure: true in order to force SSL only cookies.
config.rememberable_options = { secure: true }

# ==> Configuration for :validatable
# Range for password length.
config.password_length = 8..72
Expand Down
1 change: 1 addition & 0 deletions config/initializers/makara.rb
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Makara::Cookie::DEFAULT_OPTIONS[:same_site] = :lax
Makara::Cookie::DEFAULT_OPTIONS[:secure] = Rails.env.production? || ENV['LOCAL_HTTPS'] == 'true'
10 changes: 0 additions & 10 deletions config/initializers/secureheaders.rb

This file was deleted.

1 change: 1 addition & 0 deletions config/initializers/session_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

Rails.application.config.session_store :cookie_store, {
key: '_mastodon_session',
secure: (Rails.env.production? || ENV['LOCAL_HTTPS'] == 'true'),
same_site: :lax,
}
15 changes: 15 additions & 0 deletions lib/action_dispatch/cookie_jar_extensions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module ActionDispatch
module CookieJarExtensions
private

# Monkey-patch ActionDispatch to serve secure cookies to Tor Hidden Service
# users. Otherwise, ActionDispatch would drop the cookie over HTTP.
def write_cookie?(*)
request.headers['Host'].ends_with?('.onion') || super
end
end
end

ActionDispatch::Cookies::CookieJar.prepend(ActionDispatch::CookieJarExtensions)