Update webfinger util, fail on invalid webfinger url

This commit is contained in:
Daniel Supernault 2021-02-03 20:55:49 -07:00
parent aad07e2c83
commit 2d11317ceb
No known key found for this signature in database
GPG Key ID: 0DEF1C662C9033F7
2 changed files with 17 additions and 4 deletions

View File

@ -63,7 +63,7 @@ class FederationController extends Controller
}
$webfinger = (new Webfinger($profile))->generate();
return response()->json($webfinger, 200, [], JSON_PRETTY_PRINT)
return response()->json($webfinger, 200, [], JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES)
->header('Access-Control-Allow-Origin','*');
}

View File

@ -2,22 +2,35 @@
namespace App\Util\Lexer;
use Illuminate\Support\Str;
class Nickname
{
public static function normalizeProfileUrl($url)
{
if (starts_with($url, 'acct:')) {
if(!Str::of($url)->contains('@')) {
return;
}
if(Str::startsWith($url, 'acct:')) {
$url = str_replace('acct:', '', $url);
}
if(starts_with($url, '@')) {
if(Str::startsWith($url, '@')) {
$url = substr($url, 1);
if(!Str::of($url)->contains('@')) {
return;
}
}
$parts = explode('@', $url);
$username = $parts[0];
$domain = $parts[1];
return ['domain' => $domain, 'username' => $username];
return [
'domain' => $domain,
'username' => $username
];
}
}