Skip to content

Commit

Permalink
Fix handling encoding of HTML tags in "inline" JSON output (#6207)
Browse files Browse the repository at this point in the history
  • Loading branch information
alecpl committed Mar 7, 2018
1 parent 981cd87 commit a451ad6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ CHANGELOG Roundcube Webmail
- Enigma: Fix key generation in Safari by upgrade to OpenPGP 2.6.2 (#6149)
- Fix security issue in remote content blocking on HTML image and style tags (#6178)
- Added 9pt and 11pt to the list of font sizes in HTML editor
- Fix handling encoding of HTML tags in "inline" JSON output (#6207)

RELEASE 1.3.4
-------------
Expand Down
4 changes: 2 additions & 2 deletions program/include/rcmail_output_json.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ protected function remote_response($add = '')
$response = $hook['response'];
unset($hook['response']);

echo self::json_serialize($response, $this->devel_mode);
echo self::json_serialize($response, $this->devel_mode, false);
}

/**
Expand All @@ -245,7 +245,7 @@ protected function get_js_commands()
foreach ($this->commands as $i => $args) {
$method = array_shift($args);
foreach ($args as $i => $arg) {
$args[$i] = self::json_serialize($arg, $this->devel_mode);
$args[$i] = self::json_serialize($arg, $this->devel_mode, false);
}

$out .= sprintf(
Expand Down
10 changes: 9 additions & 1 deletion program/lib/Roundcube/rcube_output.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,22 @@ public static function get_edit_field($col, $value, $attrib, $type = 'text')
*
* @param mixed $input Input value
* @param boolean $pretty Enable JSON formatting
* @param boolean $inline Enable inline mode (generates output safe for use inside HTML)
*
* @return string Serialized JSON string
*/
public static function json_serialize($input, $pretty = false)
public static function json_serialize($input, $pretty = false, $inline = true)
{
// The input need to be valid UTF-8 to use with json_encode()
$input = rcube_charset::clean($input);
$options = JSON_UNESCAPED_SLASHES;

// JSON_HEX_TAG is needed for inlining JSON inside of the <script> tag
// if input contains a html tag it will cause issues (#6207)
if ($inline) {
$options |= JSON_HEX_TAG;
}

// JSON_UNESCAPED_UNICODE in PHP < 7.1.0 does not escape U+2028 and U+2029
// which causes issues (#6187)
if (PHP_VERSION_ID >= 70100) {
Expand Down

0 comments on commit a451ad6

Please sign in to comment.