statamic-shopify icon indicating copy to clipboard operation
statamic-shopify copied to clipboard

Webhooks routes references incorrect VerifyCsrfToken middleware

Open leeuweriq opened this issue 1 year ago • 4 comments

Description

I tried adding webhooks for product updates, however every webhook fired from Shopify results in a http 419. Looking at the actions.php where the webhook routes are defined, I see the VerifyCsrfToken class is imported using the old FQCN: use App\Http\Middleware\VerifyCsrfToken.

This should be: \Illuminate\Foundation\Http\Middleware\VerifyCsrfToken::class

Using laravel 11.x

Steps to reproduce

  1. Open actions.php
  2. See that the wrong import statement is used on line 3.

Environment

Environment Application Name: JBC Laravel Version: 11.44.2 PHP Version: 8.4.7 Composer Version: 2.8.8 Environment: local Debug Mode: ENABLED URL: jbc-web.test Maintenance Mode: OFF Timezone: UTC Locale: en

Cache Config: NOT CACHED Events: NOT CACHED Routes: NOT CACHED Views: CACHED

Drivers Broadcasting: log Cache: file Database: sqlite Logs: stack / single Mail: postmark Queue: sync Session: file

Statamic Addons: 2 Sites: 2 (English, Dutch) Stache Watcher: Enabled (auto) Static Caching: Disabled Version: 5.55.0 PRO

Statamic Addons statamic-rad-pack/shopify: 5.3.0 statamic/seo-pro: 6.6.5

leeuweriq avatar May 19 '25 09:05 leeuweriq

update: extending the \Illuminate\Foundation\Http\Middleware\VerifyCsrfToken::class when creating the App\Http\Middleware\VerifyCsrfToken class in the hopes it would resolve the 419 issue, didn't help.

Running this: app('router')->getRoutes()->getByName('statamic.shopify.webhook.product.update')->gatherMiddleware()

Returns this: array:2 [ 0 => "web" 1 => "StatamicRadPack\Shopify\Http\Middleware\VerifyShopifyHeaders" ]

Which basically means the web middleware group is still applied (which contains the VerifyCsrfToken middleware):

Image

leeuweriq avatar May 19 '25 09:05 leeuweriq

I've opened a PR here - https://github.com/statamic-rad-pack/shopify/pull/289 - let me know if this solves your issue

ryanmitchell avatar May 20 '25 08:05 ryanmitchell

Hi Ryan, yes that works! Thanks for the quick follow-up. :)

leeuweriq avatar May 20 '25 11:05 leeuweriq

I've just tagged v5.3.1 which includes this.

ryanmitchell avatar May 20 '25 11:05 ryanmitchell