From 7d006dbd6d1c3317d6c7a6ef8fb49816d04ea580 Mon Sep 17 00:00:00 2001 From: Claire Date: Tue, 3 Nov 2026 11:07:35 +0100 Subject: [PATCH 1/9] Update dependency `addressable` --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 87783f6391..8296a7d774 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) From cee54041c8f0b49381b7c895bda2f2429de1d92c Mon Sep 17 00:00:00 2001 From: Claire Date: Tue, 3 Nov 2026 11:07:41 +0100 Subject: [PATCH 2/9] Update dependency `loofah` --- Gemfile.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 8296a7d774..3d243b0a58 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -428,9 +428,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) @@ -469,7 +469,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) From 2ed4a9bbaab9b3e655b7fd9401e73881093e0326 Mon Sep 17 00:00:00 2001 From: Claire Date: Tue, 3 Nov 2026 11:07:46 +0100 Subject: [PATCH 3/9] Update dependency `rack` --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 3d243b0a58..be5e9c0871 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -625,7 +625,7 @@ GEM activesupport (>= 3.0.0) raabro (1.5.0) racc (1.8.1) - rack (3.2.7) + rack (3.2.8) rack-attack (6.8.0) rack (>= 1.0, < 4) rack-cors (3.0.0) From 6d48e2a57c5ba7421d949f60be2222754a2d6a0c Mon Sep 17 00:00:00 2001 From: Claire Date: Tue, 3 Nov 2026 11:07:56 +0100 Subject: [PATCH 4/9] Update dependency `rails-html-sanitizer` --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index be5e9c0871..72ac19242a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -669,8 +669,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) From 804ed3c41a7c494839e4c39a9e98d967e551019f Mon Sep 17 00:00:00 2001 From: Claire Date: Tue, 3 Nov 2026 11:22:17 +0100 Subject: [PATCH 5/9] Fix invite uses decreasing on invitee account deletion (#41458) --- app/models/user.rb | 7 ++++++- spec/models/user_spec.rb | 15 +++++++++++++++ spec/system/auth/registrations_spec.rb | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index eef021dbb2..7036c512a2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -71,7 +71,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 @@ -116,6 +116,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 @@ -525,4 +526,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/spec/models/user_spec.rb b/spec/models/user_spec.rb index f082767e5d..75323dc2b0 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) From 88c6c937d8100be1d511e9a397f96a4b4f2ec618 Mon Sep 17 00:00:00 2001 From: Claire Date: Tue, 3 Nov 2026 14:02:48 +0000 Subject: [PATCH 6/9] =?UTF-8?q?Fix=20=E2=80=9CForwarded=E2=80=9D=20header?= =?UTF-8?q?=20being=20used=20inappropriately=20(#41481)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/initializers/trusted_proxies.rb | 2 ++ dist/nginx.conf | 2 ++ 2 files changed, 4 insertions(+) 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; From aeb73fa842bee6e39dd1ad6b6d374ba983c15e03 Mon Sep 17 00:00:00 2001 From: Claire Date: Tue, 3 Nov 2026 14:06:27 +0000 Subject: [PATCH 7/9] Fix ActivityPub node count check (#41482) --- app/services/activitypub/process_activity_service.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/services/activitypub/process_activity_service.rb b/app/services/activitypub/process_activity_service.rb index ec62d10c50..31554b3d14 100644 --- a/app/services/activitypub/process_activity_service.rb +++ b/app/services/activitypub/process_activity_service.rb @@ -21,7 +21,13 @@ class ActivityPub::ProcessActivityService < BaseService # Doing JSON-LD compaction early ensures we know what we are working with, and avoids # issues like attacks involving swapping external context documents between processing steps. 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}" } From 1e1852ec1f56f068f2d18b3a255647b147913d7c Mon Sep 17 00:00:00 2001 From: Claire Date: Tue, 3 Nov 2026 15:59:40 +0100 Subject: [PATCH 8/9] Merge commit from fork Signed-off-by: Claire Co-authored-by: ccsimplyspolit --- app/controllers/auth/sessions_controller.rb | 4 +++ .../sign_in_token_authentication_concern.rb | 30 +++++++++++++------ app/models/concerns/user/sign_in_token.rb | 8 ++++- .../auth/sessions_controller_spec.rb | 6 ++-- 4 files changed, 35 insertions(+), 13 deletions(-) diff --git a/app/controllers/auth/sessions_controller.rb b/app/controllers/auth/sessions_controller.rb index 3bc8b8143b..45bf56a28f 100644 --- a/app/controllers/auth/sessions_controller.rb +++ b/app/controllers/auth/sessions_controller.rb @@ -170,6 +170,10 @@ class Auth::SessionsController < Devise::SessionsController ) ) + # No need to send a mail for failure to log in with a sign-in token, as that goes throug a mail + # as well + return if security_measure == :sign_in_token + # Only send a notification email every hour at most return if redis.set("2fa_failure_notification:#{user.id}", '1', ex: 1.hour, get: true).present? diff --git a/app/controllers/concerns/auth/sign_in_token_authentication_concern.rb b/app/controllers/concerns/auth/sign_in_token_authentication_concern.rb index cdef5031d9..abb55d67e3 100644 --- a/app/controllers/concerns/auth/sign_in_token_authentication_concern.rb +++ b/app/controllers/concerns/auth/sign_in_token_authentication_concern.rb @@ -12,22 +12,34 @@ module Auth::SignInTokenAuthenticationConcern end def authenticate_with_sign_in_token - user = self.resource = find_user + if user_params[:email].present? + user = self.resource = find_user_from_params + prompt_for_sign_in_token(user) if user&.valid_password?(user_params[:password]) + elsif session[:attempt_user_id] + user = self.resource = User.find_by(id: session[:attempt_user_id]) + return if user.nil? - if params.key?(:sign_in_token_resend) && session[:attempt_user_id] - prompt_for_sign_in_token(user, resend: true) - elsif user_params[:sign_in_token_attempt].present? && session[:attempt_user_id] - authenticate_with_sign_in_token_attempt(user) - elsif user.present? && user.valid_password?(user_params[:password]) - prompt_for_sign_in_token(user) + if session[:attempt_user_updated_at] != user.updated_at.to_s + restart_session + elsif params.key?(:sign_in_token_resend) + prompt_for_sign_in_token(user, resend: true) + elsif user_params[:sign_in_token_attempt].present? + authenticate_with_sign_in_token_attempt(user) + end end end def authenticate_with_sign_in_token_attempt(user) + if check_second_factor_rate_limits(user) + flash.now[:alert] = I18n.t('users.rate_limited') + return prompt_for_sign_in_token(user) + end + if user.valid_sign_in_token?(user_params[:sign_in_token_attempt]) - clear_attempt_from_session - sign_in(user) + user.clear_sign_in_token! + on_authentication_success(user, :sign_in_token) else + on_authentication_failure(user, :sign_in_token, :invalid_sign_in_token) flash.now[:alert] = I18n.t('users.invalid_sign_in_token') prompt_for_sign_in_token(user) end diff --git a/app/models/concerns/user/sign_in_token.rb b/app/models/concerns/user/sign_in_token.rb index 9ac5a17e61..754ee3df9d 100644 --- a/app/models/concerns/user/sign_in_token.rb +++ b/app/models/concerns/user/sign_in_token.rb @@ -24,7 +24,7 @@ module User::SignInToken end def valid_sign_in_token?(token) - Devise.secure_compare(sign_in_token, token) + !sign_in_token_expired? && Devise.secure_compare(sign_in_token, token) end def sign_in_token_expired? @@ -36,6 +36,12 @@ module User::SignInToken self.sign_in_token_sent_at = Time.now.utc end + def clear_sign_in_token! + self.sign_in_token = nil + self.sign_in_token_sent_at = nil + save! + end + def disable_sign_in_token! self.sign_in_token = nil self.sign_in_token_sent_at = nil diff --git a/spec/controllers/auth/sessions_controller_spec.rb b/spec/controllers/auth/sessions_controller_spec.rb index 55b46ad7b2..7ee8e8987a 100644 --- a/spec/controllers/auth/sessions_controller_spec.rb +++ b/spec/controllers/auth/sessions_controller_spec.rb @@ -476,7 +476,7 @@ RSpec.describe Auth::SessionsController do before do user.generate_sign_in_token user.save - post :create, params: { user: { sign_in_token_attempt: user.sign_in_token } }, session: { attempt_user_id: user.id } + post :create, params: { user: { sign_in_token_attempt: user.sign_in_token } }, session: { attempt_user_id: user.id, attempt_user_updated_at: user.updated_at.to_s } end it 'redirects to home' do @@ -490,7 +490,7 @@ RSpec.describe Auth::SessionsController do context 'when using an invalid sign in token' do before do - post :create, params: { user: { sign_in_token_attempt: 'wrongotp' } }, session: { attempt_user_id: user.id } + post :create, params: { user: { sign_in_token_attempt: 'wrongotp' } }, session: { attempt_user_id: user.id, attempt_user_updated_at: user.updated_at.to_s } end it 'shows a login error' do @@ -504,7 +504,7 @@ RSpec.describe Auth::SessionsController do context 'when requesting a new sign in token' do subject do - post :create, params: { sign_in_token_resend: '', user: { sign_in_token_attempt: '' } }, session: { attempt_user_id: user.id } + post :create, params: { sign_in_token_resend: '', user: { sign_in_token_attempt: '' } }, session: { attempt_user_id: user.id, attempt_user_updated_at: user.updated_at.to_s } end before do From 24cd1c875a1ac393e587421726394d5692ff5496 Mon Sep 17 00:00:00 2001 From: Claire Date: Tue, 3 Nov 2026 16:01:18 +0100 Subject: [PATCH 9/9] Bump version to v4.7.5 --- CHANGELOG.md | 15 +++++++++++++++ docker-compose.yml | 6 +++--- lib/mastodon/version.rb | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b4c45225b..c24a1a6c99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,21 @@ All notable changes to this project will be documented in this file. +## [4.7.5] - 2026-11-03 + +### Security + +- Fix password authentication bypass for inactive accounts ([GHSA-3xjw-gv43-3w62](https://github.com/mastodon/mastodon/security/advisories/GHSA-3xjw-gv43-3w62)) +- 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.7.4] - 2026-10-29 ### Security diff --git a/docker-compose.yml b/docker-compose.yml index 9ea6577763..8cf4724169 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -59,7 +59,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/mastodon/mastodon:v4.7.4 + image: ghcr.io/mastodon/mastodon:v4.7.5 restart: always env_file: .env.production command: bundle exec puma -C config/puma.rb @@ -83,7 +83,7 @@ services: # build: # dockerfile: ./streaming/Dockerfile # context: . - image: ghcr.io/mastodon/mastodon-streaming:v4.7.4 + image: ghcr.io/mastodon/mastodon-streaming:v4.7.5 restart: always env_file: .env.production command: node ./streaming/index.js @@ -102,7 +102,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/mastodon/mastodon:v4.7.4 + image: ghcr.io/mastodon/mastodon:v4.7.5 restart: always env_file: .env.production command: bundle exec sidekiq diff --git a/lib/mastodon/version.rb b/lib/mastodon/version.rb index 5a489917b1..66a781f25e 100644 --- a/lib/mastodon/version.rb +++ b/lib/mastodon/version.rb @@ -13,7 +13,7 @@ module Mastodon end def patch - 4 + 5 end def default_prerelease