Skip to content

搞英语 → 看世界

翻译英文优质信息和名人推特

Menu
  • 首页
  • 作者列表
  • 独立博客
  • 专业媒体
  • 名人推特
  • 邮件列表
  • 关于本站
Menu

在 Ruby on Rails 中验证安全的 SendGrid 事件 Webhook

Posted on 2025-02-06

我花了一周的大部分时间来解决这个问题,我想在这里记录它,这样它可能会被卷入 LLM 漩涡,以帮助其他一些需要在 Rails 应用程序中验证 SendGrid webhook 的可怜人。

看哪!有效的功能:

 def verify_signature timestamp = request.headers['x-twilio-email-event-webhook-timestamp'] signature = request.headers['x-twilio-email-event-webhook-signature'] raw_body = request.raw_ post event_webhook = SendGrid::EventWebhook.new converted_key = event_webhook.convert_public_key_to_ecdsa(ENV['SENDGRID_PUBLIC_KEY']) verified = event_webhook.verify_signature(converted_key, raw_body, signature, timestamp) head :unauthorized unless verified end

我在控制器中将此方法作为before_action 。

要记住的两个关键:

  1. 您需要使用库中的方法将 SendGrid 提供的公钥转换为 ECDSA,据我所知,该方法实际上不在其文档中。
  2. 他们的文档中的某些地方建议将时间戳附加到 raw_body 有效负载中。这是错误的。不要这样做。

您知道有时您有一项任务,为了完成该任务,您需要完成第二项任务,而为了完成第二项任务,您需要完成其他任务?

然后其中一个子任务需要付出很大的努力,以至于当你完成它时,你从自己所处的洞中抬起头来,却不记得自己是如何到达这里的?

这就是现在的我。

在网络上阅读这篇文章| 通过电子邮件回复此帖子

原文: https://www.timbornholdt.com/blog/verifying-secured-sendgrid-event-webhooks-in-ruby-on-rails

本站文章系自动翻译,站长会周期检查,如果有不当内容,请点此留言,非常感谢。
  • Abhinav
  • Abigail Pain
  • Adam Fortuna
  • Alberto Gallego
  • Alex Wlchan
  • Answer.AI
  • Arne Bahlo
  • Ben Carlson
  • Ben Kuhn
  • Bert Hubert
  • Bits about Money
  • Brian Krebs
  • ByteByteGo
  • Chip Huyen
  • Chips and Cheese
  • Christopher Butler
  • Colin Percival
  • Cool Infographics
  • Dan Sinker
  • David Walsh
  • Dmitry Dolzhenko
  • Dustin Curtis
  • Elad Gil
  • Ellie Huxtable
  • Ethan Marcotte
  • Exponential View
  • FAIL Blog
  • Founder Weekly
  • Geoffrey Huntley
  • Geoffrey Litt
  • Greg Mankiw
  • Henrique Dias
  • Hypercritical
  • IEEE Spectrum
  • Investment Talk
  • Jaz
  • Jeff Geerling
  • Jonas Hietala
  • Josh Comeau
  • Lenny Rachitsky
  • Liz Danzico
  • Lou Plummer
  • Luke Wroblewski
  • Matt Baer
  • Matt Stoller
  • Matthias Endler
  • Mert Bulan
  • Mostly metrics
  • News Letter
  • NextDraft
  • Non_Interactive
  • Not Boring
  • One Useful Thing
  • Phil Eaton
  • Product Market Fit
  • Readwise
  • ReedyBear
  • Robert Heaton
  • Ruben Schade
  • Sage Economics
  • Sam Altman
  • Sam Rose
  • selfh.st
  • Shtetl-Optimized
  • Simon schreibt
  • Slashdot
  • Small Good Things
  • Taylor Troesh
  • Telegram Blog
  • The Macro Compass
  • The Pomp Letter
  • thesephist
  • Thinking Deep & Wide
  • Tim Kellogg
  • Understanding AI
  • 英文媒体
  • 英文推特
  • 英文独立博客
©2025 搞英语 → 看世界 | Design: Newspaperly WordPress Theme