Merge commit '24cd1c875a1ac393e587421726394d5692ff5496' into glitch-soc/stable-4.7

This commit is contained in:
Claire committed 2026-11-03 16:30:06 +01:00
commit e6be86cd9e
14 files changed
+94 -26

No files matched your search

+15
View File
@@ -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
+7 -7
View File
@@ -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)
@@ -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)
@@ -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)
@@ -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)
@@ -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?
@@ -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
+7 -1
View File
@@ -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
+6 -1
View File
@@ -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
@@ -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}" }
+2
View File
@@ -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
+2
View File
@@ -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;
+3 -3
View File
@@ -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/glitch-soc/mastodon:v4.7.4
image: ghcr.io/glitch-soc/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/glitch-soc/mastodon-streaming:v4.7.4
image: ghcr.io/glitch-soc/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/glitch-soc/mastodon:v4.7.4
image: ghcr.io/glitch-soc/mastodon:v4.7.5
restart: always
env_file: .env.production
command: bundle exec sidekiq
+1 -1
View File
@@ -13,7 +13,7 @@ module Mastodon
end
def patch
4
5
end
def default_prerelease
@@ -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
+15
View File
@@ -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
+1
View File
@@ -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)