@@ -729,7 +729,7 @@ private function sanitizePropertyFediverse(IAccountProperty $property): void {
729729
730730 try {
731731 // try the public account lookup API of mastodon
732- $ response = $ client ->get ("https:// {$ instance }/api/v1/accounts/lookup?acct= {$ username }@ {$ instance }" );
732+ $ response = $ client ->get ("https:// {$ instance }/.well-known/webfinger?resource=acct: {$ username }@ {$ instance }" );
733733 // should be a json response with account information
734734 $ data = $ response ->getBody ();
735735 if (is_resource ($ data )) {
@@ -738,9 +738,26 @@ private function sanitizePropertyFediverse(IAccountProperty $property): void {
738738 $ decoded = json_decode ($ data , true );
739739 // ensure the username is the same the user passed
740740 // in this case we can assume this is a valid fediverse server and account
741- if (!is_array ($ decoded ) || ($ decoded ['username ' ] ?? '' ) !== $ username ) {
741+ if (!is_array ($ decoded ) || ($ decoded ['subject ' ] ?? '' ) !== " acct: { $ username} @ { $ instance }" ) {
742742 throw new InvalidArgumentException ();
743743 }
744+ // check for activitypub link
745+ if (is_array ($ decoded ['links ' ]) && isset ($ decoded ['links ' ])) {
746+ $ found = false ;
747+ foreach ($ decoded ['links ' ] as $ link ) {
748+ // have application/activity+json or application/ld+json
749+ if (isset ($ link ['type ' ]) && (
750+ $ link ['type ' ] === 'application/activity+json ' ||
751+ $ link ['type ' ] === 'application/ld+json; profile="https://www.w3.org/ns/activitystreams" '
752+ )) {
753+ $ found = true ;
754+ break ;
755+ }
756+ }
757+ if (!$ found ) {
758+ throw new InvalidArgumentException ();
759+ }
760+ }
744761 } catch (InvalidArgumentException ) {
745762 throw new InvalidArgumentException (self ::PROPERTY_FEDIVERSE );
746763 } catch (\Exception $ error ) {
0 commit comments