diff --git a/ActivityPubPlugin.php b/ActivityPubPlugin.php index fb53c6b..570b426 100755 --- a/ActivityPubPlugin.php +++ b/ActivityPubPlugin.php @@ -121,11 +121,9 @@ class ActivityPubPlugin extends Plugin $response = $client->get($url, $headers); $res = json_decode($response->getBody(), true); $settings = []; - try { - Activitypub_notice::validate_remote_notice($res); - } catch (Exception $e) { + if (!Activitypub_notice::validate_remote_notice($res, $msg)) { common_debug('ActivityPubPlugin Notice Grabber: Invalid potential remote notice while processing id: '.$url. '. He returned the following: '.json_encode($res, JSON_UNESCAPED_SLASHES)); - throw $e; + throw new Exception($msg); } if (isset($res->inReplyTo)) { diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cae4ea6..0d0cc9b 100755 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,7 +1,7 @@ # Contributing When contributing to this repository, please first discuss the change you wish to make via issue, -email, or any other method with the owners of this repository before making a change. +email, or any other method with the owners of this repository before making a change. Please note we have a code of conduct, please follow it in all your interactions with the project. @@ -14,7 +14,7 @@ Please note we have a code of conduct, please follow it in all your interactions 1. Ensure you strip any trailing spaces off 2. Increase the version numbers in any examples files and the README.md to the new version that this Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/). -3. You may merge the Pull Request in once you have the sign-off of two other developers, or if you +3. You may merge the Pull Request in once you have the sign-off of two other developers, or if you do not have permission to do that, you may request the second reviewer to merge it for you. ## Code of Conduct diff --git a/README.md b/README.md index 32837e5..f67010a 100755 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ It includes general information about the plugin. ## About -This plugin adds [ActivityPub](https://www.w3.org/TR/activitypub/) support to +This plugin adds [ActivityPub](https://www.w3.org/TR/activitypub/) support to GNU Social. ## Setup @@ -31,11 +31,11 @@ GNU Social. ## Contributing -Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us. +Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting merge requests to us. ## Versioning -We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://git.gnu.io/gnu/GS-ActivityPub-Plugin/tags). +We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://git.gnu.io/gnu/GS-ActivityPub-Plugin/tags). ## Credits diff --git a/actions/inbox/Create.php b/actions/inbox/Create.php index 7a7c71a..7456b4a 100755 --- a/actions/inbox/Create.php +++ b/actions/inbox/Create.php @@ -33,11 +33,9 @@ $valid_object_types = ['Note']; $res = $data->object; -try { - Activitypub_notice::validate_remote_notice((array) $res); -} catch (Exception $e) { - common_debug('ActivityPub Inbox Create Note: Invalid note: '.$e->getMessage()); - ActivityPubReturn::error($e->getMessage()); +if (!Activitypub_notice::validate_remote_notice((array) $res, $msg)) { + common_debug('ActivityPub Inbox Create Note: Invalid note: '.$msg); + ActivityPubReturn::error($msg); } $settings = []; diff --git a/classes/Activitypub_notice.php b/classes/Activitypub_notice.php index 893884e..62fb5e2 100755 --- a/classes/Activitypub_notice.php +++ b/classes/Activitypub_notice.php @@ -202,39 +202,49 @@ class Activitypub_notice extends Managed_DataObject * * @author Diogo Cordeiro * @param Array $data + * @param string $msg I/O * @return boolean true in case of success * @throws Exception */ - public static function validate_remote_notice($data) + public static function validate_remote_notice($data, &$msg) { if (!isset($data['attributedTo'])) { common_debug('ActivityPub Notice Validator: Rejected because attributedTo was not specified.'); - throw new Exception('No attributedTo specified.'); + $msg = 'No attributedTo specified.'; + return false; } if (!isset($data['id'])) { common_debug('ActivityPub Notice Validator: Rejected because Object ID was not specified.'); - throw new Exception('Object ID not specified.'); + $msg = 'Object ID not specified.'; + return false; } elseif (!filter_var($data['id'], FILTER_VALIDATE_URL)) { common_debug('ActivityPub Notice Validator: Rejected because Object ID is invalid.'); - throw new Exception('Invalid Object ID.'); + $msg = 'Invalid Object ID.'; + return false; } if (!isset($data['type']) || $data['type'] !== 'Note') { common_debug('ActivityPub Notice Validator: Rejected because of Type.'); - throw new Exception('Invalid Object type.'); + $msg = 'Invalid Object type.'; + return false; } if (!isset($data['content'])) { common_debug('ActivityPub Notice Validator: Rejected because Content was not specified.'); - throw new Exception('Object content was not specified.'); + $msg = 'Object content was not specified.'; + return false; } if (!isset($data['url'])) { - throw new Exception('Object URL was not specified.'); + common_debug('ActivityPub Notice Validator: Rejected because Object URL was not specified.'); + $msg = 'Object URL was not specified.'; + return false; } elseif (!filter_var($data['url'], FILTER_VALIDATE_URL)) { common_debug('ActivityPub Notice Validator: Rejected because Object URL is invalid.'); - throw new Exception('Invalid Object URL.'); + $msg = 'Invalid Object URL.'; + return false; } if (!isset($data['cc'])) { common_debug('ActivityPub Notice Validator: Rejected because Object CC was not specified.'); - throw new Exception('Object CC was not specified.'); + $msg = 'Object CC was not specified.'; + return false; } return true; } diff --git a/utils/explorer.php b/utils/explorer.php index e46f56a..c11a3cd 100755 --- a/utils/explorer.php +++ b/utils/explorer.php @@ -269,7 +269,12 @@ class Activitypub_explorer // Avatar if (isset($res['icon']['url'])) { - $this->_store_avatar($profile, $res['icon']['url']); + try { + $this->_store_avatar($profile, $res['icon']['url']); + } catch (Exception $e) { + // Let the exception go, it isn't a serious issue + common_debug('An error ocurred while grabbing remote avatar'.$e->getMessage()); + } } return $profile; @@ -297,7 +302,7 @@ class Activitypub_explorer $imgData = HTTPClient::quickGet($url); // Make sure it's at least an image file. ImageFile can do the rest. if (false === getimagesizefromstring($imgData)) { - throw new UnsupportedMediaException('Downloaded group avatar was not an image.'); + throw new UnsupportedMediaException('Downloaded avatar was not an image.'); } file_put_contents($temp_filename, $imgData); unset($imgData); // No need to carry this in memory. @@ -307,9 +312,9 @@ class Activitypub_explorer $imagefile = new ImageFile(null, $temp_filename); $filename = Avatar::filename( $id, - image_type_to_extension($imagefile->type), - null, - common_timestamp() + image_type_to_extension($imagefile->type), + null, + common_timestamp() ); rename($temp_filename, Avatar::path($filename)); } catch (Exception $e) {