Skip to content

Commit

Permalink
Merge pull request #2313 from splitbrain/secedit_escaping
Browse files Browse the repository at this point in the history
Prevent HTML and JS injection in section names
  • Loading branch information
splitbrain committed Apr 15, 2018
2 parents 75c3272 + ada0d77 commit 5ae261c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
11 changes: 11 additions & 0 deletions _test/tests/inc/html_secedit_pattern.test.php
Expand Up @@ -56,4 +56,15 @@ public function testSecEditPattern($text, $expectedMatches, $msg) {
}
}

public function testSecEditHTMLInjection() {
$ins = p_get_instructions("====== Foo ======\n\n===== } --> <script> =====\n\n===== Bar =====\n");
$info = array();
$xhtml = p_render('xhtml', $ins, $info);

$this->assertNotNull($xhtml);

$xhtml_without_secedit = html_secedit($xhtml, false);

$this->assertFalse(strpos($xhtml_without_secedit, '<script>'), 'Plain <script> tag found in output - HTML/JS injection might be possible!');
}
}
3 changes: 2 additions & 1 deletion inc/html.php
Expand Up @@ -118,7 +118,8 @@ function html_secedit($text,$show=true){
* @triggers HTML_SECEDIT_BUTTON
*/
function html_secedit_button($matches){
$data = json_decode($matches[1], true);
$json = htmlspecialchars_decode($matches[1], ENT_QUOTES);
$data = json_decode($json, true);
if ($data == NULL) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion inc/parser/xhtml.php
Expand Up @@ -103,7 +103,7 @@ public function finishSectionEdit($end = null, $hid = null) {
}
$data['range'] = $data['start'].'-'.(is_null($end) ? '' : $end);
unset($data['start']);
$this->doc .= '<!-- EDIT'.json_encode ($data).' -->';
$this->doc .= '<!-- EDIT'.hsc(json_encode ($data)).' -->';
}

/**
Expand Down

0 comments on commit 5ae261c

Please sign in to comment.