In Mastodon media can only be used by owners and only be associated with
a single post. We currently allow media to be associated with several
posts and until now did not limit their usage in posts to media owners.
However, media update and GET lookup was already limited to owners.
(In accordance with allowing media reuse, we also still allow GET
lookups of media already used in a post unlike Mastodon)
Allowing reuse isn’t problematic per se, but allowing use by non-owners
can be problematic if media ids of private-scoped posts can be guessed
since creating a new post with this media id will reveal the uploaded
file content and alt text.
Given media ids are currently just part of a sequentieal series shared
with some other objects, guessing media ids is with some persistence
indeed feasible.
E.g. sampline some public media ids from a real-world
instance with 112 total and 61 monthly-active users:
17.465.096 at t0
17.472.673 at t1 = t0 + 4h
17.473.248 at t2 = t1 + 20min
This gives about 30 new ids per minute of which most won't be
local media but remote and local posts, poll answers etc.
Assuming the default ratelimit of 15 post actions per 10s, scraping all
media for the 4h interval takes about 84 minutes and scraping the 20min
range mere 6.3 minutes. (Until the preceding commit, post updates were
not rate limited at all, allowing even faster scraping.)
If an attacker can infer (e.g. via reply to a follower-only post not
accessbile to the attacker) some sensitive information was uploaded
during a specific time interval and has some pointers regarding the
nature of the information, identifying the specific upload out of all
scraped media for this timerange is not impossible.
Thus restrict media usage to owners.
Checking ownership just in ActivitDraft would already be sufficient,
since when a scheduled status actually gets posted it goes through
ActivityDraft again, but would erroneously return a success status
when scheduling an illegal post.
Independently discovered and fixed by mint in Pleroma
1afde067b1
68 lines
2.1 KiB
Elixir
68 lines
2.1 KiB
Elixir
# Pleroma: A lightweight social networking server
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
defmodule Pleroma.Web.MastodonAPI.ScheduledActivityViewTest do
|
|
use Pleroma.DataCase, async: true
|
|
alias Pleroma.ScheduledActivity
|
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
|
alias Pleroma.Web.CommonAPI
|
|
alias Pleroma.Web.CommonAPI.Utils
|
|
alias Pleroma.Web.MastodonAPI.ScheduledActivityView
|
|
alias Pleroma.Web.MastodonAPI.StatusView
|
|
import Pleroma.Factory
|
|
|
|
test "A scheduled activity with a media attachment" do
|
|
user = insert(:user)
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "hi"})
|
|
|
|
scheduled_at =
|
|
NaiveDateTime.utc_now()
|
|
|> NaiveDateTime.add(:timer.minutes(10), :millisecond)
|
|
|> NaiveDateTime.to_iso8601()
|
|
|
|
file = %Plug.Upload{
|
|
content_type: "image/jpeg",
|
|
path: Path.absname("test/fixtures/image.jpg"),
|
|
filename: "an_image.jpg"
|
|
}
|
|
|
|
{:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)
|
|
|
|
attrs = %{
|
|
params: %{
|
|
"media_ids" => [upload.id],
|
|
"status" => "hi",
|
|
"sensitive" => true,
|
|
"spoiler_text" => "spoiler",
|
|
"visibility" => "unlisted",
|
|
"in_reply_to_id" => to_string(activity.id)
|
|
},
|
|
scheduled_at: scheduled_at
|
|
}
|
|
|
|
{:ok, scheduled_activity} = ScheduledActivity.create(user, attrs)
|
|
result = ScheduledActivityView.render("show.json", %{scheduled_activity: scheduled_activity})
|
|
|
|
expected = %{
|
|
id: to_string(scheduled_activity.id),
|
|
media_attachments:
|
|
Utils.attachments_from_ids(user, %{media_ids: [upload.id]})
|
|
|> Enum.map(&StatusView.render("attachment.json", %{attachment: &1})),
|
|
params: %{
|
|
in_reply_to_id: to_string(activity.id),
|
|
media_ids: [upload.id],
|
|
poll: nil,
|
|
scheduled_at: nil,
|
|
sensitive: true,
|
|
spoiler_text: "spoiler",
|
|
text: "hi",
|
|
visibility: "unlisted",
|
|
expires_in: nil
|
|
},
|
|
scheduled_at: Utils.to_masto_date(scheduled_activity.scheduled_at)
|
|
}
|
|
|
|
assert expected == result
|
|
end
|
|
end
|