Enforce an exact domain match for WebFinger resolution
The regex was not being terminated with an $
This commit is contained in:
parent
736686b4e2
commit
17987e3990
3 changed files with 20 additions and 2 deletions
1
changelog.d/webfinger-resolution.fix
Normal file
1
changelog.d/webfinger-resolution.fix
Normal file
|
|
@ -0,0 +1 @@
|
|||
Enforce an exact domain match for WebFinger resolution
|
||||
|
|
@ -35,9 +35,9 @@ defmodule Pleroma.Web.WebFinger do
|
|||
|
||||
regex =
|
||||
if webfinger_domain = Pleroma.Config.get([__MODULE__, :domain]) do
|
||||
~r/(acct:)?(?<username>[a-z0-9A-Z_\.-]+)@(#{host}|#{webfinger_domain})/
|
||||
~r/(acct:)?(?<username>[a-z0-9A-Z_\.-]+)@(#{host}|#{webfinger_domain})$/
|
||||
else
|
||||
~r/(acct:)?(?<username>[a-z0-9A-Z_\.-]+)@#{host}/
|
||||
~r/(acct:)?(?<username>[a-z0-9A-Z_\.-]+)@#{host}$/
|
||||
end
|
||||
|
||||
with %{"username" => username} <- Regex.named_captures(regex, resource),
|
||||
|
|
|
|||
|
|
@ -39,6 +39,23 @@ defmodule Pleroma.Web.WebFingerTest do
|
|||
end
|
||||
end
|
||||
|
||||
test "requires exact match for Endpoint host or WebFinger domain" do
|
||||
clear_config([Pleroma.Web.WebFinger, :domain], "pleroma.dev")
|
||||
user = insert(:user)
|
||||
|
||||
assert {:error, "Couldn't find user"} ==
|
||||
WebFinger.webfinger("#{user.nickname}@#{Pleroma.Web.Endpoint.host()}xxxx", "JSON")
|
||||
|
||||
assert {:error, "Couldn't find user"} ==
|
||||
WebFinger.webfinger("#{user.nickname}@pleroma.devxxxx", "JSON")
|
||||
|
||||
assert {:ok, _} =
|
||||
WebFinger.webfinger("#{user.nickname}@#{Pleroma.Web.Endpoint.host()}", "JSON")
|
||||
|
||||
assert {:ok, _} =
|
||||
WebFinger.webfinger("#{user.nickname}@pleroma.dev", "JSON")
|
||||
end
|
||||
|
||||
describe "fingering" do
|
||||
test "returns error for nonsensical input" do
|
||||
assert {:error, _} = WebFinger.finger("bliblablu")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue