octobercms/october · error · Twig\Sandbox\SecurityNotAllowedMethodError

Calling any method on a

Error message

Calling any method on a "%s" object is blocked.

What it means

Legacy Twig security policy checkMethodAllowed: the method name was not class-blocklisted but appears in the global blockedMethods list, so calling it on any object is denied in templates. Remove the call from the Twig code or un-block the method in the policy.

Solutions

  1. Pass the data to the template as plain variables instead of the blocked object
  2. Whitelist the class if it is trusted in this context
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at modules/system/twig/SecurityPolicyLegacy.php:121 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of octobercms/october@b608633a7e (2026-08-21). Data as JSON: /api/errors/a507fee07010d335. Report an issue: GitHub.

Appendix: source

Thrown at modules/system/twig/SecurityPolicyLegacy.php:121

    public function checkMethodAllowed($obj, $method): void
    {
        if ($obj instanceof Template || $obj instanceof Markup) {
            return;
        }

        $blockedMethod = strtr($method, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz');

        // Check objects
        foreach ($this->blockedClassMethods as $blockedClass => $blockedMethods) {
            if (is_a($obj, $blockedClass) && in_array($blockedMethod, $blockedMethods)) {
                throw new SecurityNotAllowedMethodError(sprintf('Calling "%s" method on a "%s" object is blocked.', $method, $blockedClass), $blockedClass, $method);
            }
        }

        // Check general classes
        foreach ($this->blockedClasses as $blockedClass) {
            if (is_a($obj, $blockedClass)) {
                throw new SecurityNotAllowedMethodError(sprintf('Calling any method on a "%s" object is blocked.', $blockedClass), $blockedClass, $method);
            }
        }

        // Check general methods
        if (in_array($blockedMethod, $this->blockedMethods)) {
            $class = get_class($obj);
            throw new SecurityNotAllowedMethodError(sprintf('Calling "%s" method on a "%s" object is blocked.', $method, $class), $class, $method);
        }
    }

    /**
     * checkPropertyAllowed
     * @throws SecurityNotAllowedPropertyError
     */
    public function checkPropertyAllowed($obj, $property): void
    {
        if (in_array($property, $this->blockedProperties)) {
            $class = get_class($obj);

View on GitHub (pinned to b608633a7e)