@@ -52,6 +52,11 @@ class Template implements \Zend_Filter_Interface
52
52
*/
53
53
protected $ string ;
54
54
55
+ /**
56
+ * @var string[]
57
+ */
58
+ private $ restrictedMethods = ['addafterfiltercallback ' ];
59
+
55
60
/**
56
61
* @param \Magento\Framework\Stdlib\StringUtils $string
57
62
* @param array $variables
@@ -297,6 +302,25 @@ protected function getParameters($value)
297
302
return $ params ;
298
303
}
299
304
305
+ /**
306
+ * Validate method call initiated in a template.
307
+ *
308
+ * Deny calls for methods that may disrupt template processing.
309
+ *
310
+ * @param object $object
311
+ * @param string $method
312
+ * @return void
313
+ * @throws \InvalidArgumentException
314
+ */
315
+ private function validateVariableMethodCall ($ object , string $ method )
316
+ {
317
+ if ($ object === $ this ) {
318
+ if (in_array (mb_strtolower ($ method ), $ this ->restrictedMethods )) {
319
+ throw new \InvalidArgumentException ("Method $ method cannot be called from template. " );
320
+ }
321
+ }
322
+ }
323
+
300
324
/**
301
325
* Return variable value for var construction
302
326
*
@@ -345,12 +369,12 @@ protected function getVariable($value, $default = '{no_value_defined}')
345
369
$ last = $ i ;
346
370
} elseif (isset ($ stackVars [$ i - 1 ]['variable ' ]) && $ stackVars [$ i ]['type ' ] == 'method ' ) {
347
371
// Calling object methods
348
- if ( method_exists ( $ stackVars [$ i - 1 ]['variable ' ], $ stackVars [ $ i ][ ' name ' ])) {
349
- $ stackVars [ $ i ][ ' args ' ] = $ this -> getStackArgs ( $ stackVars [$ i ]['args ' ]) ;
350
- $ stackVars [ $ i ][ ' variable ' ] = call_user_func_array (
351
- [ $ stackVars [ $ i - 1 ][ ' variable ' ], $ stackVars [$ i ]['name ' ]],
352
- $ stackVars [ $ i ][ ' args ' ]
353
- );
372
+ $ object = $ stackVars [$ i - 1 ]['variable ' ];
373
+ $ method = $ stackVars [$ i ]['name ' ] ;
374
+ if ( method_exists ( $ object , $ method )) {
375
+ $ args = $ this -> getStackArgs ( $ stackVars [$ i ]['args ' ]);
376
+ $ this -> validateVariableMethodCall ( $ object , $ method );
377
+ $ stackVars [ $ i ][ ' variable ' ] = call_user_func_array ([ $ object , $ method ], $ args );
354
378
}
355
379
$ last = $ i ;
356
380
}
0 commit comments