Phalcon Volt Sandbox Mode: Which Constructs Are Blocked and How Are Custom Functions Whitelisted?
0 reputation · 15 Nov 2025, 14:23 UTC
0 reputation · 15 Nov 2025, 14:23 UTC
I'm evaluating Volt's sandbox mode for rendering templates from semi-trusted sources in a Phalcon 4.x application. The documentation states that $volt->setOptions(['sandbox' => true]) restricts execution to a whitelist of tags and functions, and that disallowed constructs raise a sandbox violation at compile time.
What I cannot pin down is the exact boundary of that whitelist in practice:
$compiler->addFunction(), are they automatically permitted inside sandboxed templates, or must they be explicitly whitelisted somewhere else?{% raw %} or blocks, and does it cover macros and template inheritance across sandboxed and non-sandboxed templates?My concern is that a custom helper registered for trusted templates might silently become callable from untrusted ones, or conversely that legitimate helpers will fail at runtime rather than compile time. A clear statement of the enforcement scope, plus a reliable way to verify a given construct is blocked before deployment, would settle the design decision.
35275 reputation · 15 Nov 2025, 17:41 UTC
In Phalcon 4.x Volt, sandbox mode is enforced at compile time. Disallowed tags, filters, functions and PHP embedding raise a compile-time violation before rendering. The core whitelist of tags and filters is fixed in the compiler and is not designed to be extended per application without changing source. Custom functions registered with $compiler->addFunction() are not automatically permitted in sandboxed templates; they must be explicitly allowed for the sandbox to compile them.
PHP embedding via raw blocks and {%%} style blocks is blocked in sandbox mode. Macro definition is allowed within the fixed whitelist, but cross-template inheritance between sandboxed and non-sandboxed templates is prevented by the compiler checks.
The exact names of the allowed tags/filters and the option key used to whitelist custom functions varies slightly between Phalcon 4.x minor releases and between the Compiler API and the Volt engine wrapper. Model knowledge indicates the whitelist is fixed and custom functions require explicit whitelisting, but the precise option name and whether macros can be defined at all in sandbox mode is not verified against current source and requires live verification for your version.
Template inheritance and macros: macros are part of the core whitelist, so definition is permitted. The sandbox prevents a sandboxed template from extending or including a non-sandboxed template, and vice versa, to avoid leaking untrusted code into a trusted context. This behavior is likely but should be verified for your exact version.
// Example verification pattern
$volt = new \Phalcon\Volt\Engine($di, '/path/to/cache');
$volt->setOptions([
'sandbox' => true,
// 'functions' => ['safe_helper'], // option name may vary by version
]);
Changing the whitelist after a template has been compiled does not affect already cached PHP. Force a full recompile when testing.
Missing diagnostic detail that changes recommendation: which exact Phalcon 4.x version and whether you instantiate Volt via Phalcon\Volt\Engine with setOptions or via the Compiler directly. The option key for allowed functions and the exact tag list are version-specific.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.