https://retellai.com/?utm_source=discord&utm_medium=seo logo
Webhook Verification
# ❓・bug-report
c
I'm trying to set it up so that I can receive a webook from RetellAi. I've set it up to hit an endpoint in my code but i'm wanting to verifiy it. I was verifiying before just by the Account ID but that is very bad and easily spoofable. So i've been asking ChatGPT and it said I should use the X-Retell-Signature header. Perfect but i'm having a few issues with matching it up. TLDR: How do you go about verifying that the webhook came from RetellAi and not somebody else?
Lets say X-Retell-Signature is v=17...,d=123567890 How does retell get that d=123567890? I know I have to use my Secret Key under the API Keys section which is the webhook key I've (ChatGPT) written this but the key its generating is different to the one you supply. Code Snippet... def check_key return true if Rails.env.development? signature_header = request.headers["X-Retell-Signature"].to_s timestamp = signature_header[/v=(\d+)/, 1] provided_digest = signature_header[/d=([a-f0-9]+)/i, 1] if timestamp.blank? || provided_digest.blank? Rails.logger.warn("Missing or malformed RetellAi signature") head :unauthorized and return end # Prevent replay attacks (5-minute window) if timestamp.to_i < (Time.now.to_i - 5.minutes.to_i) * 1000 Rails.logger.warn("Stale RetellAi webhook timestamp") head :unauthorized and return end secret = Rails.application.credentials.dig(:retell_ai, :webhook_api_key).gsub("key_", "") unless secret Rails.logger.error("Missing RetellAi webhook secret in credentials") head :unauthorized and return end raw_body = request.raw_post message = "#{timestamp}.#{raw_body}" expected_digest = OpenSSL::HMAC.hexdigest("sha256", secret, message) Rails.logger.info("Signature header: #{signature_header}") Rails.logger.info("Timestamp: #{timestamp}") Rails.logger.info("Raw body: #{raw_body.inspect}") Rails.logger.info("String to sign: #{timestamp}.#{raw_body}") Rails.logger.info("Secret: #{secret}") Rails.logger.info("Expected digest: #{expected_digest}") Rails.logger.info("Provided digest: #{provided_digest}") unless ActiveSupport::SecurityUtils.secure_compare(expected_digest, provided_digest) Rails.logger.warn("Invalid RetellAi signature") head :unauthorized and return end end
s
Hi @Ciaran thanks for reaching out.Only the API key marked with a webhook badge can verify signatures Timestamp is in milliseconds Your timestamp check is incorrect.Don't modify the secret key Use the full API key, don't remove "key" def check_key return true if Rails.env.development? signature_header = request.headers["X-Retell-Signature"].to_s timestamp = signature_header[/v=(\d+)/, 1] provided_digest = signature_header[/d=([a-f0-9]+)/i, 1] if timestamp.blank? || provided_digest.blank? Rails.logger.warn("Missing or malformed RetellAi signature") head :unauthorized and return end # Fix: timestamp is already in milliseconds, compare directly if timestamp.to_i < (Time.now.to_i * 1000 - 5.minutes.to_i * 1000) Rails.logger.warn("Stale RetellAi webhook timestamp") head :unauthorized and return end # Fix: use the full webhook API key, don't remove "key" secret = Rails.application.credentials.dig(:retell_ai, :webhook_apikey) unless secret Rails.logger.error("Missing RetellAi webhook secret in credentials") head :unauthorized and return end raw_body = request.raw_post message = "#{timestamp}.#{raw_body}" expected_digest = OpenSSL::HMAC.hexdigest("sha256", secret, message) unless ActiveSupport::SecurityUtils.secure_compare(expected_digest, provided_digest) Rails.logger.warn("Invalid RetellAi signature") head :unauthorized and return end end
c
I'll test this and i'll let you know, thank you for helping me 🙂
That didn't do the trick sadly 🙁 @shahretell Any other ideas? I, [2025-08-01T08:15:31.004489 #1871206] INFO -- : [72bd5acf-75db-4d07-a72a-bfca7a392cd5] Expected digest: bb5ff1064f18604bef70fdf8ed1e1573e1b9f8978d4bbbc1c0699337c19943d8 I, [2025-08-01T08:15:31.004517 #1871206] INFO -- : [72bd5acf-75db-4d07-a72a-bfca7a392cd5] Provided digest: c29f2f1c76099b298a7b77baa153540df931ad6fc91f1c821080ecb27c544a52 W, [2025-08-01T08:15:31.004580 #1871206] WARN -- : [72bd5acf-75db-4d07-a72a-bfca7a392cd5] Invalid RetellAi signature I don't want to post keys and params into here as I sort of want to keep that information private as it includes phone numbers etc. The only thing I can think of is that the string_to_sign is incorrect. Could you possibly pass me an example of how that should look and I can see if theres any discrepencies?
s
HI @Ciaran you could use their official SDK verification function rather than implementing your own HMAC calculation you can get it on github
c
Could you get me the documentation for that so I can have a look please :)?
c
I have not gotten this to work. @shahretell , is there any working implementation for ruby code yet?
Hey @shahretell , just want to follow up on this. Is there any documentation for ruby yet?
b
I have the same issue in PHP @Shah - support @Retell AI
c
create new ticket please
b
New to Discord - how do I create a new ticket?
c
I never saw this response... If I recall.. I just did a before_action to check if the ip was ip that is coming from Retell + that the account ID matches the one in the credentials. It's not the safest but I could never get the digests to work correctly but it's more secure than just checking the account ID. The only thing i'd say is maybe look at the repo for the sdk and then read it and try to understand what encryption and try to do it with Ruby