Skip to content
This repository has been archived by the owner on Jan 27, 2020. It is now read-only.

Commit

Permalink
Fix HTTP responses for salmon and ActivityPub inbox processing (masto…
Browse files Browse the repository at this point in the history
…don#5200)

* Return sensible HTTP status for ActivityPub inbox processing

* Return sensible HTTP status for salmon slap processing

* Return additional information to debug signature verification failures
  • Loading branch information
ClearlyClaire authored and abcang committed Oct 12, 2018
1 parent cb9dbef commit 98f4354
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/controllers/activitypub/inboxes_controller.rb
Expand Up @@ -9,9 +9,9 @@ def create
if signed_request_account
upgrade_account
process_payload
head 201
else
head 202
else
[signature_verification_failure_reason, 401]
end
end

Expand Down
6 changes: 4 additions & 2 deletions app/controllers/api/salmon_controller.rb
Expand Up @@ -7,9 +7,11 @@ class Api::SalmonController < Api::BaseController
def update
if verify_payload?
process_salmon
head 201
else
head 202
elsif payload.present?
[signature_verification_failure_reason, 401]
else
head 400
end
end

Expand Down
9 changes: 9 additions & 0 deletions app/controllers/concerns/signature_verification.rb
Expand Up @@ -9,10 +9,15 @@ def signed_request?
request.headers['Signature'].present?
end

def signature_verification_failure_reason
return @signature_verification_failure_reason if defined?(@signature_verification_failure_reason)
end

def signed_request_account
return @signed_request_account if defined?(@signed_request_account)

unless signed_request?
@signature_verification_failure_reason = 'Request not signed'
@signed_request_account = nil
return
end
Expand All @@ -27,13 +32,15 @@ def signed_request_account
end

if incompatible_signature?(signature_params)
@signature_verification_failure_reason = 'Incompatible request signature'
@signed_request_account = nil
return
end

account = account_from_key_id(signature_params['keyId'])

if account.nil?
@signature_verification_failure_reason = "Public key not found for key #{signature_params['keyId']}"
@signed_request_account = nil
return
end
Expand All @@ -51,9 +58,11 @@ def signed_request_account
@signed_request_account = account
@signed_request_account
else
@signed_verification_failure_reason = "Verification failed for #{account.username}@#{account.domain} #{account.uri}"
@signed_request_account = nil
end
else
@signed_verification_failure_reason = "Verification failed for #{account.username}@#{account.domain} #{account.uri}"
@signed_request_account = nil
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/api/salmon_controller_spec.rb
Expand Up @@ -46,8 +46,8 @@
post :update, params: { id: account.id }
end

it 'returns http success' do
expect(response).to have_http_status(202)
it 'returns http client error' do
expect(response).to have_http_status(400)
end
end
end
Expand Down

0 comments on commit 98f4354

Please sign in to comment.