@@ -45,8 +45,11 @@ public function webfinger(Request $request)
45
45
$ resource = $ request ->input ('resource ' );
46
46
$ domain = config ('pixelfed.domain.app ' );
47
47
48
- if (config ('federation.activitypub.sharedInbox ' ) &&
49
- $ resource == 'acct: ' .$ domain .'@ ' .$ domain ) {
48
+ // Instance Actor
49
+ if (
50
+ config ('federation.activitypub.sharedInbox ' ) &&
51
+ $ resource == 'acct: ' .$ domain .'@ ' .$ domain
52
+ ) {
50
53
$ res = [
51
54
'subject ' => 'acct: ' .$ domain .'@ ' .$ domain ,
52
55
'aliases ' => [
@@ -68,6 +71,33 @@ public function webfinger(Request $request)
68
71
69
72
return response ()->json ($ res , 200 , [], JSON_UNESCAPED_SLASHES );
70
73
}
74
+
75
+ if (str_starts_with ($ resource , 'https:// ' )) {
76
+ if (str_starts_with ($ resource , 'https:// ' . $ domain . '/users/ ' )) {
77
+ $ username = str_replace ('https:// ' . $ domain . '/users/ ' , '' , $ resource );
78
+ if (strlen ($ username ) > 15 ) {
79
+ return response ('' , 400 );
80
+ }
81
+ $ stripped = str_replace (['_ ' , '. ' , '- ' ], '' , $ username );
82
+ if (!ctype_alnum ($ stripped )) {
83
+ return response ('' , 400 );
84
+ }
85
+ $ key = 'federation:webfinger:sha256:url-username: ' .$ username ;
86
+ if ($ cached = Cache::get ($ key )) {
87
+ return response ()->json ($ cached , 200 , [], JSON_UNESCAPED_SLASHES );
88
+ }
89
+ $ profile = Profile::whereUsername ($ username )->first ();
90
+ if (! $ profile || $ profile ->status !== null || $ profile ->domain ) {
91
+ return response ('' , 400 );
92
+ }
93
+ $ webfinger = (new Webfinger ($ profile ))->generate ();
94
+ Cache::put ($ key , $ webfinger , 1209600 );
95
+ return response ()->json ($ webfinger , 200 , [], JSON_UNESCAPED_SLASHES )
96
+ ->header ('Access-Control-Allow-Origin ' , '* ' );
97
+ } else {
98
+ return response ('' , 400 );
99
+ }
100
+ }
71
101
$ hash = hash ('sha256 ' , $ resource );
72
102
$ key = 'federation:webfinger:sha256: ' .$ hash ;
73
103
if ($ cached = Cache::get ($ key )) {
@@ -81,8 +111,8 @@ public function webfinger(Request $request)
81
111
return response ('' , 400 );
82
112
}
83
113
$ username = $ parsed ['username ' ];
84
- $ profile = Profile::whereNull ( ' domain ' )-> whereUsername ($ username )->first ();
85
- if (! $ profile || $ profile ->status !== null ) {
114
+ $ profile = Profile::whereUsername ($ username )->first ();
115
+ if (! $ profile || $ profile ->status !== null || $ profile -> domain ) {
86
116
return response ('' , 400 );
87
117
}
88
118
$ webfinger = (new Webfinger ($ profile ))->generate ();
0 commit comments