Skip to content

Commit

Permalink
Adding Html entity conversion to all urls generated by helpers, fixin…
Browse files Browse the repository at this point in the history
…g potential for merged passedArgs to create xss vectors.

Adding integer cast in paginate() to page param. 
Tests added/updated.
Fixes #6134

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8061 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information
markstory committed Feb 25, 2009
1 parent 2849bb0 commit af021cb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions cake/libs/controller/controller.php
Expand Up @@ -1042,6 +1042,7 @@ function paginate($object = null, $scope = array(), $whitelist = array()) {
} elseif (intval($page) < 1) {
$options['page'] = $page = 1;
}
$page = $options['page'] = (integer)$page;

if (method_exists($object, 'paginate')) {
$results = $object->paginate($conditions, $fields, $order, $limit, $page, $recursive, $extra);
Expand Down
2 changes: 1 addition & 1 deletion cake/libs/view/helper.php
Expand Up @@ -175,7 +175,7 @@ function loadConfig($name = 'tags') {
* @return string Full translated URL with base path.
*/
function url($url = null, $full = false) {
return Router::url($url, array('full' => $full, 'escape' => true));
return h(Router::url($url, $full));
}
/**
* Checks if a file exists when theme is used, if no file is found default location is returned
Expand Down
8 changes: 5 additions & 3 deletions cake/tests/cases/libs/controller/controller.test.php
Expand Up @@ -503,10 +503,12 @@ function testPaginate() {
$results = Set::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id');
$this->assertEqual($Controller->ControllerPost->lastQuery['order'][0], array('ControllerPost.author_id' => 'asc'));
$this->assertEqual($results, array(1, 3, 2));

$Controller->passedArgs = array('page' => '" onclick="alert(\'xss\');">');

$Controller->passedArgs = array('page' => '1 " onclick="alert(\'xss\');">');
$Controller->paginate = array('limit' => 1);
$Controller->paginate('ControllerPost');
$this->assertEqual($Controller->params['paging']['ControllerPost']['page'], 1, 'XSS exploit opened %s');
$this->assertIdentical($Controller->params['paging']['ControllerPost']['page'], 1, 'XSS exploit opened %s');
$this->assertIdentical($Controller->params['paging']['ControllerPost']['options']['page'], 1, 'XSS exploit opened %s');
}
/**
* testPaginateExtraParams method
Expand Down
15 changes: 15 additions & 0 deletions cake/tests/cases/libs/view/helper.test.php
Expand Up @@ -347,6 +347,21 @@ function testValue() {
$result = $this->Helper->value('Post.2.created.year');
$this->assertEqual($result, '2008');
}
/**
* Ensure HTML escaping of url params. So link addresses are valid and not exploited
*
* @return void
**/
function testUrlConversion() {
$result = $this->Helper->url('/controller/action/1');
$this->assertEqual($result, '/controller/action/1');

$result = $this->Helper->url('/controller/action/1?one=1&two=2');
$this->assertEqual($result, '/controller/action/1?one=1&amp;two=2');

$result = $this->Helper->url(array('controller' => 'posts', 'action' => 'index', 'page' => '1" onclick="alert(\'XSS\');"'));
$this->assertEqual($result, "/posts/index/page:1&quot; onclick=&quot;alert(&#039;XSS&#039;);&quot;");
}
/**
* testFieldsWithSameName method
*
Expand Down

0 comments on commit af021cb

Please sign in to comment.