Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes possible XSS with JSONP #23

Merged
merged 1 commit into from
Jul 19, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions api/2.0/includes/kernel.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
<?php
/**
* XboxLeaders API v2.0 - Xbox LIVE Data Aggregator
*
* @file /2.0/includes/kernel.php
* @package XboxLeaders API v2.0
* @copyright (c) 2013 - Jason Clemons <me@jasonclemons.me>
* @license http://opensource.org/licenses/mit-license.php The MIT License
*/
/*******************************************************************************
* XboxLeaders Xbox LIVE REST API *
* =========================================================================== *
* @file kernel.php *
* @package XboxLiveApi *
* @version 2.0 *
* @copyright (c) 2013 - Jason Clemons <me@jasonclemons.me> *
* @contributor Alan Wynn <http://github.com/djekl> *
* @contributor Luke Zbihlyj <http://github.com/lukezbihlyj> *
* @license http://opensource.org/licenses/mit-license.php The MIT License *
*******************************************************************************/

include("classes/api.class.php");
include('classes/api.class.php');

$api = new API($cache);

$api->format = (isset($_GET['format']) && in_array($_GET['format'], array("xml", "json"))) ? strtolower(trim($_GET['format'])) : "xml";
$api->format = (isset($_GET['format']) && in_array($_GET['format'], array('xml', 'json'))) ? strtolower(trim($_GET['format'])) : 'xml';
if(isset($_GET['callback']) && !empty($_GET['callback'])) {
$api->format = "jsonp";
$api->format = 'jsonp';
}
$api->version = "2.0";
$api->version = '2.0';
$api->debug = (isset($_GET['debug']));
$api->cookie_file = COOKIE_FILE;
$api->debug_file = DEBUG_FILE;
$api->stack_trace_file = STACK_TRACE_FILE;
$api->access_file = ACCESS_FILE;
$api->save_to_access($_SERVER['REMOTE_ADDR'] . " " . $_SERVER['REQUEST_URI']);
$api->save_to_access($_SERVER['REMOTE_ADDR'] . ' ' . $_SERVER['REQUEST_URI']);

$api->init(XBOX_EMAIL, XBOX_PASSWORD);

Expand Down
4 changes: 2 additions & 2 deletions api/includes/classes/base.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ protected function force_new_login() {
* @var $headers array
* @return string
*/
protected function fetch_url($url, $referer = "", $timeout = null, $post_data = null, $headers = null) {
protected function fetch_url($url, $referer = '', $timeout = null, $post_data = null, $headers = null) {
if($this->redirects > 4) {
$this->error = 606;
return false;
Expand Down Expand Up @@ -508,7 +508,7 @@ function output_pretty_json($json) {
* Not pretty, but it works. Outputs JSONP callback function.
*/
function output_pretty_jsonp($json, $callback) {
return $callback . '(' . json_encode($json, JSON_PRETTY_PRINT) . ');';
return preg_replace('~(<.*>)|(.*;)~g', '', $callback) . '(' . json_encode($json, JSON_PRETTY_PRINT) . ');';
}

/*!
Expand Down