Skip to content

Commit

Permalink
Fix sanitation of $language for code highlighting (fixes #2080)
Browse files Browse the repository at this point in the history
  • Loading branch information
phy25 authored and bug committed Aug 22, 2017
1 parent fadcc39 commit 3637ffa
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions inc/parser/code.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Doku_Renderer_code extends Doku_Renderer {
function code($text, $language = null, $filename = '') {
global $INPUT;
if(!$language) $language = 'txt';
$language = preg_replace(PREG_PATTERN_VALID_LANGUAGE, '', $language);
if(!$filename) $filename = 'snippet.'.$language;
$filename = utf8_basename($filename);
$filename = utf8_stripspecials($filename, '_');
Expand Down
6 changes: 6 additions & 0 deletions inc/parser/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
*/
if(!defined('DOKU_INC')) die('meh.');

/**
* Allowed chars in $language for code highlighting
* @see GeSHi::set_language()
*/
define('PREG_PATTERN_VALID_LANGUAGE', '#[^a-zA-Z0-9\-_]#');

/**
* An empty renderer, produces no output
*
Expand Down
2 changes: 2 additions & 0 deletions inc/parser/xhtml.php
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,8 @@ function _highlight($type, $text, $language = null, $filename = null) {
global $ID;
global $lang;

$language = preg_replace(PREG_PATTERN_VALID_LANGUAGE, '', $language);

if($filename) {
// add icon
list($ext) = mimetype($filename, false);
Expand Down

0 comments on commit 3637ffa

Please sign in to comment.