Skip to content

Commit

Permalink
Merge branch 'master' into long_emoji
Browse files Browse the repository at this point in the history
  • Loading branch information
maa123 committed Sep 21, 2023
2 parents 2707ee1 + a0f356e commit fe71b12
Show file tree
Hide file tree
Showing 24 changed files with 147 additions and 93 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/build-container-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
platforms:
required: true
type: string
cache:
type: boolean
default: true
use_native_arm64_builder:
type: boolean
push_to_images:
Expand Down Expand Up @@ -85,5 +88,5 @@ jobs:
push: ${{ inputs.push_to_images != '' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
cache-from: ${{ inputs.cache && 'type=gha' || '' }}
cache-to: ${{ inputs.cache && 'type=gha,mode=max' || '' }}
2 changes: 2 additions & 0 deletions .github/workflows/build-releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:
push_to_images: |
tootsuite/mastodon
ghcr.io/mastodon/mastodon
# Do not use cache when building releases, so apt update is always ran and the release always contain the latest packages
cache: false
# Only tag with latest when ran against the latest stable branch
# This needs to be updated after each minor version release
flavor: |
Expand Down
41 changes: 0 additions & 41 deletions .github/workflows/lint-ruby.yml

This file was deleted.

22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,28 @@ Changelog

All notable changes to this project will be documented in this file.

## [4.1.9] - 2023-09-20

### Fixed

- Fix post translation erroring out ([ClearlyClaire](https://github.com/mastodon/mastodon/pull/26990))

## [4.1.8] - 2023-09-19

### Fixed

- Fix post edits not being forwarded as expected ([ClearlyClaire](https://github.com/mastodon/mastodon/pull/26936))
- Fix moderator rights inconsistencies ([ClearlyClaire](https://github.com/mastodon/mastodon/pull/26729))
- Fix crash when encountering invalid URL ([ClearlyClaire](https://github.com/mastodon/mastodon/pull/26814))
- Fix cached posts including stale stats ([ClearlyClaire](https://github.com/mastodon/mastodon/pull/26409))
- Fix uploading of video files for which `ffprobe` reports `0/0` average framerate ([NicolaiSoeborg](https://github.com/mastodon/mastodon/pull/26500))
- Fix unexpected audio stream transcoding when uploaded video is eligible to passthrough ([yufushiro](https://github.com/mastodon/mastodon/pull/26608))

### Security

- Fix missing HTML sanitization in translation API (CVE-2023-42452)
- Fix incorrect domain name normalization (CVE-2023-42451)

## [4.1.7] - 2023-09-05

### Changed
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ COPY Gemfile* package.json yarn.lock /opt/mastodon/

# hadolint ignore=DL3008
RUN apt-get update && \
apt-get -yq dist-upgrade && \
apt-get install -y --no-install-recommends build-essential \
ca-certificates \
git \
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion app/lib/activitypub/activity/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ def update_status

return if @status.nil?

ActivityPub::ProcessStatusUpdateService.new.call(@status, @object, request_id: @options[:request_id])
ActivityPub::ProcessStatusUpdateService.new.call(@status, @json, @object, request_id: @options[:request_id])
end
end
9 changes: 9 additions & 0 deletions app/lib/admin/account_statuses_filter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class Admin::AccountStatusesFilter < AccountStatusesFilter
private

def blocked?
false
end
end
8 changes: 4 additions & 4 deletions app/lib/tag_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ class TagManager
include RoutingHelper

def web_domain?(domain)
domain.nil? || domain.gsub(/[\/]/, '').casecmp(Rails.configuration.x.web_domain).zero?
domain.nil? || domain.delete_suffix('/').casecmp(Rails.configuration.x.web_domain).zero?
end

def local_domain?(domain)
domain.nil? || domain.gsub(/[\/]/, '').casecmp(Rails.configuration.x.local_domain).zero?
domain.nil? || domain.delete_suffix('/').casecmp(Rails.configuration.x.local_domain).zero?
end

def normalize_domain(domain)
return if domain.nil?

uri = Addressable::URI.new
uri.host = domain.gsub(/[\/]/, '')
uri.host = domain.delete_suffix('/')
uri.normalized_host
end

Expand All @@ -28,7 +28,7 @@ def local_url?(url)
domain = uri.host + (uri.port ? ":#{uri.port}" : '')

TagManager.instance.web_domain?(domain)
rescue Addressable::URI::InvalidURIError
rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError
false
end
end
2 changes: 1 addition & 1 deletion app/lib/translation_service/deepl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def transform_response(str)

raise UnexpectedResponseError unless json.is_a?(Hash)

Translation.new(text: json.dig('translations', 0, 'text'), detected_source_language: json.dig('translations', 0, 'detected_source_language')&.downcase, provider: 'DeepL.com')
Translation.new(text: Sanitize.fragment(json.dig('translations', 0, 'text'), Sanitize::Config::MASTODON_STRICT), detected_source_language: json.dig('translations', 0, 'detected_source_language')&.downcase, provider: 'DeepL.com')
rescue Oj::ParseError
raise UnexpectedResponseError
end
Expand Down
2 changes: 1 addition & 1 deletion app/lib/translation_service/libre_translate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def transform_response(str, source_language)

raise UnexpectedResponseError unless json.is_a?(Hash)

Translation.new(text: json['translatedText'], detected_source_language: source_language, provider: 'LibreTranslate')
Translation.new(text: Sanitize.fragment(json['translatedText'], Sanitize::Config::MASTODON_STRICT), detected_source_language: source_language, provider: 'LibreTranslate')
rescue Oj::ParseError
raise UnexpectedResponseError
end
Expand Down
3 changes: 3 additions & 0 deletions app/lib/video_metadata_extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ def parse_metadata
@height = video_stream[:height]
@frame_rate = video_stream[:avg_frame_rate] == '0/0' ? nil : Rational(video_stream[:avg_frame_rate])
@r_frame_rate = video_stream[:r_frame_rate] == '0/0' ? nil : Rational(video_stream[:r_frame_rate])
# For some video streams the frame_rate reported by `ffprobe` will be 0/0, but for these streams we
# should use `r_frame_rate` instead. Video screencast generated by Gnome Screencast have this issue.
@frame_rate ||= @r_frame_rate
end

if (audio_stream = audio_streams.first)
Expand Down
2 changes: 1 addition & 1 deletion app/models/admin/status_batch_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,6 @@ def report_params
end

def allowed_status_ids
AccountStatusesFilter.new(@report.target_account, current_account).results.with_discarded.where(id: status_ids).pluck(:id)
Admin::AccountStatusesFilter.new(@report.target_account, current_account).results.with_discarded.where(id: status_ids).pluck(:id)
end
end
12 changes: 12 additions & 0 deletions app/models/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -354,13 +354,25 @@ def reload_stale_associations!(cached_items)

account_ids.uniq!

status_ids = cached_items.map { |item| item.reblog? ? item.reblog_of_id : item.id }.uniq

return if account_ids.empty?

accounts = Account.where(id: account_ids).includes(:account_stat, :user).index_by(&:id)

status_stats = StatusStat.where(status_id: status_ids).index_by(&:status_id)

cached_items.each do |item|
item.account = accounts[item.account_id]
item.reblog.account = accounts[item.reblog.account_id] if item.reblog?

if item.reblog?
status_stat = status_stats[item.reblog.id]
item.reblog.status_stat = status_stat if status_stat.present?
else
status_stat = status_stats[item.id]
item.status_stat = status_stat if status_stat.present?
end
end
end

Expand Down
8 changes: 7 additions & 1 deletion app/policies/admin/status_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def index?
end

def show?
role.can?(:manage_reports, :manage_users) && (record.public_visibility? || record.unlisted_visibility? || record.reported?)
role.can?(:manage_reports, :manage_users) && (record.public_visibility? || record.unlisted_visibility? || record.reported? || viewable_through_normal_policy?)
end

def destroy?
Expand All @@ -26,4 +26,10 @@ def update?
def review?
role.can?(:manage_taxonomies)
end

private

def viewable_through_normal_policy?
StatusPolicy.new(current_account, record, @preloaded_relations).show?
end
end
2 changes: 1 addition & 1 deletion app/services/activitypub/fetch_remote_poll_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ def call(poll, on_behalf_of = nil)

return unless supported_context?(json)

ActivityPub::ProcessStatusUpdateService.new.call(poll.status, json)
ActivityPub::ProcessStatusUpdateService.new.call(poll.status, json, json)
end
end
7 changes: 4 additions & 3 deletions app/services/activitypub/process_status_update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ class ActivityPub::ProcessStatusUpdateService < BaseService
include Redisable
include Lockable

def call(status, json, request_id: nil)
def call(status, activity_json, object_json, request_id: nil)
raise ArgumentError, 'Status has unsaved changes' if status.changed?

@json = json
@activity_json = activity_json
@json = object_json
@status_parser = ActivityPub::Parser::StatusParser.new(@json)
@uri = @status_parser.uri
@status = status
Expand Down Expand Up @@ -308,6 +309,6 @@ def forward_activity!
end

def forwarder
@forwarder ||= ActivityPub::Forwarder.new(@account, @json, @status)
@forwarder ||= ActivityPub::Forwarder.new(@account, @activity_json, @status)
end
end
4 changes: 3 additions & 1 deletion app/services/translate_status_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ def call(status, target_language)
@content = status_content_format(@status)
@target_language = target_language

Rails.cache.fetch("translations/#{@status.language}/#{@target_language}/#{content_hash}", expires_in: CACHE_TTL) { translation_backend.translate(@content, @status.language, @target_language) }
Rails.cache.fetch("translations:v2/#{@status.language}/#{@target_language}/#{content_hash}", expires_in: CACHE_TTL) do
translation_backend.translate(@content, @status.language, @target_language)
end
end

private
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ services:

web:
build: .
image: ghcr.io/mastodon/mastodon:v4.1.7
image: ghcr.io/mastodon/mastodon:v4.1.9
restart: always
env_file: .env.production
command: bash -c "rm -f /mastodon/tmp/pids/server.pid; bundle exec rails s -p 3000"
Expand All @@ -77,7 +77,7 @@ services:

streaming:
build: .
image: ghcr.io/mastodon/mastodon:v4.1.7
image: ghcr.io/mastodon/mastodon:v4.1.9
restart: always
env_file: .env.production
command: node ./streaming
Expand All @@ -95,7 +95,7 @@ services:

sidekiq:
build: .
image: ghcr.io/mastodon/mastodon:v4.1.7
image: ghcr.io/mastodon/mastodon:v4.1.9
restart: always
env_file: .env.production
command: bundle exec sidekiq
Expand Down
2 changes: 1 addition & 1 deletion lib/mastodon/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def minor
end

def patch
7
9
end

def flags
Expand Down
14 changes: 8 additions & 6 deletions lib/paperclip/transcoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ def make
@output_options['f'] = 'image2'
@output_options['vframes'] = 1
when 'mp4'
@output_options['acodec'] = 'aac'
@output_options['strict'] = 'experimental'

if high_vfr?(metadata) && !eligible_to_passthrough?(metadata)
@output_options['vsync'] = 'vfr'
@output_options['r'] = @vfr_threshold
unless eligible_to_passthrough?(metadata)
@output_options['acodec'] = 'aac'
@output_options['strict'] = 'experimental'

if high_vfr?(metadata)
@output_options['vsync'] = 'vfr'
@output_options['r'] = @vfr_threshold
end
end
end

Expand Down
20 changes: 16 additions & 4 deletions spec/controllers/admin/statuses_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,36 @@
end

describe 'POST #batch' do
before do
post :batch, params: { account_id: account.id, action => '', admin_status_batch_action: { status_ids: status_ids } }
end
subject { post :batch, params: { :account_id => account.id, action => '', :admin_status_batch_action => { status_ids: status_ids } } }

let(:status_ids) { [media_attached_status.id] }

context 'when action is report' do
shared_examples 'when action is report' do
let(:action) { 'report' }

it 'creates a report' do
subject

report = Report.last
expect(report.target_account_id).to eq account.id
expect(report.status_ids).to eq status_ids
end

it 'redirects to report page' do
subject

expect(response).to redirect_to(admin_report_path(Report.last.id))
end
end

it_behaves_like 'when action is report'

context 'when the moderator is blocked by the author' do
before do
account.block!(user.account)
end

it_behaves_like 'when action is report'
end
end
end
Loading

0 comments on commit fe71b12

Please sign in to comment.