From 209b0b6edad0c18a2ea14eac83c6c4787264aa63 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Sat, 12 Sep 2015 10:04:43 +0200 Subject: Mitigate JSONP callback vulnerabilities The callback parameter of the RPC interface currently allows for specifying a prefix of arbitrary length of the returned result. This can be exploited by certain attacks. As a countermeasure, this patch restricts the allowed character set for the callback name to letters, digits, underscores, parenthesis and dots. It also limits the length of the name to 128 characters. Furthermore, the reflected callback name is now always prepended with "/**/", which is a common workaround to protect against attacks such as Rosetta Flash. Fixes FS#46259. Signed-off-by: Lukas Fleischer --- web/lib/aurjson.class.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'web/lib/aurjson.class.php') diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php index e102fed..e646c63 100644 --- a/web/lib/aurjson.class.php +++ b/web/lib/aurjson.class.php @@ -110,9 +110,13 @@ class AurJSON { return; } - if (isset($http_data['callback'])) { + $callback = $http_data['callback']; + if (isset($callback)) { + if (!preg_match('/^[a-zA-Z0-9().]{1,128}$/D', $callback)) { + return $this->json_error('Invalid callback name.'); + } header('content-type: text/javascript'); - return $http_data['callback'] . "({$json})"; + return '/**/' . $callback . '(' . $json . ')'; } else { header('content-type: application/json'); return $json; -- cgit v1.2.3-70-g09d2