mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-03 18:04:26 +02:00
Rewrote the mailto function to not use eval
when encoding with javascript
(cherry picked from commit c7576eb1a1
)
This commit is contained in:
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Security
|
||||||
|
- Rewrote the mailto function to not use `eval` when encoding with javascript
|
||||||
|
|
||||||
## [3.1.40] - 2021-10-13
|
## [3.1.40] - 2021-10-13
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
@@ -94,22 +94,19 @@ function smarty_function_mailto($params)
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// FIXME: (rodneyrehm) document.write() excues me what? 1998 has passed!
|
|
||||||
if ($encode === 'javascript') {
|
if ($encode === 'javascript') {
|
||||||
$string = 'document.write(\'<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>\');';
|
$string = '<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>';
|
||||||
$js_encode = '';
|
$js_encode = '';
|
||||||
for ($x = 0, $_length = strlen($string); $x < $_length; $x++) {
|
for ($x = 0, $_length = strlen($string); $x < $_length; $x++) {
|
||||||
$js_encode .= '%' . bin2hex($string[ $x ]);
|
$js_encode .= '%' . bin2hex($string[ $x ]);
|
||||||
}
|
}
|
||||||
return '<script type="text/javascript">eval(unescape(\'' . $js_encode . '\'))</script>';
|
return '<script type="text/javascript">document.write(unescape(\'' . $js_encode . '\'))</script>';
|
||||||
} elseif ($encode === 'javascript_charcode') {
|
} elseif ($encode === 'javascript_charcode') {
|
||||||
$string = '<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>';
|
$string = '<a href="mailto:' . $address . '" ' . $extra . '>' . $text . '</a>';
|
||||||
for ($x = 0, $y = strlen($string); $x < $y; $x++) {
|
for ($x = 0, $_length = strlen($string); $x < $_length; $x++) {
|
||||||
$ord[] = ord($string[ $x ]);
|
$ord[] = ord($string[ $x ]);
|
||||||
}
|
}
|
||||||
$_ret = "<script type=\"text/javascript\" language=\"javascript\">\n" . "{document.write(String.fromCharCode(" .
|
return '<script type="text/javascript">document.write(String.fromCharCode(' . implode(',', $ord) . '))</script>';
|
||||||
implode(',', $ord) . "))" . "}\n" . "</script>\n";
|
|
||||||
return $_ret;
|
|
||||||
} elseif ($encode === 'hex') {
|
} elseif ($encode === 'hex') {
|
||||||
preg_match('!^(.*)(\?.*)$!', $address, $match);
|
preg_match('!^(.*)(\?.*)$!', $address, $match);
|
||||||
if (!empty($match[ 2 ])) {
|
if (!empty($match[ 2 ])) {
|
||||||
|
Reference in New Issue
Block a user