Skip to content

Commit

Permalink
Merge branch 'bugfix/template_object_sandbox_escape'
Browse files Browse the repository at this point in the history
  • Loading branch information
wisskid committed Feb 17, 2021
2 parents e66e293 + 74cab5a commit c927205
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Security
- Prevent access to `$smarty.template_object` in Security mode

## [3.1.38] - 2021-01-08

### Fixed
Expand Down
Empty file added expectException
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $
case 'template':
return 'basename($_smarty_tpl->source->filepath)';
case 'template_object':
if (isset($compiler->smarty->security_policy)) {
$compiler->trigger_template_error("(secure mode) template_object not permitted");
break;
}
return '$_smarty_tpl';
case 'current_dir':
return 'dirname($_smarty_tpl->source->filepath)';
Expand Down
9 changes: 9 additions & 0 deletions tests/UnitTests/SecurityTests/SecurityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,15 @@ public function testNotTrustedUri()
$this->smarty->security_policy->trusted_uri = array();
$this->assertContains('<title>Preface | Smarty</title>', $this->smarty->fetch('string:{fetch file="https://www.smarty.net/docs/en/preface.tpl"}'));
}

/**
* In security mode, accessing $smarty.template_object should be illegal.
* @expectedException SmartyCompilerException
*/
public function testSmartyTemplateObject() {
$this->smarty->display('string:{$smarty.template_object}');
}

}

class mysecuritystaticclass
Expand Down

0 comments on commit c927205

Please sign in to comment.