From c4e3e2023a1ae51a574db7a95b3a23f94d38bc4a Mon Sep 17 00:00:00 2001 From: Jukka Svahn Date: Fri, 1 Mar 2019 23:42:37 +0200 Subject: [PATCH] Sanitize remote variables This fixes potential of persistent XSS attacks. Also fixes fetching forum topics and corrects the validation logic. Cleans unnecessary variable naming; the blocks are evaluated in separate function context and do not collide. --- src/templates/pages/default.txp | 63 ++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/src/templates/pages/default.txp b/src/templates/pages/default.txp index 354c79c2..4fbefa63 100644 --- a/src/templates/pages/default.txp +++ b/src/templates/pages/default.txp @@ -67,27 +67,31 @@

GitHub Stars - -$curl1 = curl_init(); + +$curl = curl_init(); -curl_setopt_array($curl1, array( - CURLOPT_RETURNTRANSFER => 1, +curl_setopt_array($curl, [ + CURLOPT_RETURNTRANSFER => true, CURLOPT_URL => 'https://api.github.com/repos/textpattern/textpattern', CURLOPT_USERAGENT => 'Textpattern CMS', -)); + CURLOPT_FAILONERROR => true, +]); -$response1 = curl_exec($curl1); +$response = curl_exec($curl); -if (curl_error($curl1)) { - // Do nothing. -} else { - $json = json_decode($response1); - echo ''.$json->stargazers_count.''; +curl_close($curl); + +if ($response === false) { + return; +} + +if (!($json = json_decode($response))) { + return; } -curl_close($curl1); - - +echo ''.intval($json->stargazers_count).''; + +

@@ -199,26 +203,29 @@ curl_close($curl1);