# mailgun webhooks 路由上的无效真实性令牌错误

**URL:** <https://meta.discourse.org/t/invalid-authenticity-token-error-on-mailgun-webhooks-route/228412>\
**Category:** Bug\
**Created:** [2022年五月30日 02:47 UTC](https://meta.discourse.org/t/invalid-authenticity-token-error-on-mailgun-webhooks-route/228412 "2022-05-30T02:47:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wolftallemo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/wolftallemo/32/289645_2.png) [@Wolftallemo](https://meta.discourse.org/u/Wolftallemo)\
**Post date:** [2022年五月30日 02:47 UTC](https://meta.discourse.org/t/invalid-authenticity-token-error-on-mailgun-webhooks-route/228412/1 "2022-05-30T02:47:05Z")

</div>

向 `/webhooks/mailgun` 发送的任何 POST 请求都返回 HTTP 422，并且服务器日志显示 `ActionController::InvalidAuthenticityToken` 错误。这是在新安装且没有任何插件的情况下进行测试的。

 ![image](https://global.discourse-cdn.com/meta/original/4X/b/7/b/b7b6eb114b5c4e69653fe881b9c72123aa749ce7.png)

根据我主论坛的日志，这种情况大约从五月中旬开始出现。

---

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [2022年五月30日 11:56 UTC](https://meta.discourse.org/t/invalid-authenticity-token-error-on-mailgun-webhooks-route/228412/2 "2022-05-30T11:56:07Z")

</div>

您确定API密钥有效吗？

---

<div class="post-metadata">

**Author:** ![Wolftallemo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/wolftallemo/32/289645_2.png) [@Wolftallemo](https://meta.discourse.org/u/Wolftallemo)\
**Post date:** [2022年五月30日 18:31 UTC](https://meta.discourse.org/t/invalid-authenticity-token-error-on-mailgun-webhooks-route/228412/3 "2022-05-30T18:31:40Z")

</div>

是的，我已经检查了密钥，它绝对有效。

---

<div class="post-metadata">

**Author:** ![Wolftallemo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/wolftallemo/32/289645_2.png) [@Wolftallemo](https://meta.discourse.org/u/Wolftallemo)\
**Post date:** [2022年五月30日 18:54 UTC](https://meta.discourse.org/t/invalid-authenticity-token-error-on-mailgun-webhooks-route/228412/4 "2022-05-30T18:54:13Z")

</div>

我并不认为这与密钥是否有效有关（除非无效密钥会因某种原因导致 CSRF 错误）

---

<div class="post-metadata">

**Author:** ![znedw](https://avatars.discourse-cdn.com/v4/letter/z/b5e925/32.png) [@znedw](https://meta.discourse.org/u/znedw)\
**Post date:** [2022年六月10日 00:55 UTC](https://meta.discourse.org/t/invalid-authenticity-token-error-on-mailgun-webhooks-route/228412/6 "2022-06-10T00:55:31Z")

</div>

[https://meta.discourse.org/t/handling-bouncing-e-mails/45343/189?u=znedw](https://meta.discourse.org/t/handling-bouncing-e-mails/45343/189?u=znedw)

使用 AWS webhook 时也遇到了同样的问题，我使用的是构建版本 [99b0578b4ce](https://github.com/discourse/discourse/commits/99b0578b4ce6849eb7115c7ac5ce3baceb3cd7e9)

---

<div class="post-metadata">

**Author:** ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)\
**Post date:** [2022年六月13日 14:38 UTC](https://meta.discourse.org/t/invalid-authenticity-token-error-on-mailgun-webhooks-route/228412/8 "2022-06-13T14:38:03Z")

</div>

感谢您的 PR @Wolftallemo - 我刚刚合并了它，并在提交消息中添加了一些额外信息：

> <https://github.com/discourse/discourse/commit/be556ef17b71bf30c95a4622fa1a792e04887b19>
>
> The \`WebhookController\` inherits directly from \`ActionController::Base\`. Since R…ails 5.2, forgery protection has been enabled by default. When we applied those new defaults in 0403a8633bdedfe497ec3e2fe5d03e17940d6f16, it took effect on this controller and broke integrations.
> 
> This commit explicitly disables CSRF protection on these webhook routes, and updates the specs so they'll catch this kind of regression in future.

---

<div class="post-metadata">

**Author:** ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)\
**Post date:** [2022年六月20日 07:00 UTC](https://meta.discourse.org/t/invalid-authenticity-token-error-on-mailgun-webhooks-route/228412/9 "2022-06-20T07:00:08Z")

</div>

此主题已自动关闭，已有 6 天。不允许回复。
