]> git.mxchange.org Git - friendica.git/commitdiff
Centralized logging for a wrong JSON content-type
authorMichael <heluecht@pirati.ca>
Fri, 8 Mar 2024 13:48:21 +0000 (13:48 +0000)
committerMichael <heluecht@pirati.ca>
Fri, 8 Mar 2024 13:48:21 +0000 (13:48 +0000)
src/Model/APContact.php
src/Model/Item.php
src/Protocol/ActivityPub/Processor.php
src/Util/HTTPSignature.php

index d71e182e3744cada90940041a2328033b5bc2171..392f56ea4367659dea9d5b3ca406151a8f4498ce 100644 (file)
@@ -208,8 +208,7 @@ class APContact
 
                                if (!$failed && ($curlResult->getReturnCode() == 410)) {
                                        $data = ['@context' => ActivityPub::CONTEXT, 'id' => $url, 'type' => 'Tombstone'];
-                               } elseif (!$failed && !HTTPSignature::isValidContentType($curlResult->getContentType())) {
-                                       Logger::debug('Unexpected content type', ['content-type' => $curlResult->getContentType(), 'url' => $url]);
+                               } elseif (!$failed && !HTTPSignature::isValidContentType($curlResult->getContentType(), $url)) {
                                        $failed = true;
                                }
                        } catch (\Exception $exception) {
index 8ecfc9dbb21c1433bbcdd2d47c11a41c53e87a91..535e8f7989d229fd4bfe12e4bdabc8aa58100be1 100644 (file)
@@ -4097,7 +4097,7 @@ class Item
                }
 
                $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);
                }
 
index a22be1c5bcb738991cc93614073ca61dd4bf523e..c8a5ae4d5d6829fce668e10fefceeaa76677461c 100644 (file)
@@ -1618,8 +1618,7 @@ class Processor
                        return '';
                }
 
-               if (!HTTPSignature::isValidContentType($curlResult->getContentType())) {
-                       Logger::notice('Unexpected content type', ['content-type' => $curlResult->getContentType(), 'url' => $url]);
+               if (!HTTPSignature::isValidContentType($curlResult->getContentType(), $url)) {
                        return '';
                }
 
index bf5d632dcc77fd8a71d743c5b7a51168ecac6639..095b73ea7cb2fc4790ea2f0b7a4bfadca7fb676c 100644 (file)
@@ -443,8 +443,7 @@ class HTTPSignature
                        return [];
                }
 
-               if (!self::isValidContentType($curlResult->getContentType())) {
-                       Logger::notice('Unexpected content type', ['content-type' => $curlResult->getContentType(), 'url' => $request]);
+               if (!self::isValidContentType($curlResult->getContentType(), $request)) {
                        return [];
                }
 
@@ -457,9 +456,16 @@ class HTTPSignature
         * @param string $contentType
         * @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;
        }
 
        /**