Skip to content

Commit

Permalink
Only reset session for non-ajax API requests ushahidi#791
Browse files Browse the repository at this point in the history
* Avoids log out issues when grabbing things via ajax (ie. checkins)
* But prevents CSRF by resetting the session.
* Stil vulnerable with XSS but they could grab the CSRF token anyway.
  • Loading branch information
rjmackay committed Apr 2, 2013
1 parent 7eb211f commit 43bfb9d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
13 changes: 13 additions & 0 deletions application/controllers/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ public function index()
// Disables CSRF validation for API requests
Validation::$is_api_request = TRUE;

// Reset session for API requests - since they don't get CSRF checked
// AJAX requests are ok - they skip CSRF anyway.
if (! request::is_ajax())
{
// Reset the session - API should be stateless
$_SESSION = array();
// Especially reset auth
Session::instance()->set(Kohana::config('auth.session_key'), null);

// Re-authenticate
$this->auth->http_auth_login();
}

// Instantiate the API service
$api_service = new Api_Service();

Expand Down
5 changes: 0 additions & 5 deletions application/libraries/Api_Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,6 @@ public function __construct()
? $_POST
: $_GET;

// Reset the session - API should be stateless
$_SESSION = array();
// Especially reset auth
Session::instance()->set(Kohana::config('auth.session_key'), null);

// Load the API configuration file
Kohana::config_load('api');

Expand Down

0 comments on commit 43bfb9d

Please sign in to comment.