Skip to content

Commit 54fc6f8

Browse files
ClearlyClaireGargron
authored andcommitted
Prevent posting toots with media attachments from someone else (mastodon#9921)
1 parent 1113823 commit 54fc6f8

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

app/services/post_status_service.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def validate_media!
9393

9494
raise Mastodon::ValidationError, I18n.t('media_attachments.validations.too_many') if @options[:media_ids].size > 4
9595

96-
@media = MediaAttachment.where(status_id: nil).where(id: @options[:media_ids].take(4).map(&:to_i))
96+
@media = @account.media_attachments.where(status_id: nil).where(id: @options[:media_ids].take(4).map(&:to_i))
9797

9898
raise Mastodon::ValidationError, I18n.t('media_attachments.validations.images_and_video') if @media.size > 1 && @media.find(&:video?)
9999
end

spec/services/post_status_service_spec.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167

168168
it 'attaches the given media to the created status' do
169169
account = Fabricate(:account)
170-
media = Fabricate(:media_attachment)
170+
media = Fabricate(:media_attachment, account: account)
171171

172172
status = subject.call(
173173
account,
@@ -178,6 +178,19 @@
178178
expect(media.reload.status).to eq status
179179
end
180180

181+
it 'does not attach media from another account to the created status' do
182+
account = Fabricate(:account)
183+
media = Fabricate(:media_attachment, account: Fabricate(:account))
184+
185+
status = subject.call(
186+
account,
187+
text: "test status update",
188+
media_ids: [media.id],
189+
)
190+
191+
expect(media.reload.status).to eq nil
192+
end
193+
181194
it 'does not allow attaching more than 4 files' do
182195
account = Fabricate(:account)
183196

0 commit comments

Comments
 (0)