diff --git a/CHANGELOG.md b/CHANGELOG.md index 93c8e4086c..a3a1fac58d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,18 @@ All notable changes to this project will be documented in this file. +## [4.6.11] - 2026-11-03 + +- Fix DoS through JSON-LD compaction (#41482 by @ClearlyClaire, [GHSA-cf49-73r7-rxj6](https://github.com/mastodon/mastodon/security/advisories/GHSA-cf49-73r7-rxj6)) +- Fix `Forwarded` header taking precedence over `X-Forwarded-For` (#41481 by @ClearlyClaire, [GHSA-qp4r-p842-mw5c](https://github.com/mastodon/mastodon/security/advisories/GHSA-qp4r-p842-mw5c)) + - If your reverse-proxy setup uses `Forwarded` instead of `X-Forwarded-For`, please make sure it ignores user-provided `X-Forwarded-For` headers. + - If you are using our provided `nginx.conf`, please consider updating it. +- Updated dependencies, in particular to address security advisories in `addressable`, `loofah`, `rack`, and `rails-html-sanitizer` + +### Changed + +- Change invites use counts to not decrease if an invited user deletes their account (#41458 by @ClearlyClaire) + ## [4.6.10] - 2026-10-29 ### Security diff --git a/Gemfile.lock b/Gemfile.lock index 3cc418c68a..bcc53c37a0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -89,7 +89,7 @@ GEM securerandom (>= 0.3) tzinfo (~> 2.0, >= 2.0.5) uri (>= 0.13.1) - addressable (2.9.0) + addressable (2.9.2) public_suffix (>= 2.0.2, < 8.0) aes_key_wrap (1.1.0) android_key_attestation (0.3.0) @@ -430,9 +430,9 @@ GEM activesupport (>= 4) railties (>= 4) request_store (~> 1.0) - loofah (2.25.2) + loofah (2.25.3) crass (~> 1.0.2) - nokogiri (>= 1.12.0) + nokogiri (>= 1.19.5) mail (2.9.1) logger mini_mime (>= 0.1.1) @@ -471,7 +471,7 @@ GEM net-smtp (0.5.1) net-protocol nio4r (2.7.5) - nokogiri (1.19.4) + nokogiri (1.19.7) mini_portile2 (~> 2.8.2) racc (~> 1.4) omniauth (2.1.4) @@ -630,7 +630,7 @@ GEM activesupport (>= 3.0.0) raabro (1.4.0) racc (1.8.1) - rack (3.2.6) + rack (3.2.8) rack-attack (6.8.0) rack (>= 1.0, < 4) rack-cors (3.0.0) @@ -674,8 +674,8 @@ GEM activesupport (>= 5.0.0) minitest nokogiri (>= 1.6) - rails-html-sanitizer (1.7.1) - loofah (~> 2.25, >= 2.25.2) + rails-html-sanitizer (1.7.2) + loofah (~> 2.25, >= 2.25.3) nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0) rails-i18n (8.1.0) i18n (>= 0.7, < 2) @@ -1104,4 +1104,4 @@ RUBY VERSION ruby 4.0.5 BUNDLED WITH - 4.0.13 + 4.0.23 diff --git a/app/models/user.rb b/app/models/user.rb index e1f1abcb68..3b96f25212 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -70,7 +70,7 @@ class User < ApplicationRecord :confirmable belongs_to :account, inverse_of: :user - belongs_to :invite, counter_cache: :uses, optional: true + belongs_to :invite, optional: true belongs_to :created_by_application, class_name: 'Doorkeeper::Application', optional: true belongs_to :role, class_name: 'UserRole', optional: true accepts_nested_attributes_for :account @@ -115,6 +115,7 @@ class User < ApplicationRecord before_validation :sanitize_role before_create :set_approved before_create :set_age_verified_at + after_create :increment_invite_uses after_commit :send_pending_devise_notifications after_create_commit :trigger_webhooks @@ -524,4 +525,8 @@ class User < ApplicationRecord def trigger_webhooks TriggerWebhookWorker.perform_async('account.created', 'Account', account_id) end + + def increment_invite_uses + invite&.increment!(:uses) + end end diff --git a/app/services/activitypub/process_collection_service.rb b/app/services/activitypub/process_collection_service.rb index 008c6fee75..26199ca59c 100644 --- a/app/services/activitypub/process_collection_service.rb +++ b/app/services/activitypub/process_collection_service.rb @@ -12,7 +12,13 @@ class ActivityPub::ProcessCollectionService < BaseService return unless @json.is_a?(Hash) begin - @json = compact(@json) if @json['signature'].is_a?(Hash) + if @json['signature'].is_a?(Hash) + check_jsonld_limits!(@json) + + @json = compact(@json) + end + + # Unsupported features can be aliased, so re-check after compaction check_jsonld_limits!(@json) rescue Mastodon::InvalidJsonLdError => e Rails.logger.debug { "JSON-LD handling for document from #{value_or_id(@json['actor'])} skipped: #{e.message}" } diff --git a/config/initializers/trusted_proxies.rb b/config/initializers/trusted_proxies.rb index 33bfddbdf1..6e1030e39e 100644 --- a/config/initializers/trusted_proxies.rb +++ b/config/initializers/trusted_proxies.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +Rack::Request.forwarded_priority = [:x_forwarded, :forwarded] + unless Rails.application.config.action_dispatch.trusted_proxies.nil? # Rack is configured with a default collection of trusted proxies # If Rails has been configured to use a specific list, configure diff --git a/dist/nginx.conf b/dist/nginx.conf index af21f931af..f40d341f75 100644 --- a/dist/nginx.conf +++ b/dist/nginx.conf @@ -128,6 +128,7 @@ server { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header Forwarded ""; proxy_set_header Proxy ""; proxy_pass http://streaming; @@ -145,6 +146,7 @@ server { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header Forwarded ""; proxy_set_header Proxy ""; proxy_pass_header Server; diff --git a/docker-compose.yml b/docker-compose.yml index 20fa584b13..46f6154ba9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -60,7 +60,7 @@ services: web: # You can uncomment the following line if you want to not use the prebuilt image, for example if you have local code changes # build: . - image: ghcr.io/glitch-soc/mastodon:v4.6.10 + image: ghcr.io/glitch-soc/mastodon:v4.6.11 restart: always env_file: .env.production command: bundle exec puma -C config/puma.rb @@ -84,7 +84,7 @@ services: # build: # dockerfile: ./streaming/Dockerfile # context: . - image: ghcr.io/glitch-soc/mastodon-streaming:v4.6.10 + image: ghcr.io/glitch-soc/mastodon-streaming:v4.6.11 restart: always env_file: .env.production command: node ./streaming/index.js @@ -103,7 +103,7 @@ services: sidekiq: # You can uncomment the following line if you want to not use the prebuilt image, for example if you have local code changes # build: . - image: ghcr.io/glitch-soc/mastodon:v4.6.10 + image: ghcr.io/glitch-soc/mastodon:v4.6.11 restart: always env_file: .env.production command: bundle exec sidekiq diff --git a/lib/mastodon/version.rb b/lib/mastodon/version.rb index 5677497685..54c508dd79 100644 --- a/lib/mastodon/version.rb +++ b/lib/mastodon/version.rb @@ -13,7 +13,7 @@ module Mastodon end def patch - 10 + 11 end def default_prerelease diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 2b5021176f..3c9f4466bb 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -25,6 +25,21 @@ RSpec.describe User do describe 'Associations' do it { is_expected.to belong_to(:account).required } it { is_expected.to have_many(:login_activities) } + it { is_expected.to belong_to(:invite).optional } + it { is_expected.to have_many(:invites).inverse_of(:user).dependent(false) } + it { is_expected.to have_one(:invite_request).inverse_of(:user).dependent(:destroy).class_name(UserInviteRequest) } + + describe 'invite' do + let(:invite) { Fabricate(:invite) } + + it 'increments invite uses on creation but does not decrement it on deletion' do + expect { Fabricate(:user, email: 'alice@example.com', invite: invite) } + .to change { invite.reload.uses }.by(1) + + expect { described_class.find_by(email: 'alice@example.com').destroy } + .to_not(change { invite.reload.uses }) + end + end end describe 'Validations' do diff --git a/spec/system/auth/registrations_spec.rb b/spec/system/auth/registrations_spec.rb index acc4d89975..35d72de51a 100644 --- a/spec/system/auth/registrations_spec.rb +++ b/spec/system/auth/registrations_spec.rb @@ -122,6 +122,7 @@ RSpec.describe 'Auth Registration' do expect { fill_in_and_submit_form(apply: false) } .to change(User, :count).by(1) + .and change { invite.reload.uses }.by(1) expect(User.find_by(email: 'test@example.com')) .to have_attributes(approved: true)