mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-03 01:44:26 +02:00
Merge branch 'js_escape_security_fix_31' into support/3.1
This commit is contained in:
@@ -188,7 +188,9 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $
|
|||||||
// see https://html.spec.whatwg.org/multipage/scripting.html#restrictions-for-contents-of-script-elements
|
// see https://html.spec.whatwg.org/multipage/scripting.html#restrictions-for-contents-of-script-elements
|
||||||
'<!--' => '<\!--',
|
'<!--' => '<\!--',
|
||||||
'<s' => '<\s',
|
'<s' => '<\s',
|
||||||
'<S' => '<\S'
|
'<S' => '<\S',
|
||||||
|
"`" => "\\\\`",
|
||||||
|
"\${" => "\\\\\\$\\{"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
case 'mail':
|
case 'mail':
|
||||||
|
@@ -92,7 +92,9 @@ function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompile
|
|||||||
// see https://html.spec.whatwg.org/multipage/scripting.html#restrictions-for-contents-of-script-elements
|
// see https://html.spec.whatwg.org/multipage/scripting.html#restrictions-for-contents-of-script-elements
|
||||||
return 'strtr(' .
|
return 'strtr(' .
|
||||||
$params[ 0 ] .
|
$params[ 0 ] .
|
||||||
', array("\\\\" => "\\\\\\\\", "\'" => "\\\\\'", "\"" => "\\\\\"", "\\r" => "\\\\r", "\\n" => "\\\n", "</" => "<\/", "<!--" => "<\!--", "<s" => "<\s", "<S" => "<\S" ))';
|
', array("\\\\" => "\\\\\\\\", "\'" => "\\\\\'", "\"" => "\\\\\"", "\\r" => "\\\\r",
|
||||||
|
"\\n" => "\\\n", "</" => "<\/", "<!--" => "<\!--", "<s" => "<\s", "<S" => "<\S",
|
||||||
|
"`" => "\\\\`", "\${" => "\\\\\\$\\{"))';
|
||||||
}
|
}
|
||||||
} catch (SmartyException $e) {
|
} catch (SmartyException $e) {
|
||||||
// pass through to regular plugin fallback
|
// pass through to regular plugin fallback
|
||||||
|
@@ -207,4 +207,25 @@ class PluginModifierEscapeTest extends PHPUnit_Smarty
|
|||||||
$this->assertEquals("sma'rty@»example«.com", $this->smarty->fetch($tpl));
|
$this->assertEquals("sma'rty@»example«.com", $this->smarty->fetch($tpl));
|
||||||
Smarty::$_MBSTRING = true;
|
Smarty::$_MBSTRING = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testTemplateLiteralBackticks()
|
||||||
|
{
|
||||||
|
$tpl = $this->smarty->createTemplate('string:{"`Hello, World!`"|escape:"javascript"}');
|
||||||
|
$this->assertEquals("\\`Hello, World!\\`", $this->smarty->fetch($tpl));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testTemplateLiteralInterpolation()
|
||||||
|
{
|
||||||
|
$tpl = $this->smarty->createTemplate('string:{$vector|escape:"javascript"}');
|
||||||
|
$this->smarty->assign('vector', "`Hello, \${name}!`");
|
||||||
|
$this->assertEquals("\\`Hello, \\\$\\{name}!\\`", $this->smarty->fetch($tpl));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testTemplateLiteralBackticksAndInterpolation()
|
||||||
|
{
|
||||||
|
$this->smarty->assign('vector', '`${alert(`Hello, ${name}!`)}${`\n`}`');
|
||||||
|
$tpl = $this->smarty->createTemplate('string:{$vector|escape:"javascript"}');
|
||||||
|
$this->assertEquals("\\`\\\$\\{alert(\\`Hello, \\\$\\{name}!\\`)}\\\$\\{\\`\\\\n\\`}\\`", $this->smarty->fetch($tpl));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
2
tests/UnitTests/TemplateSource/ValueTests/Operators/templates_c/.gitignore
vendored
Normal file
2
tests/UnitTests/TemplateSource/ValueTests/Operators/templates_c/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# Ignore anything in here, but keep this directory
|
||||||
|
*
|
Reference in New Issue
Block a user