ysaxon/pyrocms-ssti-fix
Composer 安装命令:
composer require ysaxon/pyrocms-ssti-fix
包简介
Security fix for PyroCMS SSTI vulnerability (CVE-2023-29689). Applies Twig sandbox to user-editable templates.
README 文档
README
🛡️ PyroCMS SSTI Fix
Drop-in security fix for CVE-2023-29689 - Server-Side Template Injection leading to Remote Code Execution in PyroCMS 3.9.
The Problem
PyroCMS allows admin users to edit templates stored in the database. Without sandboxing, attackers with admin access can inject malicious Twig code:
{{['id']|map('system')|join}}
This executes arbitrary system commands. The upstream maintainers consider this "working as intended" since admin users are trusted - but in multi-tenant or enterprise environments, "admin" ≠ "trusted with shell access".
The Solution
This package automatically sandboxes user-editable templates while leaving legitimate theme/addon templates unrestricted. It uses Twig's SourcePolicyInterface (contributed upstream by the author of this package) to selectively apply restrictions.
Installation
composer require ysaxon/pyrocms-ssti-fix
Unfortunately, due to PyroCMS disabling autodiscovery you will need to add the serviceProvider yourself.
You can do that with
sed -i "/App\\\Providers\\\AppServiceProvider::class,/a \ YSaxon\\\PyroCmsSstiFix\\\SandboxServiceProvider::class," config/app.php
Requirements
- PHP 7.4+ or 8.0+
- Twig 2.16+ or 3.9+ (for
SourcePolicyInterfacesupport) - Laravel 6.0+ / PyroCMS 3.x
How It Works
┌─────────────────────────────────────────────────────────────┐
│ Twig Render Request │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ StorageSourcePolicy │
│ │
│ Is template from storage path (database/user-editable)? │
│ │
│ YES ──────────────────► Enable Sandbox │
│ │ - Block: map, filter, reduce │
│ │ - Block: dangerous tags │
│ │ - Whitelist safe operations │
│ │
│ NO ───────────────────► No Sandbox │
│ (Theme/addon templates work │
│ normally) │
└─────────────────────────────────────────────────────────────┘
Configuration (Optional)
Default settings are secure and work for most installations. To customize:
php artisan vendor:publish --tag=pyrocms-ssti-fix-config
This creates config/pyrocms-ssti-fix.php:
return [ // Master switch 'enabled' => env('PYROCMS_SSTI_FIX_ENABLED', true), // Override auto-detected storage path 'storage_path' => env('PYROCMS_SSTI_FIX_STORAGE_PATH', null), // Customize allowed tags/filters/functions/methods/properties 'policy' => [ 'tags' => [SecurityPolicyDefaults::INCLUDE_DEFAULTS], 'filters' => [SecurityPolicyDefaults::INCLUDE_DEFAULTS], // ... see config file for full options ], ];
What's Blocked
The default security policy blocks these dangerous features in sandboxed templates:
Filters (RCE vectors)
map-{{['cmd']|map('system')}}executes shell commandsfilter- Can call arbitrary PHP functionsreduce- Can call arbitrary PHP functions
Tags (inclusion attacks)
include,extends,block,macro,import,embed,use
Functions
source- Reads arbitrary file contentsinclude- Includes other templatestemplate_from_string- Creates templates from strings
What's Allowed
Safe operations remain available in sandboxed templates:
{# Variables #} {{ entry.title }} {{ user.name|upper }} {# Loops and conditionals #} {% for item in items %} {% if item.active %} {{ item.name }} {% endif %} {% endfor %} {# Safe filters #} {{ text|escape }} {{ date|date('Y-m-d') }} {{ items|length }} {{ name|lower|trim }} {# Safe functions #} {{ max(a, b) }} {{ random(['red', 'blue', 'green']) }}
Extending the Whitelist
If your admin templates legitimately need additional features:
// config/pyrocms-ssti-fix.php 'policy' => [ 'filters' => [ SecurityPolicyDefaults::INCLUDE_DEFAULTS, 'my_custom_filter', // Add specific filter ], 'methods' => [ SecurityPolicyDefaults::INCLUDE_DEFAULTS, 'App\Models\Post' => ['getTitle', 'getSummary'], ], ],
Testing the Fix
After installation, verify the exploit is blocked:
- Go to PyroCMS admin → Users → Roles
- Edit a role's description field
- Enter:
{{['id']|map('system')|join}} - Save and view
Before fix: Shows output of id command (or crashes)
After fix: Shows error or [rendering failed: Filter "map" is not allowed.]
Troubleshooting
"Twig not found in container"
The package couldn't find Twig. This usually means:
- PyroCMS/streams-platform isn't fully loaded yet
- You're not running in a PyroCMS environment
Enable debug mode to see details:
PYROCMS_SSTI_FIX_DEBUG=true
Legitimate templates breaking
If admin-editable templates use features that are now blocked:
- Check logs for which feature was blocked
- Add it to the whitelist in config (if safe)
- Or refactor the template to use allowed features
Performance concerns
The package caches all path checks and method/property lookups. In auto mode, only storage-path templates incur sandbox overhead.
Security Notes
- This package does not fix the underlying architectural issue (Twig rendering user input)
- It mitigates exploitation by restricting what sandboxed templates can do
- Admin users can still create annoying templates; they just can't achieve RCE
- Consider additional hardening (WAF rules, CSP, etc.) for defense in depth
Credits
- Yaakov Saxon - Package author,
SourcePolicyInterfacecontributor to Twig - Twig PR #3893 - Upstream contribution enabling selective sandbox
License
MIT License - see LICENSE file.
Related
- CVE-2023-29689 - NVD entry
- GHSA-w7vm-4v3j-vgpw - GitHub Advisory
- Twig Sandbox Documentation
ysaxon/pyrocms-ssti-fix 适用场景与选型建议
ysaxon/pyrocms-ssti-fix 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「twig」 「security」 「sandbox」 「patch」 「vulnerability」 「fix」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ysaxon/pyrocms-ssti-fix 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ysaxon/pyrocms-ssti-fix 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ysaxon/pyrocms-ssti-fix 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
This Symfony bundle integrates PhpSpreadsheet into Symfony using Twig.
A Twig extension to insert css as inline styles with a tag
Caching and compression for Twig assets (JavaScript and CSS).
Provide a way to secure accesses to all routes of an symfony application.
Twig extensions for Tracy Debugger
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 35
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-09