Skip to content

Commit dfd0874

Browse files
author
roman
committed
MC-13741: Fixed incorrect behavior of template variables
1 parent a3c9b91 commit dfd0874

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

lib/internal/Magento/Framework/Filter/Template.php

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
*/
1010
namespace Magento\Framework\Filter;
1111

12+
use Magento\Framework\Model\AbstractExtensibleModel;
13+
use Magento\Framework\Model\AbstractModel;
14+
1215
/**
1316
* Template filter
1417
*
@@ -66,7 +69,13 @@ class Template implements \Zend_Filter_Interface
6669
/**
6770
* @var string[]
6871
*/
69-
private $restrictedMethods = ['addafterfiltercallback'];
72+
private $restrictedMethods = [
73+
'addafterfiltercallback',
74+
'getresourcecollection',
75+
'load',
76+
'save',
77+
'getcollection'
78+
];
7079

7180
/**
7281
* @param \Magento\Framework\Stdlib\StringUtils $string
@@ -391,6 +400,27 @@ private function validateVariableMethodCall($object, string $method): void
391400
}
392401
}
393402

403+
/**
404+
* Check allowed methods for data objects.
405+
*
406+
* Deny calls for methods that may disrupt template processing.
407+
*
408+
* @param object $object
409+
* @param string $method
410+
* @return bool
411+
* @throws \InvalidArgumentException
412+
*/
413+
private function isAllowedDataObjectMethod($object, string $method): bool
414+
{
415+
if ($object instanceof AbstractExtensibleModel || $object instanceof AbstractModel) {
416+
if (in_array(mb_strtolower($method), $this->restrictedMethods)) {
417+
throw new \InvalidArgumentException("Method $method cannot be called from template.");
418+
}
419+
}
420+
421+
return true;
422+
}
423+
394424
/**
395425
* Return variable value for var construction
396426
*
@@ -429,10 +459,13 @@ protected function getVariable($value, $default = '{no_value_defined}')
429459
|| substr($stackVars[$i]['name'], 0, 3) == 'get'
430460
) {
431461
$stackVars[$i]['args'] = $this->getStackArgs($stackVars[$i]['args']);
432-
$stackVars[$i]['variable'] = call_user_func_array(
433-
[$stackVars[$i - 1]['variable'], $stackVars[$i]['name']],
434-
$stackVars[$i]['args']
435-
);
462+
463+
if ($this->isAllowedDataObjectMethod($stackVars[$i - 1]['variable'], $stackVars[$i]['name'])) {
464+
$stackVars[$i]['variable'] = call_user_func_array(
465+
[$stackVars[$i - 1]['variable'], $stackVars[$i]['name']],
466+
$stackVars[$i]['args']
467+
);
468+
}
436469
}
437470
}
438471
$last = $i;

0 commit comments

Comments
 (0)