mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-22 14:45:16 +00:00
Fix obfuscation of short domains
Fixes https://akkoma.dev/AkkomaGang/akkoma/issues/645
This commit is contained in:
parent
6fb91d79f3
commit
e47c50666d
|
@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
- Documentation issue in which a non-existing nginx file was referenced
|
- Documentation issue in which a non-existing nginx file was referenced
|
||||||
- Issue where a bad inbox URL could break federation
|
- Issue where a bad inbox URL could break federation
|
||||||
- Issue where hashtag rel values would be scrubbed
|
- Issue where hashtag rel values would be scrubbed
|
||||||
|
- Issue where short domains listed in `transparency_obfuscate_domains` were not actually obfuscated
|
||||||
|
|
||||||
## 2023.08
|
## 2023.08
|
||||||
|
|
||||||
|
|
|
@ -314,6 +314,20 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do
|
||||||
def filter(object), do: {:ok, object}
|
def filter(object), do: {:ok, object}
|
||||||
|
|
||||||
defp obfuscate(string) when is_binary(string) do
|
defp obfuscate(string) when is_binary(string) do
|
||||||
|
# Want to strip at least two neighbouring chars
|
||||||
|
# to ensure at least one non-dot char is in the obfuscation area
|
||||||
|
stripped = String.length(string) - 6
|
||||||
|
|
||||||
|
{keepstart, keepend} =
|
||||||
|
if stripped > 1 do
|
||||||
|
{3, 3}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
2 - div(1 - stripped, 2),
|
||||||
|
2 + div(stripped, 2)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
string
|
string
|
||||||
|> to_charlist()
|
|> to_charlist()
|
||||||
|> Enum.with_index()
|
|> Enum.with_index()
|
||||||
|
@ -322,7 +336,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicy do
|
||||||
?.
|
?.
|
||||||
|
|
||||||
{char, index} ->
|
{char, index} ->
|
||||||
if 3 <= index && index < String.length(string) - 3, do: ?*, else: char
|
if keepstart <= index && index < String.length(string) - keepend, do: ?*, else: char
|
||||||
end)
|
end)
|
||||||
|> to_string()
|
|> to_string()
|
||||||
end
|
end
|
||||||
|
|
|
@ -283,7 +283,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
||||||
|
|
||||||
assert {:ok,
|
assert {:ok,
|
||||||
%{
|
%{
|
||||||
mrf_simple: %{reject: ["rem***.*****nce", "a.b"]},
|
mrf_simple: %{reject: ["rem***.*****nce", "*.b"]},
|
||||||
mrf_simple_info: %{reject: %{"rem***.*****nce" => %{}}}
|
mrf_simple_info: %{reject: %{"rem***.*****nce" => %{}}}
|
||||||
}} = SimplePolicy.describe()
|
}} = SimplePolicy.describe()
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue