Skip to content

v6 with adapter - compatibility - #102

Merged
riasvdv merged 12 commits into
3.xfrom
feature/for-v6-with-adapter-package
Nov 10, 2026
Merged

riasvdv merged 12 commits into
3.xfrom
feature/for-v6-with-adapter-package

Conversation

@i-just

@i-just i-just commented May 7, 2026 •

Copy link
Copy Markdown
Contributor

Description

Makes Webhooks 3.x work on Craft 6 through the craftcms/yii2-adapter package, alongside Craft 4 and 5.

composer.json        craftcms/cms ^4.17.0|^5.9.0  →  ^4.17.0|^5.9.0|^6.0.0-alpha.1
                     merged 3.x, so the 3.3.0/3.4.0 SSRF fixes and url-validator ^1.2 are kept
Twig templates       event passed as an array (Craft 6’s sandbox rejects yii\base\Event objects)
console/queue        requests pushed right away (Craft 6 only fires EVENT_AFTER_REQUEST for web requests)
default payload      Yiisoft ArrayableInterface handled, so Carbon dates and extra sender attributes work
Edit Webhook         event suggestions no longer require yii\base\Component; JS waits for Craft.whenReady
index / Activity     <craft-switch> status toggle works; .hidden override so the spinner stops covering filters
composer.lock        url-validator 1.2.0 (3.x’s lock still had 1.1.0)
#95 (merged in)      url columns → mediumtext, so URLs can be longer than 255 characters; new installs too
#98 (merged in)      the install migration archives existing tables instead of dropping them

#95 and #98 are merged in with their original commits, so they'll show as merged when this PR is. The schema version is now 2.4.1, so Craft runs #95’s migration on update.

Craft’s Migration::archiveTableIfExists() truncates archived names to 10 characters on Craft 4 and 5 (webhookgroups → webhoo_old, then webhooks → webho_old1). The data is kept, but the names don’t say which table is which. That’s a core bug, fixed on 6.x in craftcms/cms 87a3271, where they archive as webhooks_old and so on, and on 5.x in craftcms/cms#20484.

Craft 6 always renders these templates in the Twig sandbox, which doesn’t allow json_encode. The README’s payload example now writes the JSON out, escaping strings with |e('js'), and warns against allowing json_encode: it can output properties of objects the sandbox otherwise hides, such as a relation field’s source element. A webhook whose template fails to render is now logged and skipped. Before, the error stopped the action that triggered it, such as saving an entry.

The native Craft 6 release, without the adapter, is #108 (4.x).

Evidence

Run on craftcms/cms 6.x 2e1929f with yii2-adapter 6bbbf5e, against a local receiver (no external services):

  • ECS, PHPStan and Prettier pass.
  • Install, and saving webhooks with URL validation: private and loopback hosts are rejected, allowedPrivateHosts works, and unknown events are rejected.
  • Entry afterSave, Elements::afterSaveElement, entry afterDelete (a GET to an env var URL) and user afterSave webhooks fire, and draft filters work.
  • Delivery: a 500 is retried up to maxAttempts, a redirect to 169.254.169.254 is blocked, $ENV headers are parsed when sent, debounce merges requests, and garbage collection purges old ones.
  • A user with accessPlugin-webhooks gets 200 and one with only accessCp gets 403. Settings save to project config.
  • In the browser: saving filters, the index status toggle, the Activity slideout and redeliver.
  • With a webhook whose payload uses json_encode still enabled, saving an entry now succeeds and logs Unable to trigger webhook “Failing”: Filter "json_encode" is not allowed. Before this change, the same save threw that error. The README’s new payload example delivered application/json with a title containing quotes, a backslash, </script> and an emoji intact.
  • Adds migration to increase length of url column #95 and Archive tables in install migration #98, on craftcms/cms fd1763f: craft:up ran Adds migration to increase length of url column #95’s migration and changed both url columns from varchar(255) to text. A 364-character URL saved from the CP, and the request reached the receiver with its query string intact (200). Running the install migration over a copy of the database kept all 5 webhooks, 19 requests and 1 group in archived tables, and the new tables accepted a webhook with a 300+ character URL.

libordan and others added 6 commits September 1, 2024 11:45
- 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>
riasvdv and others added 5 commits November 8, 2026 16:00
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
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
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
@riasvdv
riasvdv marked this pull request as ready for review November 9, 2026 17:55
@riasvdv
riasvdv requested a review from brandonkelly as a code owner November 9, 2026 17:55
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
@riasvdv
riasvdv merged commit cd223df into 3.x Nov 10, 2026
8 checks passed
@riasvdv
riasvdv deleted the feature/for-v6-with-adapter-package branch November 10, 2026 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants