fix(mrf): match domain rules literally
Escape the domain so `.` only matches a dot, and use an optional group for the `*.` prefix, which matches the same hosts without exponential backtracking. Bad entries now match nothing instead of raising on every check.
This commit is contained in:
parent
3e9dc477c9
commit
7e157d8cc9
3 changed files with 27 additions and 20 deletions
|
|
@ -148,14 +148,13 @@ defmodule Pleroma.Web.ActivityPub.MRF do
|
|||
@spec subdomains_regex([String.t()]) :: [Regex.t()]
|
||||
def subdomains_regex(domains) when is_list(domains) do
|
||||
for domain <- domains do
|
||||
try do
|
||||
target = String.replace(domain, "*.", "(.*\\.)*")
|
||||
~r<^#{target}$>i
|
||||
rescue
|
||||
e ->
|
||||
Logger.error("MRF: Invalid subdomain Regex: #{domain}")
|
||||
reraise e, __STACKTRACE__
|
||||
end
|
||||
{prefix, rest} =
|
||||
case domain do
|
||||
"*." <> rest -> {"(.*\\.)?", rest}
|
||||
_ -> {"", domain}
|
||||
end
|
||||
|
||||
~r<^#{prefix}#{Regex.escape(rest)}$>i
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue