Repository navigation
Webhooks 4.0 for Craft 6 (native) - #108
Merged
Merged
Conversation
Amp-Thread-ID: https://ampcode.com/threads/T-01a1bb52-1bc2-7562-8c0c-c85c057b73a4 Co-authored-by: Amp <amp@ampcode.com>
- Pass sandboxed Twig templates the event’s properties as an array on Craft 6, whose sandbox no longer allows yii\base\Event objects - Push request jobs right away from console requests on Craft 6, which only triggers EVENT_AFTER_REQUEST for web requests - Convert Craft 6 components (Yiisoft\Arrays\ArrayableInterface) with toArray() so payload dates and extra attributes work - Suggest events for Craft 6 element classes, which aren’t yii\base\Component subclasses - Initialize CP scripts with Craft.whenReady() on bridged screens - Support <craft-switch> lightswitches on the Webhooks index page - Keep .hidden working for the filter pane and spinner - Update craftcms/url-validator in composer.lock to satisfy ^1.2 - Document the json_encode sandbox requirement for payload templates Amp-Thread-ID: https://ampcode.com/threads/T-01a1bb52-1bc2-7562-8c0c-c85c057b73a4 Co-authored-by: Amp <amp@ampcode.com>
Structural only: file contents change in the next commit. Amp-Thread-ID: https://ampcode.com/threads/T-01a1bb52-1bc2-7562-8c0c-c85c057b73a4 Co-authored-by: Amp <amp@ampcode.com>
Webhooks listen for Laravel event classes, with an optional subject class, and send requests with Laravel's HTTP client from queue jobs. URLs and redirects are still validated against SSRF and pinned to the validated IPs. The control panel pages are built with Craft's UI components, and a migration converts Craft 5 element and service events. The Yii-era JS tooling, ECS and DDEV config are removed; none of them run on Craft 6. Amp-Thread-ID: https://ampcode.com/threads/T-01a1bb52-1bc2-7562-8c0c-c85c057b73a4 Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a1bb52-1bc2-7562-8c0c-c85c057b73a4 Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a1bb52-1bc2-7562-8c0c-c85c057b73a4 Co-authored-by: Amp <amp@ampcode.com>
The shared PHPStan job reports Http::create() as undefined, because Larastan doesn't see the macro Craft registers when it boots. Amp-Thread-ID: https://ampcode.com/threads/T-01a1bb52-1bc2-7562-8c0c-c85c057b73a4 Co-authored-by: Amp <amp@ampcode.com>
craftcms/cms 5c6ff68 defaults PluginTestCase's user model to Craft's, and
lets the Twig sandbox convert dates to strings, so now|date('c') works in
payload templates again.
Amp-Thread-ID: https://ampcode.com/threads/T-01a1bb52-1bc2-7562-8c0c-c85c057b73a4
Co-authored-by: Amp <amp@ampcode.com>
Ports two open 3.x pull requests: - #95: the url columns on webhooks and webhookrequests are now mediumtext, with a migration for existing installs, and saving a webhook no longer limits its URL to 255 characters. - #98: the install migration archives tables left over from a previous install with Craft's Migration::archiveTableIfExists(), instead of dropping them. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a1bb52-1bc2-7562-8c0c-c85c057b73a4
New installs now create the url columns as mediumtext too, and the schema version bump makes Craft run the url length migration on update. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a1bb52-1bc2-7562-8c0c-c85c057b73a4
Picks up archiveTableIfExists() keeping archived names within the database's identifier length limit. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a1bb52-1bc2-7562-8c0c-c85c057b73a4
Allowing json_encode lets sandboxed templates output public properties
of objects the sandbox otherwise hides, such as element queries and
their source elements, including a user's password hash right after it
changes. The README's payload example now writes the JSON out, escaping
string values with |e('js').
Amp-Thread-ID: https://ampcode.com/threads/T-01a1bb52-1bc2-7562-8c0c-c85c057b73a4
Co-authored-by: Amp <amp@ampcode.com>
[ci skip]
Amp-Thread-ID: https://ampcode.com/threads/T-01a1bb52-1bc2-7562-8c0c-c85c057b73a4
Co-authored-by: Amp <amp@ampcode.com>
A webhook template that failed to render threw from the event handler, so it stopped the action that triggered it, such as saving an entry. On Craft 6, payload templates that use json_encode always fail, because the Twig sandbox doesn't allow it. Errors are now logged and the webhook is skipped, as in Webhooks 4. Allowing json_encode in the sandbox lets templates output public properties of objects the sandbox otherwise hides, so the README no longer suggests it. Its payload example writes the JSON out instead. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a1bb52-1bc2-7562-8c0c-c85c057b73a4
brandonkelly
approved these changes
Nov 9, 2026
Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a1bb52-1bc2-7562-8c0c-c85c057b73a4
Craft 4 and 5 requirements are unchanged. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a1bb52-1bc2-7562-8c0c-c85c057b73a4
Craft 6 renders autosuggest inputs as comboboxes that ignore the
template's Vue methods, so Sender Class and Event Name listed nothing.
The controller now passes the suggestions in, and the Event Name list is
reloaded when the sender class changes.
The filter buttons used a "checkmark" icon that doesn't exist on any
version ("check" does), and Craft 6 doesn't style the ignore button's
status dot or align the buttons. Filter labels were centered by Craft 6's
table header styles.
Craft 6 slideouts have no padding and no $container property, so request
details were cut off and the Redeliver and Send now buttons were never
bound.
Craft 6-only styles are scoped to .cp-legacy-screen, so Craft 4 and 5
are unchanged.
Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a1bb52-1bc2-7562-8c0c-c85c057b73a4
…kage v6 with adapter - compatibility
Amp-Thread-ID: https://ampcode.com/threads/T-01a1bb52-1bc2-7562-8c0c-c85c057b73a4 Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a1bb52-1bc2-7562-8c0c-c85c057b73a4 Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a1bb52-1bc2-7562-8c0c-c85c057b73a4 Co-authored-by: Amp <amp@ampcode.com>
Brings in the 3.5.0 and 3.5.1 release notes. Their code changes were for the Yii 2 adapter, and the native port already covers them, so the branch's files are kept. [ci skip] Amp-Thread-ID: https://ampcode.com/threads/T-01a1c610-2b0e-771b-aa95-71df6e96ced3 Co-authored-by: Amp <amp@ampcode.com>
The URL validator is now created the first time a URL is validated. Before, the plugin created it while booting, so a typo such as `foo*` made every request and Artisan command fail. Now sending logs the error and marks the request as failed, and saving a webhook shows it as a URL error. Amp-Thread-ID: https://ampcode.com/threads/T-01a1c610-2b0e-771b-aa95-71df6e96ced3 Co-authored-by: Amp <amp@ampcode.com>
Deleting a pending request made its queued job fail. Bulk delete now keeps requests that haven't been sent yet, and a job whose request was deleted exits without retrying. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A `handler` request option replaced Laravel's handler stack, so the URL validation middleware never ran. The custom handler now goes at the bottom of the stack instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Filters set to “No” were disabling other filters too, and a disabled filter could be left set to “Yes” or “No”. As in 3.x, only a “Yes” filter disables the filters it excludes, and those are reset to “Any”. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Retake the Edit Webhook, Event Filters and Custom Headers screenshots on Craft CMS 6.0.0-beta.1, with event filters ordered No, Any, Yes. The README now says only a filter set to “Yes” disables the ones it conflicts with, as 0c82a47 changed. Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a1bb52-1bc2-7562-8c0c-c85c057b73a4
Amp-Thread-ID: https://ampcode.com/threads/T-01a1bb52-1bc2-7562-8c0c-c85c057b73a4 Co-authored-by: Amp <amp@ampcode.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Webhooks 4.0: a native Craft 6 plugin. It no longer needs
craftcms/yii2-adapteror Yii.On upgrade, a migration converts Craft 5 webhooks: element
afterSave/afterDelete/… becomeElementLifecycle*events with the element as subject class,ElementsandUsersservice events become their Laravel event classes, and filter class names are renamed. Webhooks whose event has no Craft 6 equivalent are disabled and logged. SeeUPGRADE.md.This also includes two open 3.x pull requests:
urlcolumns are nowmediumtext, with a migration for existing installs, so URLs can be longer than 255 characters.webhooks_old, …) instead of dropping them, with the new coreMigration::archiveTableIfExists()(craftcms/cmsfd1763f, the native version of Craft 5’s method).Craft 6 always renders templates in the Twig sandbox, and the sandbox doesn’t allow
json_encode,atomorclassName(). The README’s payload example now writes the JSON out, escaping strings with|e('js'), and the docs warn against allowingjson_encode: it can output properties of objects the sandbox otherwise hides, such as a relation field’s source element. Saving a webhook reports sandbox violations instead of failing later in the queue, and a template that still fails is logged without stopping the action that triggered it.Spatie:
laravel-webhook-server4.x signs and retries one-off calls, but Webhooks needs a stored request log for the Activity page, debounce, redeliver, env vars parsed at send time, Twig URLs and headers, and SSRF validation on every redirect hop. It doesn’t sign requests either. Adding it would mean wrapping or bypassing most of it, so this uses Laravel’s HTTP client and queue directly.laravel-webhook-clientreceives webhooks, so it doesn’t apply.The 3.x release that runs on Craft 6 through the adapter is #102.
Evidence
Run against craftcms/cms 6.x
31ad9f1,2e1929f,5c6ff68andfd1763f, with a local receiver. The lock now pinsc48add6, which keeps archived table names within the database’s length limit; the tests, Pint and Larastan pass on it.5c6ff68lets the sandbox convert dates to strings, sonow|date('c')works in payload templates, and defaultsPluginTestCase’s user model to Craft’s. No external webhook services were called.composer test: 23 passed on SQLite and on MySQL 8.4. Each check was confirmed by breaking it: no retry, no SSRF middleware, no debounce, unsandboxed validation. Pint and Larastan pass.169.254.169.254is blocked. Garbage collection purges old requests. Redeliver, the index status toggle, groups and settings (saved to project config) work in the browser. A user withaccessPlugin-webhooksgets 200 and one with onlyaccessCpgets 403.composer updatethe adapter and Yii are removed, andcraft:upruns the conversion migration. The four existing webhooks were converted and keep delivering, an unmappable one was disabled with a warning, and request history was kept.urlcolumns fromvarchar(255)totext, and running the install migration again moved the 7 webhooks and 27 requests to_oldtables. Their indexes, sequences and foreign keys were renamed or pointed at the other_oldtables, and the new tables accept rows. The core helper’s own test passes on SQLite, MySQL and PostgreSQL, with and without a table prefix.Not yet done: delivery to a real external endpoint (Zapier, Netlify).