mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-25 15:55:22 +00:00
commit
0dc54e9ac0
2 changed files with 53 additions and 29 deletions
|
@ -7,6 +7,7 @@
|
||||||
- Update ApiV1Controller, fix network timeline ([0faf59e3](https://github.com/pixelfed/pixelfed/commit/0faf59e3))
|
- Update ApiV1Controller, fix network timeline ([0faf59e3](https://github.com/pixelfed/pixelfed/commit/0faf59e3))
|
||||||
- Update public/network timelines, fix non-redis response and fix reblogs in home feed ([8b4ac5cc](https://github.com/pixelfed/pixelfed/commit/8b4ac5cc))
|
- Update public/network timelines, fix non-redis response and fix reblogs in home feed ([8b4ac5cc](https://github.com/pixelfed/pixelfed/commit/8b4ac5cc))
|
||||||
- Update Federation, use proper Content-Type headers for following/follower collections ([fb0bb9a3](https://github.com/pixelfed/pixelfed/commit/fb0bb9a3))
|
- Update Federation, use proper Content-Type headers for following/follower collections ([fb0bb9a3](https://github.com/pixelfed/pixelfed/commit/fb0bb9a3))
|
||||||
|
- Update ActivityPubFetchService, enforce stricter Content-Type validation ([1232cfc8](https://github.com/pixelfed/pixelfed/commit/1232cfc8))
|
||||||
- ([](https://github.com/pixelfed/pixelfed/commit/))
|
- ([](https://github.com/pixelfed/pixelfed/commit/))
|
||||||
|
|
||||||
## [v0.11.11 (2024-02-09)](https://github.com/pixelfed/pixelfed/compare/v0.11.10...v0.11.11)
|
## [v0.11.11 (2024-02-09)](https://github.com/pixelfed/pixelfed/compare/v0.11.10...v0.11.11)
|
||||||
|
|
|
@ -11,38 +11,61 @@ use Illuminate\Http\Client\RequestException;
|
||||||
|
|
||||||
class ActivityPubFetchService
|
class ActivityPubFetchService
|
||||||
{
|
{
|
||||||
public static function get($url, $validateUrl = true)
|
public static function get($url, $validateUrl = true)
|
||||||
{
|
{
|
||||||
if($validateUrl === true) {
|
if($validateUrl === true) {
|
||||||
if(!Helpers::validateUrl($url)) {
|
if(!Helpers::validateUrl($url)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$baseHeaders = [
|
$baseHeaders = [
|
||||||
'Accept' => 'application/activity+json, application/ld+json',
|
'Accept' => 'application/activity+json, application/ld+json',
|
||||||
];
|
];
|
||||||
|
|
||||||
$headers = HttpSignature::instanceActorSign($url, false, $baseHeaders, 'get');
|
$headers = HttpSignature::instanceActorSign($url, false, $baseHeaders, 'get');
|
||||||
$headers['Accept'] = 'application/activity+json, application/ld+json';
|
$headers['Accept'] = 'application/activity+json, application/ld+json';
|
||||||
$headers['User-Agent'] = 'PixelFedBot/1.0.0 (Pixelfed/'.config('pixelfed.version').'; +'.config('app.url').')';
|
$headers['User-Agent'] = 'PixelFedBot/1.0.0 (Pixelfed/'.config('pixelfed.version').'; +'.config('app.url').')';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$res = Http::withOptions(['allow_redirects' => false])->withHeaders($headers)
|
$res = Http::withOptions(['allow_redirects' => false])
|
||||||
->timeout(30)
|
->withHeaders($headers)
|
||||||
->connectTimeout(5)
|
->timeout(30)
|
||||||
->retry(3, 500)
|
->connectTimeout(5)
|
||||||
->get($url);
|
->retry(3, 500)
|
||||||
} catch (RequestException $e) {
|
->get($url);
|
||||||
return;
|
} catch (RequestException $e) {
|
||||||
} catch (ConnectionException $e) {
|
return;
|
||||||
return;
|
} catch (ConnectionException $e) {
|
||||||
} catch (Exception $e) {
|
return;
|
||||||
return;
|
} catch (Exception $e) {
|
||||||
}
|
return;
|
||||||
if(!$res->ok()) {
|
}
|
||||||
return;
|
|
||||||
}
|
if(!$res->ok()) {
|
||||||
return $res->body();
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!$res->hasHeader('Content-Type')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$acceptedTypes = [
|
||||||
|
'application/activity+json; charset=utf-8',
|
||||||
|
'application/activity+json',
|
||||||
|
'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
|
||||||
|
];
|
||||||
|
|
||||||
|
$contentType = $res->getHeader('Content-Type')[0];
|
||||||
|
|
||||||
|
if(!$contentType) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!in_array($contentType, $acceptedTypes)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $res->body();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue