forked from AkkomaGang/akkoma
fix validate_url for private ip
This commit is contained in:
parent
d80859731e
commit
0276cf5a02
1 changed files with 12 additions and 4 deletions
|
@ -8,12 +8,20 @@ defmodule Pleroma.Web.RichMedia.Helpers do
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.Web.RichMedia.Parser
|
alias Pleroma.Web.RichMedia.Parser
|
||||||
|
|
||||||
|
@private_ip_regexp ~r/(127\.)|(10\.\d+\.\d+.\d+)|(192\.168\.)
|
||||||
|
|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(localhost)/
|
||||||
|
|
||||||
defp validate_page_url(page_url) when is_binary(page_url) do
|
defp validate_page_url(page_url) when is_binary(page_url) do
|
||||||
validate_tld = Application.get_env(:auto_linker, :opts)[:validate_tld]
|
validate_tld = Application.get_env(:auto_linker, :opts)[:validate_tld]
|
||||||
|
|
||||||
if AutoLinker.Parser.url?(page_url, scheme: true, validate_tld: validate_tld) do
|
cond do
|
||||||
|
Regex.match?(@private_ip_regexp, page_url) ->
|
||||||
|
:error
|
||||||
|
|
||||||
|
AutoLinker.Parser.url?(page_url, scheme: true, validate_tld: validate_tld) ->
|
||||||
URI.parse(page_url) |> validate_page_url
|
URI.parse(page_url) |> validate_page_url
|
||||||
else
|
|
||||||
|
true ->
|
||||||
:error
|
:error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue