Skip to content

Commit c927205

Browse files
committed
Merge branch 'bugfix/template_object_sandbox_escape'
2 parents e66e293 + 74cab5a commit c927205

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
### Security
10+
- Prevent access to `$smarty.template_object` in Security mode
11+
912
## [3.1.38] - 2021-01-08
1013

1114
### Fixed

expectException

Whitespace-only changes.

libs/sysplugins/smarty_internal_compile_private_special_variable.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $
8181
case 'template':
8282
return 'basename($_smarty_tpl->source->filepath)';
8383
case 'template_object':
84+
if (isset($compiler->smarty->security_policy)) {
85+
$compiler->trigger_template_error("(secure mode) template_object not permitted");
86+
break;
87+
}
8488
return '$_smarty_tpl';
8589
case 'current_dir':
8690
return 'dirname($_smarty_tpl->source->filepath)';

tests/UnitTests/SecurityTests/SecurityTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,15 @@ public function testNotTrustedUri()
382382
$this->smarty->security_policy->trusted_uri = array();
383383
$this->assertContains('<title>Preface | Smarty</title>', $this->smarty->fetch('string:{fetch file="https://www.smarty.net/docs/en/preface.tpl"}'));
384384
}
385+
386+
/**
387+
* In security mode, accessing $smarty.template_object should be illegal.
388+
* @expectedException SmartyCompilerException
389+
*/
390+
public function testSmartyTemplateObject() {
391+
$this->smarty->display('string:{$smarty.template_object}');
392+
}
393+
385394
}
386395

387396
class mysecuritystaticclass

0 commit comments

Comments
 (0)