From 2ebebe9abc7a92266de0a4ba817af531cd50c551 Mon Sep 17 00:00:00 2001 From: RealKinetix Date: Wed, 14 Jul 2021 10:15:19 -0700 Subject: [PATCH 1/4] Sanitize negative followers count on APContact Please see https://github.com/friendica/friendica/issues/9498#issuecomment-818894106 and related discussion regarding this - it appears it's possible for AP users, maybe just Mastodon users, to have a negative followers count. This causes fatal errors in Friendica, so I think we should sanitize this input. --- src/Model/APContact.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Model/APContact.php b/src/Model/APContact.php index aa5dbe2f71..971a48d9dd 100644 --- a/src/Model/APContact.php +++ b/src/Model/APContact.php @@ -272,6 +272,11 @@ class APContact if (!empty($apcontact['followers'])) { $followers = ActivityPub::fetchContent($apcontact['followers']); + // Mastodon seriously allows for this condition? + // Jul 14 2021 - See https://mastodon.online/@goes11 for a negative followers count + if ($followers['totalItems'] < 0) { + $followers['totalItems'] = 0; + } if (!empty($followers['totalItems'])) { $apcontact['followers_count'] = $followers['totalItems']; } From c1db1c980efafee06ed05b9c758a82d47d8a1974 Mon Sep 17 00:00:00 2001 From: RealKinetix Date: Wed, 14 Jul 2021 12:17:03 -0700 Subject: [PATCH 2/4] Fix indent to standards --- src/Model/APContact.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/APContact.php b/src/Model/APContact.php index 971a48d9dd..eb34e502ec 100644 --- a/src/Model/APContact.php +++ b/src/Model/APContact.php @@ -275,7 +275,7 @@ class APContact // Mastodon seriously allows for this condition? // Jul 14 2021 - See https://mastodon.online/@goes11 for a negative followers count if ($followers['totalItems'] < 0) { - $followers['totalItems'] = 0; + $followers['totalItems'] = 0; } if (!empty($followers['totalItems'])) { $apcontact['followers_count'] = $followers['totalItems']; From f16b1df83f28a68595df6174468d34dd53ae270e Mon Sep 17 00:00:00 2001 From: RealKinetix Date: Wed, 14 Jul 2021 13:46:38 -0700 Subject: [PATCH 3/4] Adjust where the code is to avoid empty warning Shifted the code to avoid: PHP Warning: Undefined array key "totalItems" in /home/friendicadev/friendica/src/Model/APContact.php on line 277 --- src/Model/APContact.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Model/APContact.php b/src/Model/APContact.php index eb34e502ec..64f45a8451 100644 --- a/src/Model/APContact.php +++ b/src/Model/APContact.php @@ -272,12 +272,12 @@ class APContact if (!empty($apcontact['followers'])) { $followers = ActivityPub::fetchContent($apcontact['followers']); - // Mastodon seriously allows for this condition? - // Jul 14 2021 - See https://mastodon.online/@goes11 for a negative followers count - if ($followers['totalItems'] < 0) { - $followers['totalItems'] = 0; - } if (!empty($followers['totalItems'])) { + // Mastodon seriously allows for this condition? + // Jul 14 2021 - See https://mastodon.online/@goes11 for a negative followers count + if ($followers['totalItems'] < 0) { + $followers['totalItems'] = 0; + } $apcontact['followers_count'] = $followers['totalItems']; } } From a0107be2af513730fac9d1f83a57a92bd4d4f51c Mon Sep 17 00:00:00 2001 From: RealKinetix Date: Wed, 14 Jul 2021 13:51:30 -0700 Subject: [PATCH 4/4] Negative numbers in following is a thing too Check & sanitize 'following' as well, as per: https://mastodon.social/@BLUW --- src/Model/APContact.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Model/APContact.php b/src/Model/APContact.php index 64f45a8451..1ae34a40a8 100644 --- a/src/Model/APContact.php +++ b/src/Model/APContact.php @@ -266,6 +266,11 @@ class APContact if (!empty($apcontact['following'])) { $following = ActivityPub::fetchContent($apcontact['following']); if (!empty($following['totalItems'])) { + // Mastodon seriously allows for this condition? + // Jul 14 2021 - See https://mastodon.social/@BLUW for a negative following count + if ($following['totalItems'] < 0) { + $following['totalItems'] = 0; + } $apcontact['following_count'] = $following['totalItems']; } }