Merge pull request 'MRF: match domain rules literally' (#8046) from lambadalambda/pleroma:fix/mrf-domain-regex-escape into develop

Reviewed-on: https://git.pleroma.social/pleroma/pleroma/pulls/8046
This commit is contained in:
lain 2026-10-31 16:18:35 +00:00
commit 0157ade4d3
3 changed files with 27 additions and 20 deletions

View file

@ -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