Skip to content

Commit 4989970

Browse files
committed
Return 401 for invalid link-checker-api webhook signature
A correctly-formed request with the wrong signature is an authentication failure, not a malformed request.
1 parent 2fb8903 commit 4989970

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

app/controllers/admin/link_checker_api_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def verify_signature
2525

2626
body = request.raw_post
2727
signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha1"), webhook_secret_token, body)
28-
head :bad_request unless Rack::Utils.secure_compare(signature, given_signature)
28+
head :unauthorized unless Rack::Utils.secure_compare(signature, given_signature)
2929
end
3030

3131
def webhook_secret_token

test/functional/admin/link_checker_api_controller_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ def generate_signature(body, key)
5757
assert_response :bad_request
5858
end
5959

60-
test "POST :callback returns 400 when the signature does not match the body" do
60+
test "POST :callback returns 401 when the signature does not match the body" do
6161
LinkCheckerApiReport.any_instance.expects(:mark_report_as_completed).never
6262

6363
body = link_checker_api_batch_report_hash(id: 5, links: [{ uri: @link, status: "ok" }])
6464
request.headers["X-LinkCheckerApi-Signature"] = generate_signature(body.to_json, "wrong-secret")
6565
post :callback, params: body
6666

67-
assert_response :bad_request
67+
assert_response :unauthorized
6868
end
6969
end

0 commit comments

Comments
 (0)