Prevent remote access of local-only posts via /objects
Ref: fix-local-public
This commit is contained in:
parent
466568ae36
commit
fe933b9bf2
|
@ -84,7 +84,10 @@ def visible_for_user?(%{__struct__: module} = message, user)
|
||||||
when module in [Activity, Object] do
|
when module in [Activity, Object] do
|
||||||
x = [user.ap_id | User.following(user)]
|
x = [user.ap_id | User.following(user)]
|
||||||
y = [message.data["actor"]] ++ message.data["to"] ++ (message.data["cc"] || [])
|
y = [message.data["actor"]] ++ message.data["to"] ++ (message.data["cc"] || [])
|
||||||
is_public?(message) || Enum.any?(x, &(&1 in y))
|
|
||||||
|
user_is_local = user.local
|
||||||
|
federatable = not is_local_public?(message)
|
||||||
|
(is_public?(message) || Enum.any?(x, &(&1 in y))) and (user_is_local || federatable)
|
||||||
end
|
end
|
||||||
|
|
||||||
def entire_thread_visible_for_user?(%Activity{} = activity, %User{} = user) do
|
def entire_thread_visible_for_user?(%Activity{} = activity, %User{} = user) do
|
||||||
|
|
|
@ -247,6 +247,27 @@ test "returns local-only objects when authenticated", %{conn: conn} do
|
||||||
assert json_response(response, 200) == ObjectView.render("object.json", %{object: object})
|
assert json_response(response, 200) == ObjectView.render("object.json", %{object: object})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "does not return local-only objects for remote users", %{conn: conn} do
|
||||||
|
user = insert(:user)
|
||||||
|
reader = insert(:user, local: false)
|
||||||
|
|
||||||
|
{:ok, post} =
|
||||||
|
CommonAPI.post(user, %{status: "test @#{reader.nickname}", visibility: "local"})
|
||||||
|
|
||||||
|
assert Pleroma.Web.ActivityPub.Visibility.is_local_public?(post)
|
||||||
|
|
||||||
|
object = Object.normalize(post, fetch: false)
|
||||||
|
uuid = String.split(object.data["id"], "/") |> List.last()
|
||||||
|
|
||||||
|
assert response =
|
||||||
|
conn
|
||||||
|
|> assign(:user, reader)
|
||||||
|
|> put_req_header("accept", "application/activity+json")
|
||||||
|
|> get("/objects/#{uuid}")
|
||||||
|
|
||||||
|
json_response(response, 404)
|
||||||
|
end
|
||||||
|
|
||||||
test "it returns a json representation of the object with accept application/json", %{
|
test "it returns a json representation of the object with accept application/json", %{
|
||||||
conn: conn
|
conn: conn
|
||||||
} do
|
} do
|
||||||
|
|
Loading…
Reference in New Issue