Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional checks for banned instances + various code improvements along the way #1258

Merged
merged 19 commits into from
Dec 31, 2024

Conversation

melroy89
Copy link
Member

@melroy89 melroy89 commented Nov 28, 2024

Even after the previous PR: #1254. I still see some requests failing and being make to banned instances. This is a follow-up PR.

  • There are several places like LikeHandler, activityPubManager and UpdateActorHandler that is calling methods directly or indirectly methods from ActivityPubManager.php (methods like: findActorOrCreate or updateActor for example).
  • I added additional checks for these methods in ActivityPubManager now as well. And just return null, which just ignore the request. Without the need for additional try/catch blabla in the callee methods.
  • While I was in ApHttpClient.php (but eventually decided not to add the isBannedInstance check there). I did documented some code and introduced a dedicated getCollectinCacheKey method as well, just like getActorCacheKey
  • I made several method private. If methods can be private, please yes. Our code is already enough spaghetti.
  • Rename a wrong log message from updateUser to logRequestException`
  • Finally, I made the activityPubManager variable consistent through all out the inbox, outbox activitypub files as well as services and messenger handler files. This will make grepping easier. And give me less headache.

Fixes 25th: #1175 (comment)

@melroy89 melroy89 added the enhancement New feature or request label Nov 28, 2024
@melroy89 melroy89 added this to the v1.7.4 milestone Nov 28, 2024
@melroy89 melroy89 enabled auto-merge (squash) November 30, 2024 23:35
Copy link
Member

@BentiGorlich BentiGorlich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most important thing is the check in findActorOrCreate

src/Service/ActivityPubManager.php Outdated Show resolved Hide resolved
src/Service/ActivityPubManager.php Outdated Show resolved Hide resolved
Comment on lines 163 to 166
// Check if the instance is banned
if ($this->settingsManager->isBannedInstance($actorUrl)) {
return null;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check should be pushed down to the line just before $actor = $this->apHttpClient->getActorObject($actorUrl);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure? This might still do dispatchUpdateActor.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dispatch update actor checks for banned instances as well so this is not an issue i think

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes indeed, it checks it:

if ($this->settingsManager->isBannedInstance($actorUrl)) {
. But not dispatching in the first place is more efficient, which I like. And reduce unnecessary CPU cycles etc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well it does the check before actually dispatching the update:

public function dispatchUpdateActor(string $actorUrl)
{
if ($this->settingsManager->isBannedInstance($actorUrl)) {
return;
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed the isBannedInstance check down to line 176 now.

The question now is whether you really want to return users or magazines from a banned instance..?

BentiGorlich
BentiGorlich previously approved these changes Dec 2, 2024
src/Service/ActivityPubManager.php Outdated Show resolved Hide resolved
Comment on lines 163 to 166
// Check if the instance is banned
if ($this->settingsManager->isBannedInstance($actorUrl)) {
return null;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dispatch update actor checks for banned instances as well so this is not an issue i think

@melroy89 melroy89 changed the title Add additional checks for banned instances Add additional checks for banned instances + various code improvements along the way Dec 17, 2024
@melroy89 melroy89 force-pushed the add_missing_ban_instances_checks branch from 910330e to 9b02e5c Compare December 17, 2024 22:56
@melroy89 melroy89 enabled auto-merge (squash) December 20, 2024 22:20
@melroy89 melroy89 requested review from garrettw and removed request for BentiGorlich December 29, 2024 15:31
src/Service/ActivityPub/ApHttpClient.php Outdated Show resolved Hide resolved
src/Service/ActivityPub/ApHttpClient.php Outdated Show resolved Hide resolved
@melroy89 melroy89 requested a review from garrettw December 30, 2024 20:02
Copy link
Contributor

@garrettw garrettw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment left on previous thread

garrettw
garrettw previously approved these changes Dec 31, 2024
@melroy89 melroy89 merged commit d6479df into main Dec 31, 2024
7 checks passed
@melroy89 melroy89 deleted the add_missing_ban_instances_checks branch December 31, 2024 17:33
@BentiGorlich
Copy link
Member

I am really not a fan of a new contributor approving changes on highly important code. Nothing against @garrettw , but you are a new contributor.
Additionally @melroy89 you marked a conversation as completed just because I didn't bave the time to answer, which I also not appreciate.

If I have remarks in the future I will check the 'request changes option ' if I have such comments to prevent this, but please be careful with everything activity pub related

@garrettw
Copy link
Contributor

No offense taken.
I only reviewed this because I was requested to, and after looking it over, if I had thought the changes were beyond my current understanding of the code, I would have declined to review it — but I thought it looked fairly straightforward.

@BentiGorlich
Copy link
Member

The code changes are easy, the implications of the changes however are not.

@garrettw
Copy link
Contributor

I guess I can see how that’s true for a couple of the files involved.

@melroy89
Copy link
Member Author

I am really not a fan of a new contributor approving changes on highly important code. Nothing against @garrettw , but you are a new contributor. Additionally @melroy89 you marked a conversation as completed just because I didn't bave the time to answer, which I also not appreciate.

If I have remarks in the future I will check the 'request changes option ' if I have such comments to prevent this, but please be careful with everything activity pub related

Happy new year!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants