Add a check for valid URI before fetching it in AP Client
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
5ac02bae5d
commit
cbf772f282
@ -17,7 +17,8 @@ defmodule Mobilizon.Federation.ActivityPub.Fetcher do
|
|||||||
def fetch(url, options \\ []) do
|
def fetch(url, options \\ []) do
|
||||||
on_behalf_of = Keyword.get(options, :on_behalf_of, Relay.get_actor())
|
on_behalf_of = Keyword.get(options, :on_behalf_of, Relay.get_actor())
|
||||||
|
|
||||||
with date <- Signature.generate_date_header(),
|
with false <- address_invalid(url),
|
||||||
|
date <- Signature.generate_date_header(),
|
||||||
headers <-
|
headers <-
|
||||||
[{:Accept, "application/activity+json"}]
|
[{:Accept, "application/activity+json"}]
|
||||||
|> maybe_date_fetch(date)
|
|> maybe_date_fetch(date)
|
||||||
@ -90,4 +91,12 @@ defmodule Mobilizon.Federation.ActivityPub.Fetcher do
|
|||||||
{:error, err}
|
{:error, err}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@spec address_invalid(String.t()) :: false | {:error, :invalid_url}
|
||||||
|
defp address_invalid(address) do
|
||||||
|
with %URI{host: host, scheme: scheme} <- URI.parse(address),
|
||||||
|
true <- is_nil(host) or is_nil(scheme) do
|
||||||
|
{:error, :invalid_url}
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user