Skip to content

Commit f6da67d

Browse files
author
Jason Oster
committed
Fix potential XSS issue
1 parent 665b265 commit f6da67d

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

functions/init/sanitize.php

+16
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@ function recursiveSanitize($value) {
3232
return $value;
3333
}
3434

35+
36+
function sanitizeForWeb($string) {
37+
$string = preg_replace('/<br\s*\/?>/', "\n", $string);
38+
39+
$string = str_replace('&', '&amp;', $string);
40+
$string = str_replace('<', '&lt;', $string);
41+
$string = str_replace('>', '&gt;', $string);
42+
$string = str_replace('\'', '&#39;', $string);
43+
$string = str_replace('"', '&#34;', $string);
44+
45+
$string = str_replace('<br />', "\n", $string);
46+
47+
return $string;
48+
}
49+
50+
3551
if (!isset($_SERVER) && isset($HTTP_SERVER_VARS)) {
3652
$_SERVER = &$HTTP_SERVER_VARS;
3753
}

includes/event.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
if ($start != $end) $event_times = "$start - $end";
2828
}
2929

30-
$event['event_text'] = urldecode($event['event_text']);
31-
$event['description'] = urldecode($event['description']);
32-
$event['location'] = urldecode($event['location']);
30+
$event['event_text'] = sanitizeForWeb(urldecode($event['event_text']));
31+
$event['description'] = sanitizeForWeb(urldecode($event['description']));
32+
$event['location'] = sanitizeForWeb(urldecode($event['location']));
3333
$display ='';
3434
if (isset($event['description'])) $event['description'] = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]",'<a target="_new" href="\0">\0</a>',$event['description']);
3535

0 commit comments

Comments
 (0)