Skip to content

Commit 453ca89

Browse files
ClearlyClairehiyuki2578
authored andcommitted
Reduce usage of LD signatures (mastodon#9659)
* Do not LDS-sign Follow, Accept, Reject, Undo, Block * Do not use LDS for Create activities of private toots * Minor cleanup * Ignore unsigned activities instead of misattributing them * Use status.distributable? instead of querying visibility directly
1 parent a89852d commit 453ca89

13 files changed

Lines changed: 40 additions & 34 deletions

app/lib/activitypub/activity/follow.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def perform
2828
end
2929

3030
def reject_follow_request!(target_account)
31-
json = Oj.dump(ActivityPub::LinkedDataSignature.new(ActiveModelSerializers::SerializableResource.new(FollowRequest.new(account: @account, target_account: target_account, uri: @json['id']), serializer: ActivityPub::RejectFollowSerializer, adapter: ActivityPub::Adapter).as_json).sign!(target_account))
31+
json = ActiveModelSerializers::SerializableResource.new(FollowRequest.new(account: @account, target_account: target_account, uri: @json['id']), serializer: ActivityPub::RejectFollowSerializer, adapter: ActivityPub::Adapter).to_json
3232
ActivityPub::DeliveryWorker.perform_async(json, target_account.id, @account.inbox_url)
3333
end
3434
end

app/services/activitypub/process_collection_service.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def call(body, account, **options)
2727
private
2828

2929
def different_actor?
30-
@json['actor'].present? && value_or_id(@json['actor']) != @account.uri && @json['signature'].present?
30+
@json['actor'].present? && value_or_id(@json['actor']) != @account.uri
3131
end
3232

3333
def process_items(items)

app/services/after_block_domain_from_account_service.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ def reject_follow!(follow)
3131

3232
return unless follow.account.activitypub?
3333

34-
json = Oj.dump(ActivityPub::LinkedDataSignature.new(ActiveModelSerializers::SerializableResource.new(
34+
json = ActiveModelSerializers::SerializableResource.new(
3535
follow,
3636
serializer: ActivityPub::RejectFollowSerializer,
3737
adapter: ActivityPub::Adapter
38-
).as_json).sign!(@account))
38+
).to_json
3939

4040
ActivityPub::DeliveryWorker.perform_async(json, @account.id, follow.account.inbox_url)
4141
end

app/services/authorize_follow_service.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ def create_notification(follow_request)
2424
end
2525

2626
def build_json(follow_request)
27-
Oj.dump(ActivityPub::LinkedDataSignature.new(ActiveModelSerializers::SerializableResource.new(
27+
ActiveModelSerializers::SerializableResource.new(
2828
follow_request,
2929
serializer: ActivityPub::AcceptFollowSerializer,
3030
adapter: ActivityPub::Adapter
31-
).as_json).sign!(follow_request.target_account))
31+
).to_json
3232
end
3333

3434
def build_xml(follow_request)

app/services/block_service.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# frozen_string_literal: true
22

33
class BlockService < BaseService
4-
include StreamEntryRenderer
5-
64
def call(account, target_account)
75
return if account.id == target_account.id
86

@@ -27,11 +25,11 @@ def create_notification(block)
2725
end
2826

2927
def build_json(block)
30-
Oj.dump(ActivityPub::LinkedDataSignature.new(ActiveModelSerializers::SerializableResource.new(
28+
ActiveModelSerializers::SerializableResource.new(
3129
block,
3230
serializer: ActivityPub::BlockSerializer,
3331
adapter: ActivityPub::Adapter
34-
).as_json).sign!(block.account))
32+
).to_json
3533
end
3634

3735
def build_xml(block)

app/services/follow_service.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# frozen_string_literal: true
22

33
class FollowService < BaseService
4-
include StreamEntryRenderer
5-
64
# Follow a remote user, notify remote user about the follow
75
# @param [Account] source_account From which to follow
86
# @param [String, Account] uri User URI to follow in the form of username@domain (or account record)
@@ -82,10 +80,10 @@ def build_follow_xml(follow)
8280
end
8381

8482
def build_json(follow_request)
85-
Oj.dump(ActivityPub::LinkedDataSignature.new(ActiveModelSerializers::SerializableResource.new(
83+
ActiveModelSerializers::SerializableResource.new(
8684
follow_request,
8785
serializer: ActivityPub::FollowSerializer,
8886
adapter: ActivityPub::Adapter
89-
).as_json).sign!(follow_request.account))
87+
).to_json
9088
end
9189
end

app/services/process_mentions_service.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,13 @@ def ostatus_xml
6060
end
6161

6262
def activitypub_json
63-
@activitypub_json ||= Oj.dump(ActivityPub::LinkedDataSignature.new(ActiveModelSerializers::SerializableResource.new(
63+
return @activitypub_json if defined?(@activitypub_json)
64+
payload = ActiveModelSerializers::SerializableResource.new(
6465
@status,
6566
serializer: ActivityPub::ActivitySerializer,
6667
adapter: ActivityPub::Adapter
67-
).as_json).sign!(@status.account))
68+
).as_json
69+
@activitypub_json = Oj.dump(@status.distributable? ? ActivityPub::LinkedDataSignature.new(payload).sign!(@status.account) : payload)
6870
end
6971

7072
def resolve_account_service

app/services/reject_follow_service.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ def create_notification(follow_request)
1919
end
2020

2121
def build_json(follow_request)
22-
Oj.dump(ActivityPub::LinkedDataSignature.new(ActiveModelSerializers::SerializableResource.new(
22+
ActiveModelSerializers::SerializableResource.new(
2323
follow_request,
2424
serializer: ActivityPub::RejectFollowSerializer,
2525
adapter: ActivityPub::Adapter
26-
).as_json).sign!(follow_request.target_account))
26+
).to_json
2727
end
2828

2929
def build_xml(follow_request)

app/services/unblock_service.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ def create_notification(unblock)
2020
end
2121

2222
def build_json(unblock)
23-
Oj.dump(ActivityPub::LinkedDataSignature.new(ActiveModelSerializers::SerializableResource.new(
23+
ActiveModelSerializers::SerializableResource.new(
2424
unblock,
2525
serializer: ActivityPub::UndoBlockSerializer,
2626
adapter: ActivityPub::Adapter
27-
).as_json).sign!(unblock.account))
27+
).to_json
2828
end
2929

3030
def build_xml(block)

app/services/unfollow_service.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ def create_notification(follow)
4343
end
4444

4545
def build_json(follow)
46-
Oj.dump(ActivityPub::LinkedDataSignature.new(ActiveModelSerializers::SerializableResource.new(
46+
ActiveModelSerializers::SerializableResource.new(
4747
follow,
4848
serializer: ActivityPub::UndoFollowSerializer,
4949
adapter: ActivityPub::Adapter
50-
).as_json).sign!(follow.account))
50+
).to_json
5151
end
5252

5353
def build_xml(follow)

0 commit comments

Comments
 (0)