mirror of
https://github.com/smarty-php/smarty.git
synced 2026-08-07 05:54:15 +02:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 217d8b7445 |
@@ -0,0 +1 @@
|
||||
- Security: prevent SSRF bypass of `trusted_uri` via redirect-following in `{fetch}`. When a security policy is active, the HTTP stream wrapper no longer auto-follows redirects, so an Open Redirect on a trusted host can no longer be used to reach arbitrary URIs. Reported by Aleksey Solovev (Positive Technologies), PT-03-2026.
|
||||
@@ -189,7 +189,19 @@ class Fetch extends Base {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
$content = @file_get_contents($params['file']);
|
||||
$context = null;
|
||||
if (isset($template->getSmarty()->security_policy)) {
|
||||
// When a security policy is active, the trusted_uri check only validates
|
||||
// the URL passed to {fetch}. PHP's HTTP stream wrapper follows redirects
|
||||
// by default, which would let an Open Redirect on a trusted host bypass
|
||||
// the policy and reach arbitrary internal addresses (SSRF). Disable
|
||||
// redirect following for the policy-checked request. See PT-03-2026.
|
||||
$context = stream_context_create([
|
||||
'http' => ['follow_location' => 0, 'max_redirects' => 1],
|
||||
'https' => ['follow_location' => 0, 'max_redirects' => 1],
|
||||
]);
|
||||
}
|
||||
$content = @file_get_contents($params['file'], false, $context);
|
||||
if ($content === false) {
|
||||
throw new Exception("{fetch} cannot read resource '" . $params['file'] . "'");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user