Skip to content

Commit f7d70dc

Browse files
ClearlyClairehiyuki2578
authored andcommitted
Do not try fetching keys of unknown accounts on a Delete from them (mastodon#10326)
1 parent 6ea981b commit f7d70dc

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

app/controllers/activitypub/inboxes_controller.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
class ActivityPub::InboxesController < Api::BaseController
44
include SignatureVerification
5+
include JsonLdHelper
56

67
before_action :set_account
78

89
def create
9-
if signed_request_account
10+
if unknown_deleted_account?
11+
head 202
12+
elsif signed_request_account
1013
upgrade_account
1114
process_payload
1215
head 202
@@ -17,12 +20,19 @@ def create
1720

1821
private
1922

23+
def unknown_deleted_account?
24+
json = Oj.load(body, mode: :strict)
25+
json['type'] == 'Delete' && json['actor'].present? && json['actor'] == value_or_id(json['object']) && !Account.where(uri: json['actor']).exists?
26+
rescue Oj::ParseError
27+
false
28+
end
29+
2030
def set_account
2131
@account = Account.find_local!(params[:account_username]) if params[:account_username]
2232
end
2333

2434
def body
25-
@body ||= request.body.read
35+
@body ||= request.body.read.force_encoding('UTF-8')
2636
end
2737

2838
def upgrade_account
@@ -36,6 +46,6 @@ def upgrade_account
3646
end
3747

3848
def process_payload
39-
ActivityPub::ProcessingWorker.perform_async(signed_request_account.id, body.force_encoding('UTF-8'), @account&.id)
49+
ActivityPub::ProcessingWorker.perform_async(signed_request_account.id, body, @account&.id)
4050
end
4151
end

spec/controllers/activitypub/inboxes_controller_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
Fabricate(:account)
1111
end
1212

13-
post :create
13+
post :create, body: '{}'
1414
expect(response).to have_http_status(202)
1515
end
1616
end
@@ -21,7 +21,7 @@
2121
false
2222
end
2323

24-
post :create
24+
post :create, body: '{}'
2525
expect(response).to have_http_status(401)
2626
end
2727
end

0 commit comments

Comments
 (0)