From 0438ed524ed4bcd5b59ef6276ae63626a77737c4 Mon Sep 17 00:00:00 2001 From: Samuel Giddins Date: Mon, 9 Oct 2023 18:34:51 -0700 Subject: [PATCH] [WIP] Rails 7.1 --- Gemfile | 7 +- Gemfile.lock | 191 ++++++++++-------- .../concerns/maintenance_tasks_auditable.rb | 4 +- app/jobs/application_job.rb | 2 +- app/jobs/store_version_contents_job.rb | 4 +- app/jobs/verify_link_job.rb | 2 +- app/jobs/yank_version_contents_job.rb | 2 +- app/models/audit.rb | 2 +- app/models/version.rb | 2 +- bin/setup | 2 +- config/application.rb | 9 +- config/environments/development.rb | 11 +- config/environments/production.rb | 18 +- config/environments/test.rb | 21 +- .../initializers/content_security_policy.rb | 4 +- .../initializers/filter_parameter_logging.rb | 4 +- config/initializers/launchdarkly.rb | 1 + config/initializers/permissions_policy.rb | 20 +- config/initializers/turbo.rb | 3 + db/schema.rb | 2 +- test/integration/session_test.rb | 10 +- test/system/avo/oidc_providers_test.rb | 2 +- 22 files changed, 198 insertions(+), 125 deletions(-) create mode 100644 config/initializers/turbo.rb diff --git a/Gemfile b/Gemfile index 161cdc49e42..9f8178ae905 100644 --- a/Gemfile +++ b/Gemfile @@ -1,12 +1,12 @@ source "https://rubygems.org" -gem "rails", "~> 7.0.0" +gem "rails", "~> 7.1.0" gem "rails-i18n", "~> 7.0" gem "aws-sdk-s3", "~> 1.141" gem "aws-sdk-sqs", "~> 1.69" gem "bootsnap", "~> 1.16" -gem "clearance", "~> 2.6" +gem "clearance", "~> 2.6", github: "thoughtbot/clearance", ref: "6190c92521317b6de577c8ea3dff75cb832dc6b4" gem "dalli", "~> 3.2" gem "ddtrace", "~> 1.18", require: "ddtrace/auto_instrument" gem "dogstatsd-ruby", "~> 5.5" @@ -32,7 +32,7 @@ gem "rack", "~> 2.2" gem "rack-utf8_sanitizer", "~> 1.8" gem "rbtrace", "~> 0.5.0" gem "rdoc", "~> 6.6" -gem "roadie-rails", "~> 3.0" +gem "roadie-rails", "~> 3.1" gem "ruby-magic", "~> 0.6" gem "shoryuken", "~> 6.1", require: false gem "statsd-instrument", "~> 3.5" @@ -113,6 +113,5 @@ group :test do gem "simplecov-cobertura", "~> 2.1", require: false gem "aggregate_assertions", "~> 0.2.0" gem "minitest-gcstats", "~> 1.3" - gem "minitest-profile", "~> 0.0.2" gem "minitest-reporters", "~> 1.6" end diff --git a/Gemfile.lock b/Gemfile.lock index 00218879d10..efc7a0fe594 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,73 +1,96 @@ +GIT + remote: https://github.com/thoughtbot/clearance.git + revision: 6190c92521317b6de577c8ea3dff75cb832dc6b4 + ref: 6190c92521317b6de577c8ea3dff75cb832dc6b4 + specs: + clearance (2.6.1) + actionmailer (>= 5.0) + activemodel (>= 5.0) + activerecord (>= 5.0) + argon2 (~> 2.0, >= 2.0.2) + bcrypt (>= 3.1.1) + email_validator (~> 2.0) + railties (>= 5.0) + GEM remote: https://rubygems.org/ specs: - actioncable (7.0.8) - actionpack (= 7.0.8) - activesupport (= 7.0.8) + actioncable (7.1.2) + actionpack (= 7.1.2) + activesupport (= 7.1.2) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (7.0.8) - actionpack (= 7.0.8) - activejob (= 7.0.8) - activerecord (= 7.0.8) - activestorage (= 7.0.8) - activesupport (= 7.0.8) + zeitwerk (~> 2.6) + actionmailbox (7.1.2) + actionpack (= 7.1.2) + activejob (= 7.1.2) + activerecord (= 7.1.2) + activestorage (= 7.1.2) + activesupport (= 7.1.2) mail (>= 2.7.1) net-imap net-pop net-smtp - actionmailer (7.0.8) - actionpack (= 7.0.8) - actionview (= 7.0.8) - activejob (= 7.0.8) - activesupport (= 7.0.8) + actionmailer (7.1.2) + actionpack (= 7.1.2) + actionview (= 7.1.2) + activejob (= 7.1.2) + activesupport (= 7.1.2) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp - rails-dom-testing (~> 2.0) - actionpack (7.0.8) - actionview (= 7.0.8) - activesupport (= 7.0.8) - rack (~> 2.0, >= 2.2.4) + rails-dom-testing (~> 2.2) + actionpack (7.1.2) + actionview (= 7.1.2) + activesupport (= 7.1.2) + nokogiri (>= 1.8.5) + racc + rack (>= 2.2.4) + rack-session (>= 1.0.1) rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (7.0.8) - actionpack (= 7.0.8) - activerecord (= 7.0.8) - activestorage (= 7.0.8) - activesupport (= 7.0.8) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + actiontext (7.1.2) + actionpack (= 7.1.2) + activerecord (= 7.1.2) + activestorage (= 7.1.2) + activesupport (= 7.1.2) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.0.8) - activesupport (= 7.0.8) + actionview (7.1.2) + activesupport (= 7.1.2) builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.1, >= 1.2.0) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) active_link_to (1.0.5) actionpack addressable - activejob (7.0.8) - activesupport (= 7.0.8) + activejob (7.1.2) + activesupport (= 7.1.2) globalid (>= 0.3.6) - activemodel (7.0.8) - activesupport (= 7.0.8) - activerecord (7.0.8) - activemodel (= 7.0.8) - activesupport (= 7.0.8) - activestorage (7.0.8) - actionpack (= 7.0.8) - activejob (= 7.0.8) - activerecord (= 7.0.8) - activesupport (= 7.0.8) + activemodel (7.1.2) + activesupport (= 7.1.2) + activerecord (7.1.2) + activemodel (= 7.1.2) + activesupport (= 7.1.2) + timeout (>= 0.4.0) + activestorage (7.1.2) + actionpack (= 7.1.2) + activejob (= 7.1.2) + activerecord (= 7.1.2) + activesupport (= 7.1.2) marcel (~> 1.0) - mini_mime (>= 1.1.0) - activesupport (7.0.8) + activesupport (7.1.2) + base64 + bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb i18n (>= 1.6, < 2) minitest (>= 5.1) + mutex_m tzinfo (~> 2.0) addressable (2.8.5) public_suffix (>= 2.0.2, < 6.0) @@ -77,8 +100,8 @@ GEM amazing_print (1.5.0) android_key_attestation (0.3.0) ansi (1.5.0) - argon2 (2.1.1) - ffi (~> 1.14) + argon2 (2.3.0) + ffi (~> 1.15) ffi-compiler (~> 1.0) ast (2.4.2) attr_required (1.0.1) @@ -122,6 +145,7 @@ GEM base64 (0.2.0) bcrypt (3.1.20) benchmark-ips (2.12.0) + bigdecimal (3.1.4) bindata (2.4.15) bitarray (1.2.0) bloomer (1.0.0) @@ -147,17 +171,10 @@ GEM chartkick (5.0.4) choice (0.2.0) chunky_png (1.4.0) - clearance (2.6.1) - actionmailer (>= 5.0) - activemodel (>= 5.0) - activerecord (>= 5.0) - argon2 (~> 2.0, >= 2.0.2) - bcrypt (>= 3.1.1) - email_validator (~> 2.0) - railties (>= 5.0) coderay (1.1.3) compact_index (0.14.0) concurrent-ruby (1.2.2) + connection_pool (2.4.1) cose (1.3.0) cbor (~> 0.5.9) openssl-signature_algorithm (~> 1.0) @@ -206,8 +223,10 @@ GEM dotenv-rails (2.8.1) dotenv (= 2.8.1) railties (>= 3.2) + drb (2.2.0) + ruby2_keywords dry-initializer (3.1.1) - email_validator (2.2.3) + email_validator (2.2.4) activemodel erb (4.0.3) cgi (>= 0.3.3) @@ -275,6 +294,10 @@ GEM inline_svg (1.9.0) activesupport (>= 3.0) nokogiri (>= 1.6) + io-console (0.6.0) + irb (1.9.1) + rdoc + reline (>= 0.3.8) jmespath (1.6.2) job-iteration (1.4.1) activejob (>= 5.2) @@ -355,7 +378,6 @@ GEM minitest (5.20.0) minitest-gcstats (1.3.0) minitest (~> 5.0) - minitest-profile (0.0.2) minitest-reporters (1.6.1) ansi builder @@ -366,6 +388,7 @@ GEM msgpack (1.7.2) multi_json (1.15.0) multi_xml (0.6.0) + mutex_m (0.2.0) net-imap (0.4.6) date net-protocol @@ -463,24 +486,29 @@ GEM rack (>= 2.1.0) rack-protection (3.0.5) rack + rack-session (1.0.1) + rack (< 3) rack-test (2.1.0) rack (>= 1.3) rack-utf8_sanitizer (1.9.1) rack (>= 1.0, < 4.0) - rails (7.0.8) - actioncable (= 7.0.8) - actionmailbox (= 7.0.8) - actionmailer (= 7.0.8) - actionpack (= 7.0.8) - actiontext (= 7.0.8) - actionview (= 7.0.8) - activejob (= 7.0.8) - activemodel (= 7.0.8) - activerecord (= 7.0.8) - activestorage (= 7.0.8) - activesupport (= 7.0.8) + rackup (1.0.0) + rack (< 3) + webrick + rails (7.1.2) + actioncable (= 7.1.2) + actionmailbox (= 7.1.2) + actionmailer (= 7.1.2) + actionpack (= 7.1.2) + actiontext (= 7.1.2) + actionview (= 7.1.2) + activejob (= 7.1.2) + activemodel (= 7.1.2) + activerecord (= 7.1.2) + activestorage (= 7.1.2) + activesupport (= 7.1.2) bundler (>= 1.15.0) - railties (= 7.0.8) + railties (= 7.1.2) rails-controller-testing (1.0.5) actionpack (>= 5.0.1.rc1) actionview (>= 5.0.1.rc1) @@ -504,13 +532,14 @@ GEM rack railties (>= 5.1) semantic_logger (~> 4.13) - railties (7.0.8) - actionpack (= 7.0.8) - activesupport (= 7.0.8) - method_source + railties (7.1.2) + actionpack (= 7.1.2) + activesupport (= 7.1.2) + irb + rackup (>= 1.0.0) rake (>= 12.2) - thor (~> 1.0) - zeitwerk (~> 2.5) + thor (~> 1.0, >= 1.2.2) + zeitwerk (~> 2.6) rainbow (3.1.1) rake (13.1.0) rb-fsevent (0.11.2) @@ -523,6 +552,8 @@ GEM rdoc (6.6.1) psych (>= 4.0.0) regexp_parser (2.8.1) + reline (0.4.0) + io-console (~> 0.5) rexml (3.2.6) roadie (5.2.0) css_parser (~> 1.4) @@ -676,6 +707,7 @@ GEM addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) + webrick (1.8.1) websocket (1.2.10) websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) @@ -702,7 +734,7 @@ DEPENDENCIES browser (~> 5.3, >= 5.3.1) capybara (~> 3.38) chartkick (~> 5.0) - clearance (~> 2.6) + clearance (~> 2.6)! compact_index (~> 0.14.0) dalli (~> 3.2) dartsass-sprockets (~> 3.0) @@ -732,7 +764,6 @@ DEPENDENCIES memory_profiler (~> 1.0) minitest (~> 5.18) minitest-gcstats (~> 1.3) - minitest-profile (~> 0.0.2) minitest-reporters (~> 1.6) mocha (~> 2.0) octokit (~> 8.0) @@ -750,14 +781,14 @@ DEPENDENCIES rack-attack (~> 6.6) rack-test (~> 2.1) rack-utf8_sanitizer (~> 1.8) - rails (~> 7.0.0) + rails (~> 7.1.0) rails-controller-testing (~> 1.0) rails-erd (~> 1.7) rails-i18n (~> 7.0) rails_semantic_logger (~> 4.14) rbtrace (~> 0.5.0) rdoc (~> 6.6) - roadie-rails (~> 3.0) + roadie-rails (~> 3.1) rotp (~> 6.2) rqrcode (~> 2.1) rubocop (~> 1.48) diff --git a/app/controllers/concerns/maintenance_tasks_auditable.rb b/app/controllers/concerns/maintenance_tasks_auditable.rb index 8532ec66db0..c736e992b35 100644 --- a/app/controllers/concerns/maintenance_tasks_auditable.rb +++ b/app/controllers/concerns/maintenance_tasks_auditable.rb @@ -3,9 +3,11 @@ module MaintenanceTasksAuditable prepended do include Auditable - around_action :audit_action, except: %i[index show] + around_action :audit_action def audit_action(&) + return yield if params[:action].in?(%w[show index]) + action = params.fetch(:action) task_name = params.fetch(:task_id) diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index dbc38ffe735..49707c8946a 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -11,7 +11,7 @@ class ApplicationJob < ActiveJob::Base # Default to retrying errors a few times, so we don't get an alert for # spurious errors - retry_on StandardError, wait: :exponentially_longer, attempts: 5 + retry_on StandardError, wait: :polynomially_longer, attempts: 5 # Automatically retry jobs that encountered a deadlock retry_on ActiveRecord::Deadlocked diff --git a/app/jobs/store_version_contents_job.rb b/app/jobs/store_version_contents_job.rb index 92225b996d2..43988fb6a9a 100644 --- a/app/jobs/store_version_contents_job.rb +++ b/app/jobs/store_version_contents_job.rb @@ -9,8 +9,8 @@ class GemNotFound < RuntimeError; end discard_on ActiveJob::DeserializationError discard_on Gem::Package::FormatError, Gem::Security::Exception - retry_on VersionNotIndexed, wait: :exponentially_longer, attempts: 5 - retry_on GemNotFound, wait: :exponentially_longer, attempts: 5 + retry_on VersionNotIndexed, wait: :polynomially_longer, attempts: 5 + retry_on GemNotFound, wait: :polynomially_longer, attempts: 5 rescue_from(GemNotFound, Gem::Package::FormatError, Gem::Security::Exception) do |error| version = version_arg.full_name diff --git a/app/jobs/verify_link_job.rb b/app/jobs/verify_link_job.rb index b65719bafce..efae34c0583 100644 --- a/app/jobs/verify_link_job.rb +++ b/app/jobs/verify_link_job.rb @@ -1,7 +1,7 @@ class VerifyLinkJob < ApplicationJob queue_as :default - retry_on ActiveRecord::RecordNotFound, ActiveRecord::RecordInvalid, wait: :exponentially_longer, attempts: 3 + retry_on ActiveRecord::RecordNotFound, ActiveRecord::RecordInvalid, wait: :polynomially_longer, attempts: 3 ERRORS = (HTTP_ERRORS + [Faraday::Error, SocketError, SystemCallError, OpenSSL::SSL::SSLError]).freeze diff --git a/app/jobs/yank_version_contents_job.rb b/app/jobs/yank_version_contents_job.rb index ec5e5ba09be..c7e5372dc8a 100644 --- a/app/jobs/yank_version_contents_job.rb +++ b/app/jobs/yank_version_contents_job.rb @@ -7,7 +7,7 @@ class VersionNotYanked < RuntimeError; end discard_on ActiveJob::DeserializationError - retry_on VersionNotYanked, wait: :exponentially_longer, attempts: 5 + retry_on VersionNotYanked, wait: :polynomially_longer, attempts: 5 def version_arg arguments.first[:version] diff --git a/app/models/audit.rb b/app/models/audit.rb index 4784d308c9b..f806bcf94bc 100644 --- a/app/models/audit.rb +++ b/app/models/audit.rb @@ -2,7 +2,7 @@ class Audit < ApplicationRecord belongs_to :auditable, polymorphic: true belongs_to :admin_github_user, class_name: "Admin::GitHubUser" - serialize :audited_changes, JSON + serialize :audited_changes, coder: JSON validates :action, presence: true validates :auditable, presence: false diff --git a/app/models/version.rb b/app/models/version.rb index 89a483f21bf..a1dc9044e6a 100644 --- a/app/models/version.rb +++ b/app/models/version.rb @@ -24,7 +24,7 @@ class Version < ApplicationRecord # rubocop:disable Metrics/ClassLength serialize :licenses serialize :requirements - serialize :cert_chain, CertificateChainSerializer + serialize :cert_chain, coder: CertificateChainSerializer validates :number, length: { maximum: Gemcutter::MAX_FIELD_LENGTH }, format: { with: Patterns::VERSION_PATTERN } validates :platform, length: { maximum: Gemcutter::MAX_FIELD_LENGTH }, format: { with: Rubygem::NAME_PATTERN } diff --git a/bin/setup b/bin/setup index 09be7d70e9d..e2675753e1d 100755 --- a/bin/setup +++ b/bin/setup @@ -5,7 +5,7 @@ require "fileutils" APP_ROOT = File.expand_path("..", __dir__) def system!(*args) - system(*args) || abort("\n== Command #{args} failed ==") + system(*args, exception: true) end FileUtils.chdir APP_ROOT do diff --git a/config/application.rb b/config/application.rb index d4b6d24bfb7..e4f8a5aaca9 100644 --- a/config/application.rb +++ b/config/application.rb @@ -2,7 +2,7 @@ require "rails" # Pick the frameworks you want: -# require "active_model/railtie" +require "active_model/railtie" require "active_job/railtie" require "active_record/railtie" # require "active_storage/engine" @@ -14,6 +14,7 @@ # require "action_cable/engine" require "sprockets/railtie" require "rails/test_unit/railtie" + # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) @@ -23,6 +24,11 @@ class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. config.load_defaults 6.1 + # Please, add to the `ignore` list any other `lib` subdirectories that do + # not contain `.rb` files, or that should not be reloaded or eager loaded. + # Common ones are `templates`, `generators`, or `middleware`, for example. + config.autoload_lib(ignore: %w[assets tasks cops shoryuken]) + # Settings in config/environments/* take precedence over those specified here. # Application configuration can go into files in config/initializers # -- all .rb files in that directory are automatically loaded after loading @@ -51,7 +57,6 @@ class Application < Rails::Application RubygemFs.s3! ENV["S3_PROXY"] if ENV["S3_PROXY"] end - config.eager_load_paths << Rails.root.join("lib") config.toxic_domains_filepath = Rails.root.join("vendor", "toxic_domains_whole.txt") config.active_job.queue_adapter = :good_job diff --git a/config/environments/development.rb b/config/environments/development.rb index f8dfb707135..612f62b9c2c 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -7,7 +7,7 @@ # In the development environment your application's code is reloaded any time # it changes. This slows down response time but is perfect for development # since you don't have to restart the web server when you make code changes. - config.cache_classes = false + config.enable_reloading = true # Do not eager load code on boot. config.eager_load = false @@ -61,6 +61,9 @@ # Highlight code that triggered database queries in logs. config.active_record.verbose_query_logs = true + # Highlight code that enqueued background job in logs. + config.active_job.verbose_enqueue_logs = true + # Debug mode disables concatenation and preprocessing of assets. # This option may cause significant delays in view rendering with a large # number of complex assets. @@ -76,6 +79,9 @@ # Annotate rendered view with file names. # config.action_view.annotate_rendered_view_with_filenames = true + # Raise error when a before_action's only/except options reference missing actions + config.action_controller.raise_on_missing_callback_actions = true + # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. config.file_watcher = ActiveSupport::EventedFileUpdateChecker @@ -123,7 +129,4 @@ config.active_record.verbose_query_logs = false config.action_view.cache_template_loading = true end - - # Uncomment if you wish to allow Action Cable access from any origin. - # config.action_cable.disable_request_forgery_protection = true end diff --git a/config/environments/production.rb b/config/environments/production.rb index c3af35cbad5..80b38130b49 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -6,7 +6,7 @@ # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. - config.cache_classes = true + config.enable_reloading = false # Eager load code on boot. This eager loads most of Rails and # your application in memory, allowing both threaded web servers @@ -18,8 +18,8 @@ config.consider_all_requests_local = false config.action_controller.perform_caching = true - # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] - # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). + # Ensures that a master key has been made available in ENV["RAILS_MASTER_KEY"], config/master.key, or an environment + # key such as config/credentials/production.key. This key is used to decrypt credentials (and other encrypted files). # config.require_master_key = true # Disable serving static files from the `/public` folder by default since @@ -46,6 +46,10 @@ # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache # config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX + # Assume all access to the app is happening through a SSL-terminating reverse proxy. + # Can be used together with config.force_ssl for Strict-Transport-Security and secure cookies. + # config.assume_ssl = true + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. config.force_ssl = true config.ssl_options = { @@ -100,6 +104,14 @@ # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false + # Enable DNS rebinding protection and other `Host` header attacks. + # config.hosts = [ + # "example.com", # Allow requests from example.com + # /.*\.example\.com/ # Allow requests from subdomains like `www.example.com` + # ] + # Skip DNS rebinding protection for the default health check endpoint. + # config.host_authorization = { exclude: ->(request) { request.path == "/up" } } + config.cache_store = :mem_cache_store, ENV['MEMCACHED_ENDPOINT'], { failover: true, socket_timeout: 1.5, diff --git a/config/environments/test.rb b/config/environments/test.rb index a795e0e13af..73358c44122 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -9,25 +9,28 @@ Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. - config.cache_classes = true + # While tests run files are not watched, reloading is not necessary. + config.enable_reloading = false - # Do not eager load code on boot. This avoids loading your whole application - # just for the purpose of running a single test. If you are using a tool that - # preloads Rails for running tests, you may have to set it to true. - config.eager_load = false + # Eager loading loads your entire application. When running a single test locally, + # this is usually not necessary, and can slow down your test suite. However, it's + # recommended that you enable it in continuous integration systems to ensure eager + # loading is working properly before deploying your code. + config.eager_load = ENV["CI"].present? # Configure public file server for tests with Cache-Control for performance. config.public_file_server.enabled = true config.public_file_server.headers = { - 'Cache-Control' => "public, max-age=#{1.hour.to_i}" + "Cache-Control" => "public, max-age=#{1.hour.to_i}" } # Show full error reports and disable caching. config.consider_all_requests_local = true config.action_controller.perform_caching = false + config.cache_store = :mem_cache_store # Raise exceptions instead of rendering exception templates. - config.action_dispatch.show_exceptions = false + config.action_dispatch.show_exceptions = :none # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false @@ -55,7 +58,6 @@ # Tell Active Support which deprecation messages to disallow. config.active_support.disallowed_deprecation_warnings = [] - config.cache_store = :mem_cache_store # Raises error for missing translations. config.i18n.raise_on_missing_translations = true @@ -63,6 +65,9 @@ # Annotate rendered view with file names. # config.action_view.annotate_rendered_view_with_filenames = true + # Raise error when a before_action's only/except options reference missing actions + config.action_controller.raise_on_missing_callback_actions = true + BCrypt::Engine.cost = BCrypt::Engine::MIN_COST if ENV["CI"] && !ENV["RAILS_ENABLE_TEST_LOG"] diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index 7192151be9e..6537637532e 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -44,9 +44,9 @@ } end -# Generate session nonces for permitted importmap and inline scripts +# Generate session nonces for permitted importmap, inline scripts, and inline styles. Rails.application.config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s } -Rails.application.config.content_security_policy_nonce_directives = %w[script-src] +Rails.application.config.content_security_policy_nonce_directives = %w[script-src style-src] # Report CSP violations to a specified URI. See: # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index bd215540566..d997f9aa485 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -1,6 +1,8 @@ # Be sure to restart your server when you modify this file. -# Configure sensitive parameters which will be filtered from the log file. +# Configure parameters to be partially matched (e.g. passw matches password) and filtered from the log file. +# Use this to limit dissemination of sensitive information. +# See the ActiveSupport::ParameterFilter documentation for supported notations and behaviors. Rails.application.config.filter_parameters += %I[ password passw secret token _key crypt salt certificate otp ssn api_key recovery_codes seed jwt diff --git a/config/initializers/launchdarkly.rb b/config/initializers/launchdarkly.rb index c8931d06abf..372f00ce03f 100644 --- a/config/initializers/launchdarkly.rb +++ b/config/initializers/launchdarkly.rb @@ -1,3 +1,4 @@ +# DEPRECATION WARNING: `Rails.application.secrets` is deprecated in favor of `Rails.application.credentials` and will be removed in Rails 7.2. Rails.application.configure do ld_config = LaunchDarkly::Config.new( logger: SemanticLogger[LaunchDarkly], diff --git a/config/initializers/permissions_policy.rb b/config/initializers/permissions_policy.rb index 00f64d71b03..7db3b9577e6 100644 --- a/config/initializers/permissions_policy.rb +++ b/config/initializers/permissions_policy.rb @@ -1,11 +1,13 @@ +# Be sure to restart your server when you modify this file. + # Define an application-wide HTTP permissions policy. For further -# information see https://developers.google.com/web/updates/2018/06/feature-policy -# -# Rails.application.config.permissions_policy do |f| -# f.camera :none -# f.gyroscope :none -# f.microphone :none -# f.usb :none -# f.fullscreen :self -# f.payment :self, "https://secure.example.com" +# information see: https://developers.google.com/web/updates/2018/06/feature-policy + +# Rails.application.config.permissions_policy do |policy| +# policy.camera :none +# policy.gyroscope :none +# policy.microphone :none +# policy.usb :none +# policy.fullscreen :self +# policy.payment :self, "https://secure.example.com" # end diff --git a/config/initializers/turbo.rb b/config/initializers/turbo.rb new file mode 100644 index 00000000000..d7794b6ec78 --- /dev/null +++ b/config/initializers/turbo.rb @@ -0,0 +1,3 @@ +# https://github.com/hotwired/turbo-rails/issues/512 +# +Rails.autoloaders.once.do_not_eager_load("#{Turbo::Engine.root}/app/channels") diff --git a/db/schema.rb b/db/schema.rb index e280f51d425..fd7b44481ff 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_11_29_233528) do +ActiveRecord::Schema[7.1].define(version: 2023_11_29_233528) do # These are extensions that must be enabled in order to support this database enable_extension "hstore" enable_extension "pgcrypto" diff --git a/test/integration/session_test.rb b/test/integration/session_test.rb index 13e425639e4..e9cf8f161ff 100644 --- a/test/integration/session_test.rb +++ b/test/integration/session_test.rb @@ -3,6 +3,8 @@ class SessionTest < ActionDispatch::IntegrationTest def retrive_authenticity_token(path) get path + + assert_response :success request.session[:_csrf_token] end @@ -10,7 +12,7 @@ def retrive_authenticity_token(path) create(:user, handle: "johndoe", password: PasswordHelpers::SECURE_TEST_PASSWORD) @last_session_token = retrive_authenticity_token sign_in_path post session_path(session: { who: "johndoe", password: PasswordHelpers::SECURE_TEST_PASSWORD }) - ActionController::Base.allow_forgery_protection = true # default is false + ActionController::Base.allow_forgery_protection = true # default is false in test env end teardown do @@ -31,12 +33,18 @@ def retrive_authenticity_token(path) @last_session_token = retrive_authenticity_token edit_profile_path delete sign_out_path(authenticity_token: request.session[:_csrf_token]) + assert_response :redirect + assert_redirected_to sign_in_path + create(:user, handle: "bob", password: PasswordHelpers::SECURE_TEST_PASSWORD) post session_path( session: { who: "bob", password: PasswordHelpers::SECURE_TEST_PASSWORD }, authenticity_token: request.session[:_csrf_token] ) + assert_response :redirect + assert_redirected_to dashboard_path + patch "/profile", params: { user: { handle: "alice" }, authenticity_token: @last_session_token } assert_response :forbidden diff --git a/test/system/avo/oidc_providers_test.rb b/test/system/avo/oidc_providers_test.rb index 39d0bb25186..8b91d0ecaf0 100644 --- a/test/system/avo/oidc_providers_test.rb +++ b/test/system/avo/oidc_providers_test.rb @@ -165,7 +165,7 @@ def sign_in_as(user) ) assert_equal( "78167F727DEC5D801DD1C8784C704A1C880EC0E1", - audit.audited_changes.dig("records", "gid://gemcutter/OIDC::Provider/#{provider.id}", "changes", "jwks", 1, "keys", 0, "kid") + audit.audited_changes.dig("records", "gid://gemcutter/OIDC::Provider/#{provider.id}", "changes", "jwks", 1, 0, "kid") ) assert_equal admin_user, audit.admin_github_user assert_equal "A nice long comment", audit.comment