Merge pull request #13976 from annando/content-type-logging
Centralized logging for a wrong JSON content-type
This commit is contained in:
commit
f041701765
|
@ -208,8 +208,7 @@ class APContact
|
||||||
|
|
||||||
if (!$failed && ($curlResult->getReturnCode() == 410)) {
|
if (!$failed && ($curlResult->getReturnCode() == 410)) {
|
||||||
$data = ['@context' => ActivityPub::CONTEXT, 'id' => $url, 'type' => 'Tombstone'];
|
$data = ['@context' => ActivityPub::CONTEXT, 'id' => $url, 'type' => 'Tombstone'];
|
||||||
} elseif (!$failed && !HTTPSignature::isValidContentType($curlResult->getContentType())) {
|
} elseif (!$failed && !HTTPSignature::isValidContentType($curlResult->getContentType(), $url)) {
|
||||||
Logger::debug('Unexpected content type', ['content-type' => $curlResult->getContentType(), 'url' => $url]);
|
|
||||||
$failed = true;
|
$failed = true;
|
||||||
}
|
}
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
|
|
|
@ -4097,7 +4097,7 @@ class Item
|
||||||
}
|
}
|
||||||
|
|
||||||
$curlResult = DI::httpClient()->head($uri, [HttpClientOptions::ACCEPT_CONTENT => HttpClientAccept::JSON_AS]);
|
$curlResult = DI::httpClient()->head($uri, [HttpClientOptions::ACCEPT_CONTENT => HttpClientAccept::JSON_AS]);
|
||||||
if (HTTPSignature::isValidContentType($curlResult->getContentType())) {
|
if (HTTPSignature::isValidContentType($curlResult->getContentType(), $uri)) {
|
||||||
$fetched_uri = ActivityPub\Processor::fetchMissingActivity($uri, [], '', $completion, $uid);
|
$fetched_uri = ActivityPub\Processor::fetchMissingActivity($uri, [], '', $completion, $uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1618,8 +1618,7 @@ class Processor
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!HTTPSignature::isValidContentType($curlResult->getContentType())) {
|
if (!HTTPSignature::isValidContentType($curlResult->getContentType(), $url)) {
|
||||||
Logger::notice('Unexpected content type', ['content-type' => $curlResult->getContentType(), 'url' => $url]);
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -443,8 +443,7 @@ class HTTPSignature
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!self::isValidContentType($curlResult->getContentType())) {
|
if (!self::isValidContentType($curlResult->getContentType(), $request)) {
|
||||||
Logger::notice('Unexpected content type', ['content-type' => $curlResult->getContentType(), 'url' => $request]);
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -457,9 +456,16 @@ class HTTPSignature
|
||||||
* @param string $contentType
|
* @param string $contentType
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public static function isValidContentType(string $contentType): bool
|
public static function isValidContentType(string $contentType, string $url = ''): bool
|
||||||
{
|
{
|
||||||
return in_array(current(explode(';', $contentType)), ['application/activity+json', 'application/ld+json']);
|
if (in_array(current(explode(';', $contentType)), ['application/activity+json', 'application/ld+json'])) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (current(explode(';', $contentType)) == 'application/json') {
|
||||||
|
Logger::notice('Unexpected content type, possibly from a remote system that is not standard compliant.', ['content-type' => $contentType, 'url' => $url]);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user