forked from YokaiRick/akkoma
SimplePolicy: filter string Objects
This commit is contained in:
parent
3d742c3c1a
commit
c16c7fdb87
2 changed files with 26 additions and 1 deletions
|
@ -181,7 +181,7 @@ defp check_banner_removal(%{host: actor_host} = _actor_info, %{"image" => _image
|
||||||
|
|
||||||
defp check_banner_removal(_actor_info, object), do: {:ok, object}
|
defp check_banner_removal(_actor_info, object), do: {:ok, object}
|
||||||
|
|
||||||
defp check_object(%{"object" => object} = activity) when is_map(object) do
|
defp check_object(%{"object" => object} = activity) do
|
||||||
with {:ok, _object} <- filter(object) do
|
with {:ok, _object} <- filter(object) do
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
end
|
end
|
||||||
|
@ -240,6 +240,19 @@ def filter(%{"id" => actor, "type" => obj_type} = object)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def filter(object) when is_binary(object) do
|
||||||
|
uri = URI.parse(object)
|
||||||
|
|
||||||
|
with {:ok, object} <- check_accept(uri, object),
|
||||||
|
{:ok, object} <- check_reject(uri, object) do
|
||||||
|
{:ok, object}
|
||||||
|
else
|
||||||
|
{:reject, nil} -> {:reject, "[SimplePolicy]"}
|
||||||
|
{:reject, _} = e -> e
|
||||||
|
_ -> {:reject, "[SimplePolicy]"}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def filter(object), do: {:ok, object}
|
def filter(object), do: {:ok, object}
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
|
|
|
@ -272,6 +272,18 @@ test "reject Announce when object would be rejected" do
|
||||||
|
|
||||||
assert {:reject, _} = SimplePolicy.filter(announce)
|
assert {:reject, _} = SimplePolicy.filter(announce)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "reject by URI object" do
|
||||||
|
clear_config([:mrf_simple, :reject], ["blocked.tld"])
|
||||||
|
|
||||||
|
announce = %{
|
||||||
|
"type" => "Announce",
|
||||||
|
"actor" => "https://okay.tld/users/alice",
|
||||||
|
"object" => "https://blocked.tld/activities/1"
|
||||||
|
}
|
||||||
|
|
||||||
|
assert {:reject, _} = SimplePolicy.filter(announce)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "when :followers_only" do
|
describe "when :followers_only" do
|
||||||
|
|
Loading…
Reference in a new issue