ysaxon / pyrocms-ssti-fix
Security fix for PyroCMS SSTI vulnerability (CVE-2023-29689). Applies Twig sandbox to user-editable templates.
Requires
- php: ^7.4 || ^8.0
- illuminate/support: ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0
- twig/twig: ^2.16 || ^3.9
Requires (Dev)
- phpunit/phpunit: ^9.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-02 17:32:51 UTC
README
🛡️ PyroCMS SSTI Fix
Drop-in mitigation for CVE-2023-29689 — Server-Side Template Injection → RCE in PyroCMS 3.x.
The original approach and code as well as the enabling upstream PR in Twig are my own. Packaging and some refinement were done by Claude.
Update (v0.2):
This package now also fixes CVE-2026-46633, a Twig core vuln with no upstream fix on the 2.x line PyroCMS is pinned to. On reviewing this package, Claude noticed that CVE and added ParseTimeSandbox to block extends and use at compile time, before Twig's runtime sandbox would ever see them. I've only lightly reviewed it. See the Claude written SECURITY.md.
One more problem this package does not fix by default is that PyroCMS's img() function can republish any image file the web server can read, even outside the webroot, and works as a path oracle, because it errors differently depending on whether a file is missing, exists but isn't an image, or is an image. It can be blocked with one config switch (see Config), but that breaks PyroCMS functionality that relies on it, so it is allowed by default.
This package is intended to mitigate the SSTI risks of PyroCMS while still leaving it usable, but ultimately, replacing Pyro with something more modern might be a safer option.
The Problem
PyroCMS lets admins edit Twig templates that are stored in the database and rendered server-side. But many Twig features can be abused for exploits.
Here is a simple RCE demo:
{{ ['id']|map('system')|join }}
This executes id and returns the result wherever the template is rendered.
Twig has a security sandbox configuration available, but applying it breaks a bunch of tags necessary for PyroCMS to function.
The Solution
This package automatically sandboxes user-editable templates while leaving static theme/addon templates unrestricted, using Twig's SourcePolicyInterface, which I contributed upstream, to selectively apply restrictions.
Installation
composer require ysaxon/pyrocms-ssti-fix
Requires Twig 2.16+ or 3.9+ (the versions with SourcePolicyInterface). PyroCMS 3.x ships Twig 2.x; Composer will upgrade it within 2.x if needed.
PyroCMS disables package auto-discovery,
so register the provider manually in config/app.php:
sed -i "/App\\\Providers\\\AppServiceProvider::class,/a \ YSaxon\\\PyroCmsSstiFix\\\SandboxServiceProvider::class," config/app.php
or edit it in yourself.
Config (optional)
Defaults are an attempt to balance security with drop-in-usability.
php artisan vendor:publish --tag=pyrocms-ssti-fix-config
This creates config/pyrocms-ssti-fix.php. For each part of the policy you can keep SecurityPolicyDefaults::INCLUDE_DEFAULTS and add to it to make it more permissive, or remove that token and specify only what you want to allow to make it more restrictive. You can use asterisks as wildcards on class or method names, e.g. to whitelist all method names starting with some prefix, as the default policy does for get*, has*, and is*.
'policy' => [ 'methods' => [ SecurityPolicyDefaults::INCLUDE_DEFAULTS, 'App\Models\Post' => ['methodSafeForThisObject', 'safePrefix*'], '*' => ['alwaysSafeEverywhere'] ], ],
Important: don't add map, filter, reduce, or sort back to the allowed filters. You might assume Twig's sandbox still stops the dangerous form ({{ x|map('system') }}) via its rule that such callbacks must be closures — but CVE-2026-24425, a flaw in my own SourcePolicyInterface implementation, means that guard doesn't fire when the sandbox is enabled by source policy, and Twig 2.x (what PyroCMS pins) has no fix. So long as those filters are blocked, it's no problem, which is also why I never realized the vulnerability originally, but if they are unblocked, you get RCE again, so just don't unblock them.
Also note that for drop-in usability, the img function is allowed by default, which can still pose arbitrary-image-read and path-oracle vulnerabilities (see SECURITY.md) if templates are edited by a malicious user. To disable it, set PYROCMS_SSTI_FIX_IMG=block in .env (or 'img' => 'block' in the published config).
Post install validation
Admin → Users → Roles, put {{ ['id']|map('system')|join }} in a role
description. With the fix applied, you should see an error mentioning Filter "map" is not allowed
instead of command output.