Get rid of unsafe variables.

This commit is contained in:
eal 2018-05-06 09:58:59 +03:00
parent 1e83727fdd
commit bfad57c7c9
5 changed files with 50 additions and 35 deletions

View file

@ -17,9 +17,10 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do
if actor_info.host in @media_removal do if actor_info.host in @media_removal do
child_object = Map.delete(object["object"], "attachment") child_object = Map.delete(object["object"], "attachment")
object = Map.put(object, "object", child_object) object = Map.put(object, "object", child_object)
end
{:ok, object} {:ok, object}
else
{:ok, object}
end
end end
@media_nsfw Keyword.get(@mrf_policy, :media_nsfw) @media_nsfw Keyword.get(@mrf_policy, :media_nsfw)
@ -32,9 +33,10 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do
child_object = Map.put(child_object, "tags", tags) child_object = Map.put(child_object, "tags", tags)
child_object = Map.put(child_object, "sensitive", true) child_object = Map.put(child_object, "sensitive", true)
object = Map.put(object, "object", child_object) object = Map.put(object, "object", child_object)
end
{:ok, object} {:ok, object}
else
{:ok, object}
end
end end
@ftl_removal Keyword.get(@mrf_policy, :federated_timeline_removal) @ftl_removal Keyword.get(@mrf_policy, :federated_timeline_removal)
@ -43,6 +45,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do
user = User.get_by_ap_id(object["actor"]) user = User.get_by_ap_id(object["actor"])
# flip to/cc relationship to make the post unlisted # flip to/cc relationship to make the post unlisted
object =
if "https://www.w3.org/ns/activitystreams#Public" in object["to"] and if "https://www.w3.org/ns/activitystreams#Public" in object["to"] and
user.follower_address in object["cc"] do user.follower_address in object["cc"] do
to = to =
@ -53,12 +56,17 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do
List.delete(object["cc"], user.follower_address) ++ List.delete(object["cc"], user.follower_address) ++
["https://www.w3.org/ns/activitystreams#Public"] ["https://www.w3.org/ns/activitystreams#Public"]
object = Map.put(object, "to", to) object
object = Map.put(object, "cc", cc) |> Map.put("to", to)
end |> Map.put("cc", cc)
else
object
end end
{:ok, object} {:ok, object}
else
{:ok, object}
end
end end
def filter(object) do def filter(object) do

View file

@ -72,8 +72,11 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|> Enum.reduce(%{}, fn data, mapping -> |> Enum.reduce(%{}, fn data, mapping ->
name = data["name"] name = data["name"]
name =
if String.starts_with?(name, ":") do if String.starts_with?(name, ":") do
name = name |> String.slice(1..-2) name = name |> String.slice(1..-2)
else
name
end end
mapping |> Map.put(name, data["icon"]["url"]) mapping |> Map.put(name, data["icon"]["url"])

View file

@ -123,8 +123,11 @@ defmodule Pleroma.Web.ActivityPub.UserView do
"limit" => "10" "limit" => "10"
} }
params =
if max_qid != nil do if max_qid != nil do
params = Map.put(params, "max_id", max_qid) Map.put(params, "max_id", max_qid)
else
params
end end
activities = ActivityPub.fetch_public_activities(params) activities = ActivityPub.fetch_public_activities(params)

View file

@ -212,11 +212,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|> Map.put("actor_id", ap_id) |> Map.put("actor_id", ap_id)
|> Map.put("whole_db", true) |> Map.put("whole_db", true)
activities =
if params["pinned"] == "true" do if params["pinned"] == "true" do
# Since Pleroma has no "pinned" posts feature, we'll just set an empty list here # Since Pleroma has no "pinned" posts feature, we'll just set an empty list here
activities = [] []
else else
activities =
ActivityPub.fetch_public_activities(params) ActivityPub.fetch_public_activities(params)
|> Enum.reverse() |> Enum.reverse()
end end

View file

@ -239,12 +239,13 @@ defmodule Pleroma.Web.WebFinger do
URI.parse(account).host URI.parse(account).host
end end
address =
case find_lrdd_template(domain) do case find_lrdd_template(domain) do
{:ok, template} -> {:ok, template} ->
address = String.replace(template, "{uri}", URI.encode(account)) String.replace(template, "{uri}", URI.encode(account))
_ -> _ ->
address = "http://#{domain}/.well-known/webfinger?resource=acct:#{account}" "http://#{domain}/.well-known/webfinger?resource=acct:#{account}"
end end
with response <- with response <-