mirror of
https://github.com/discourse/discourse.git
synced 2026-07-31 08:38:27 -05:00
DEV: Ai bot Signature verification uses different body source than action logic (#38294)
Discord BotController signature verification uses `request.raw_post`, but action logic reads body via `request.body.read` — This PR unifies usage.
This commit is contained in:
@@ -8,14 +8,15 @@ module DiscourseAi
|
||||
skip_before_action :verify_authenticity_token
|
||||
|
||||
def interactions
|
||||
body = request.raw_post
|
||||
|
||||
# Request signature verification
|
||||
begin
|
||||
verify_request!
|
||||
verify_request!(body)
|
||||
rescue Ed25519::VerifyError
|
||||
return head :unauthorized
|
||||
end
|
||||
|
||||
body = request.body.read
|
||||
interaction = JSON.parse(body, object_class: OpenStruct)
|
||||
|
||||
if interaction.type == 1
|
||||
@@ -36,10 +37,10 @@ module DiscourseAi
|
||||
|
||||
private
|
||||
|
||||
def verify_request!
|
||||
def verify_request!(body)
|
||||
signature = request.headers["X-Signature-Ed25519"]
|
||||
timestamp = request.headers["X-Signature-Timestamp"]
|
||||
verify_key.verify([signature].pack("H*"), "#{timestamp}#{request.raw_post}")
|
||||
verify_key.verify([signature].pack("H*"), "#{timestamp}#{body}")
|
||||
end
|
||||
|
||||
def verify_key
|
||||
|
||||
Reference in New Issue
Block a user