Refactor: Enhance QboWebhookProcessor with logging for signature validation

This commit is contained in:
2026-03-01 00:58:46 -05:00
parent 69d266bdca
commit 16ca1caabc

View File

@@ -21,9 +21,12 @@ class QboWebhookProcessor
WebhookProcessJob.perform_later(body) WebhookProcessJob.perform_later(body)
end end
private
# Validates the QuickBooks webhook request by computing the HMAC signature and comparing it to the provided signature. Returns false if either the signature or secret is blank, or if the computed signature does not match the provided signature. # Validates the QuickBooks webhook request by computing the HMAC signature and comparing it to the provided signature. Returns false if either the signature or secret is blank, or if the computed signature does not match the provided signature.
def self.valid_signature?(body, signature, secret) def self.valid_signature?(body, signature, secret)
return false if signature.blank? || secret.blank? return false if signature.blank? || secret.blank?
log "Validating signature"
digest = OpenSSL::Digest.new('sha256') digest = OpenSSL::Digest.new('sha256')
computed = Base64.strict_encode64( computed = Base64.strict_encode64(
@@ -32,4 +35,8 @@ class QboWebhookProcessor
ActiveSupport::SecurityUtils.secure_compare(computed, signature) ActiveSupport::SecurityUtils.secure_compare(computed, signature)
end end
def self.log(msg)
Rails.logger.info "[QboWebhookProcessor] #{msg}"
end
end end