@@ -63,6 +63,11 @@ class Template implements \Zend_Filter_Interface
63
63
*/
64
64
protected $ string ;
65
65
66
+ /**
67
+ * @var string[]
68
+ */
69
+ private $ restrictedMethods = ['addafterfiltercallback ' ];
70
+
66
71
/**
67
72
* @param \Magento\Framework\Stdlib\StringUtils $string
68
73
* @param array $variables
@@ -367,6 +372,25 @@ protected function getParameters($value)
367
372
return $ params ;
368
373
}
369
374
375
+ /**
376
+ * Validate method call initiated in a template.
377
+ *
378
+ * Deny calls for methods that may disrupt template processing.
379
+ *
380
+ * @param object $object
381
+ * @param string $method
382
+ * @return void
383
+ * @throws \InvalidArgumentException
384
+ */
385
+ private function validateVariableMethodCall ($ object , string $ method ): void
386
+ {
387
+ if ($ object === $ this ) {
388
+ if (in_array (mb_strtolower ($ method ), $ this ->restrictedMethods )) {
389
+ throw new \InvalidArgumentException ("Method $ method cannot be called from template. " );
390
+ }
391
+ }
392
+ }
393
+
370
394
/**
371
395
* Return variable value for var construction
372
396
*
@@ -414,12 +438,12 @@ protected function getVariable($value, $default = '{no_value_defined}')
414
438
$ last = $ i ;
415
439
} elseif (isset ($ stackVars [$ i - 1 ]['variable ' ]) && $ stackVars [$ i ]['type ' ] == 'method ' ) {
416
440
// Calling object methods
417
- if ( method_exists ( $ stackVars [$ i - 1 ]['variable ' ], $ stackVars [ $ i ][ ' name ' ])) {
418
- $ stackVars [ $ i ][ ' args ' ] = $ this -> getStackArgs ( $ stackVars [$ i ]['args ' ]) ;
419
- $ stackVars [ $ i ][ ' variable ' ] = call_user_func_array (
420
- [ $ stackVars [ $ i - 1 ][ ' variable ' ], $ stackVars [$ i ]['name ' ]],
421
- $ stackVars [ $ i ][ ' args ' ]
422
- );
441
+ $ object = $ stackVars [$ i - 1 ]['variable ' ];
442
+ $ method = $ stackVars [$ i ]['name ' ] ;
443
+ if ( method_exists ( $ object , $ method )) {
444
+ $ args = $ this -> getStackArgs ( $ stackVars [$ i ]['args ' ]);
445
+ $ this -> validateVariableMethodCall ( $ object , $ method );
446
+ $ stackVars [ $ i ][ ' variable ' ] = call_user_func_array ([ $ object , $ method ], $ args );
423
447
}
424
448
$ last = $ i ;
425
449
}
0 commit comments