Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4a1e82d

Browse files
committed
Latte: security fix for escaping inside <script>, prevents "Script data escape start state"
http://www.whatwg.org/specs/web-apps/current-work/multipage/tokenization.html#script-data-escape-start-state
1 parent 4d40622 commit 4a1e82d

7 files changed

Lines changed: 14 additions & 14 deletions

File tree

‎Nette/Templating/Helpers.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public static function escapeCss($s)
118118

119119

120120
/**
121-
* Escapes string for use inside JavaScript template.
121+
* Escapes variables for use inside <script>.
122122
* @param mixed UTF-8 encoding
123123
* @return string
124124
*/
@@ -127,7 +127,7 @@ public static function escapeJs($s)
127127
if (is_object($s) && ($s instanceof ITemplate || $s instanceof Html || $s instanceof Form)) {
128128
$s = $s->__toString(TRUE);
129129
}
130-
return str_replace(']]>', ']]\x3E', Nette\Utils\Json::encode($s));
130+
return str_replace(array(']]>', '<!'), array(']]\x3E', '\x3C!'), Nette\Utils\Json::encode($s));
131131
}
132132

133133

‎tests/Nette/Latte/expected/macros.general.html.html‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
<li id="item-3" class="odd">Paul</li>
4646

4747

48-
<li id="item-4" class="even">]]&gt;</li>
48+
<li id="item-4" class="even">]]&gt; &lt;!--</li>
4949
</ul>
5050

5151

@@ -64,7 +64,7 @@
6464
<!--
6565
alert('</div>');
6666

67-
var prop = ["John","Mary","Paul","]]\x3E"];
67+
var prop = ["John","Mary","Paul","]]\x3E \x3C!--"];
6868

6969
document.getElementById("some&<>\"'\/chars").style.backgroundColor = 'red';
7070

@@ -76,7 +76,7 @@
7676
<script>
7777
/* <![CDATA[ */
7878

79-
var prop2 = ["John","Mary","Paul","]]\x3E"];
79+
var prop2 = ["John","Mary","Paul","]]\x3E \x3C!--"];
8080

8181
/* ]]> */
8282
</script>
@@ -123,7 +123,7 @@
123123
<li>John</li>
124124
<li>Mary</li>
125125
<li>Paul</li>
126-
<li>]]&gt;</li>
126+
<li>]]&gt; &lt;!--</li>
127127
</ul>
128128

129129
<ul title="for">

‎tests/Nette/Latte/expected/macros.general.xhtml.html‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
<li id="item-3" class="odd">Paul</li>
4646

4747

48-
<li id="item-4" class="even">]]&gt;</li>
48+
<li id="item-4" class="even">]]&gt; &lt;!--</li>
4949
</ul>
5050

5151

@@ -64,7 +64,7 @@
6464
<!--
6565
alert('</div>');
6666

67-
var prop = ["John","Mary","Paul","]]\x3E"];
67+
var prop = ["John","Mary","Paul","]]\x3E \x3C!--"];
6868

6969
document.getElementById("some&<>\"'\/chars").style.backgroundColor = 'red';
7070

@@ -76,7 +76,7 @@
7676
<script>
7777
/* <![CDATA[ */
7878

79-
var prop2 = ["John","Mary","Paul","]]\x3E"];
79+
var prop2 = ["John","Mary","Paul","]]\x3E \x3C!--"];
8080

8181
/* ]]> */
8282
</script>
@@ -123,7 +123,7 @@
123123
<li>John</li>
124124
<li>Mary</li>
125125
<li>Paul</li>
126-
<li>]]&gt;</li>
126+
<li>]]&gt; &lt;!--</li>
127127
</ul>
128128

129129
<ul title="for">

‎tests/Nette/Latte/expected/macros.xml.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<li>John</li>
4848
<li>Mary</li>
4949
<li>Paul</li>
50-
<li>]]&gt;</li>
50+
<li>]]&gt; &lt;!--</li>
5151
</ul>
5252

5353
<p>

‎tests/Nette/Latte/macros.general.html.phpt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ $template->registerHelperLoader('Nette\Templating\Helpers::loader');
2828

2929
$template->hello = '<i>Hello</i>';
3030
$template->xss = 'some&<>"\'/chars';
31-
$template->people = array('John', 'Mary', 'Paul', ']]>');
31+
$template->people = array('John', 'Mary', 'Paul', ']]> <!--');
3232
$template->menu = array('about', array('product1', 'product2'), 'contact');
3333
$template->el = Html::el('div')->title('1/2"');
3434

‎tests/Nette/Latte/macros.general.xhtml.phpt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ $template->registerHelperLoader('Nette\Templating\Helpers::loader');
2626

2727
$template->hello = '<i>Hello</i>';
2828
$template->xss = 'some&<>"\'/chars';
29-
$template->people = array('John', 'Mary', 'Paul', ']]>');
29+
$template->people = array('John', 'Mary', 'Paul', ']]> <!--');
3030
$template->menu = array('about', array('product1', 'product2'), 'contact');
3131
$template->el = Html::el('div')->title('1/2"');
3232

‎tests/Nette/Latte/macros.xml.phpt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ $template->registerHelperLoader('Nette\Templating\Helpers::loader');
2727

2828
$template->hello = '<i>Hello</i>';
2929
$template->id = ':/item';
30-
$template->people = array('John', 'Mary', 'Paul', ']]>');
30+
$template->people = array('John', 'Mary', 'Paul', ']]> <!--');
3131
$template->comment = 'test -- comment';
3232
$template->netteHttpResponse = new Nette\Http\Response;
3333
$template->el = Html::el('div')->title('1/2"');

0 commit comments

Comments
 (0)