Hi, it’s Claudio Baccigalupo. This week’s changes to the Rails codebase have a strong focus on security, from a rewritten guide to safer defaults for new apps.
Rewrite the Securing Rails guide
As part of the Rails Foundation documentation effort, the refreshed guide drops outdated sections and old gems, adds a new section on cookies, and covers file uploads with Active Storage.
Patch Rack::Multipart::Parser to not allow arbitrary encoding
Multipart form data submitted in arbitrary encodings has little to no legitimate use, but it has been used several times in exploit chains targeting Rails applications. Rails now patches Rack to disregard it. The change is also backported to 8.1 and 8.0. If your app depends on that behavior, opt out with:
config.action_dispatch.allow_rack_multipart_encoding = true
Harden generated GitHub Actions workflows
The ci.yml of new apps pins the versions of actions to a SHA to mitigate repointed git tag attacks, in a format that Dependabot keeps up to date. ruby/setup-ruby stays unpinned so new Ruby releases are available right away. Checkout actions also set persist-credentials: false, so later steps can’t read GitHub tokens from the filesystem.
Add config.active_record.association_scope_keeps_owner_conditions
unscope(where: ...), unscope(:where) and rewhere in an association scope could remove the condition that ties the records to their owner, so update_all, delete_all and dependent: :delete_all could affect records of other owners. With load_defaults "8.2", those conditions are always applied. Otherwise the old behavior is kept with a deprecation warning:
class Car < ActiveRecord::Base
has_many :all_bulbs, -> { unscope(:where) }, class_name: "Bulb"
end
car.all_bulbs
# Before: SELECT "bulbs".* FROM "bulbs"
# After: SELECT "bulbs".* FROM "bulbs" WHERE "bulbs"."car_id" = ?
Break hard dependency between Action Mailer and Active Job
Apps that use Action Mailer without Active Job now load much less code. If you use Action Mailer outside of Rails and rely on deliver_later, you may need to add Active Job to your Gemfile.
Check for protect_from_forgery in ActiveStorage::BaseController
Apps that turned off default_protect_from_forgery get forgery protection on Active Storage controllers again.
Entirely drop support for Active Record 6.1 marshal format
Writing in that format was already dropped. Now Active Record models marshaled with Rails 6.1 can’t be loaded either.
Support sets in class attributes and token lists
Set became a core class in Ruby 4.0, and it’s a natural fit for HTML classes:
tag.button("Save", class: Set["button", "primary"])
# Before: <button class="Set["button", "primary"]">Save</button>
# After: <button class="button primary">Save</button>
Remove job from the execution context after perform_now
The name of a job performed with perform_now leaked into the SQL comments of queries run after the job had finished.
Don’t generate fixture values for virtual columns
Fixtures no longer fail to load with “table has no columns named…” for tables with virtual columns, as their values are now left to the database.
Cast grouped keys and plucked columns unknown to the schema
Grouping by or plucking a column of a joined subquery or a CTE now casts it with the type the database reports:
Topic.with(read_topics: Topic.select("id AS topic_id", :last_read)).joins(:read_topics).pluck("read_topics.last_read")
# Before: ["2004-04-15"]
# After: [Thu, 15 Apr 2004]
Fix numericality :odd and :even options raising for non-finite values
Infinity and NaN now add the :odd or :even error instead of raising FloatDomainError.
Fix disable_joins ignoring the polymorphic type condition of an as: association
A has_many :through with disable_joins: true through an as: association loaded records of other types sharing the same ID.
Install the pinned connection’s lock before pinning it
Fixes a race condition in pin_connection! where another thread could be handed the connection being pinned, which could lead to a deadlock.
Speed up String#truncate_words on long strings
Truncating a 100k character string to 10 words is now about 100 times faster, and no longer causes a spike in memory.
Four new versions benchmarked in Agents on Rails
GPT-6.2 Astra (xhigh and medium), GPT-6.2 Sol (xhigh), and DeepSeek v4.1 Flash 1017 (max) are the newest models added the list.
You can view the whole list of changes here. We had 34 contributors to the Rails codebase this past week!
Until next time!
Subscribe to get these updates mailed to you.