Vinny
Vinny

Reputation: 3

Laravel Error 419 Page Expired or not loading the page at all after Webhook setup on Github

After I set up a webhook from my github to my laravel website, one of the pages stopped working. (Control Panel)

If I delete the webhook from Github, the page starts working again.

The symptoms are either Error 419 Page Expired or the page doesn't load at all after trying to login.

Any clues? I am thinking it might be related to VerifyCsrfToken exceptions but I don't know how I would add github webhook in there.

Image of Webhook in github

Upvotes: 0

Views: 1274

Answers (1)

PassionInfinite
PassionInfinite

Reputation: 638

Thank you Vinny for showing the photo of the Github webhooks setup. To resolve your problem you will need to do the following three steps:

  1. You need to select APPLICATION/JSON in the Content-Type option of Github Webhooks. As Laravel doesn't include VerifyCSRFToken middleware for the JSON.
  2. Make sure you are using api middleware group. To do that you need to define this endpoint in the api.php NOT in web.php.
  3. After you define you can confirm your endpoint by prefix with /api with your domain name and the path defined in your api.php

For more context, you can visit this documentation URL. https://laravel.com/docs/8.x/middleware#middleware-groups

Note: I would recommend using signature verification to avoid bad usage of your endpoint and webhook triggers. To do that you can follow this nice article.

https://dev.to/ryan1/how-to-validate-github-webhooks-with-laravel-and-php-2he1

Upvotes: 2

Related Questions