Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
feld
pleroma
Commits
976094cd
Commit
976094cd
authored
Aug 25, 2020
by
Haelwenn
Browse files
Merge branch '2077-fix-bogus-webfinger-ids' into 'develop'
Webfinger: Handle bogus ids better. Closes
#2077
See merge request
!2919
parents
361aa22e
112bec52
Changes
2
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/web/web_finger/web_finger.ex
View file @
976094cd
...
...
@@ -149,6 +149,18 @@ defmodule Pleroma.Web.WebFinger do
end
end
defp
get_address_from_domain
(
domain
,
encoded_account
)
when
is_binary
(
domain
)
do
case
find_lrdd_template
(
domain
)
do
{
:ok
,
template
}
->
String
.
replace
(
template
,
"{uri}"
,
encoded_account
)
_
->
"https://
#{
domain
}
/.well-known/webfinger?resource=
#{
encoded_account
}
"
end
end
defp
get_address_from_domain
(
_
,
_
),
do
:
nil
@spec
finger
(
String
.
t
())
::
{
:ok
,
map
()}
|
{
:error
,
any
()}
def
finger
(
account
)
do
account
=
String
.
trim_leading
(
account
,
"@"
)
...
...
@@ -163,16 +175,8 @@ defmodule Pleroma.Web.WebFinger do
encoded_account
=
URI
.
encode
(
"acct:
#{
account
}
"
)
address
=
case
find_lrdd_template
(
domain
)
do
{
:ok
,
template
}
->
String
.
replace
(
template
,
"{uri}"
,
encoded_account
)
_
->
"https://
#{
domain
}
/.well-known/webfinger?resource=
#{
encoded_account
}
"
end
with
response
<-
with
address
when
is_binary
(
address
)
<-
get_address_from_domain
(
domain
,
encoded_account
),
response
<-
HTTP
.
get
(
address
,
[{
"accept"
,
"application/xrd+xml,application/jrd+json"
}]
...
...
test/web/web_finger/web_finger_test.exs
View file @
976094cd
...
...
@@ -40,6 +40,11 @@ defmodule Pleroma.Web.WebFingerTest do
end
describe
"fingering"
do
test
"returns error for nonsensical input"
do
assert
{
:error
,
_
}
=
WebFinger
.
finger
(
"bliblablu"
)
assert
{
:error
,
_
}
=
WebFinger
.
finger
(
"pleroma.social"
)
end
test
"returns error when fails parse xml or json"
do
user
=
"invalid_content@social.heldscal.la"
assert
{
:error
,
%
Jason
.
DecodeError
{}}
=
WebFinger
.
finger
(
user
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment