Skip to content

Commit

Permalink
Sanitizing path in Dispatcher::baseUrl(), fixes #6336, misc. whitespa…
Browse files Browse the repository at this point in the history
…ce fixes.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8165 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information
nateabele committed May 4, 2009
1 parent be7ade3 commit 8369a8f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
3 changes: 2 additions & 1 deletion cake/dispatcher.php
Expand Up @@ -344,7 +344,8 @@ function baseUrl() {
return $this->base = $base;
}
if (!$baseUrl) {
$base = dirname(env('PHP_SELF'));
$replace = array('<', '>', '*', '\'', '"');
$base = str_replace($replace, '', dirname(env('PHP_SELF')));

if ($webroot === 'webroot' && $webroot === basename($base)) {
$base = dirname($base);
Expand Down
5 changes: 4 additions & 1 deletion cake/libs/model/model.php
Expand Up @@ -1010,7 +1010,10 @@ function read($fields = null, $id = null) {
}

if ($id !== null && $id !== false) {
$this->data = $this->find(array($this->alias . '.' . $this->primaryKey => $id), $fields);
$this->data = $this->find('first', array(
'conditions' => array($this->alias . '.' . $this->primaryKey => $id),
'fields' => $fields
));
return $this->data;
} else {
return false;
Expand Down
17 changes: 17 additions & 0 deletions cake/tests/cases/dispatcher.test.php
Expand Up @@ -1898,6 +1898,23 @@ function testHttpMethodOverrides() {

unset($_POST['_method']);
}

/**
* Tests that invalid characters cannot be injected into the application base path.
*
* @return void
*/
function testBasePathInjection() {
$self = $_SERVER['PHP_SELF'];
$_SERVER['PHP_SELF'] = urldecode(
"/index.php/%22%3E%3Ch1%20onclick=%22alert('xss');%22%3Eheya%3C/h1%3E"
);

$dispatcher =& new Dispatcher();
$result = $dispatcher->baseUrl();
$expected = '/index.php/h1 onclick=alert(xss);heya';
$this->assertEqual($result, $expected);
}
/**
* testEnvironmentDetection method
*
Expand Down
19 changes: 14 additions & 5 deletions cake/tests/cases/libs/router.test.php
Expand Up @@ -658,14 +658,23 @@ function testUrlGeneration() {

Router::reload();
Router::setRequestInfo(array(
array('plugin' => 'shows', 'controller' => 'show_tickets', 'action' => 'admin_edit', 'pass' =>
array(0 => '6'), 'prefix' => 'admin', 'admin' => true, 'form' => array(), 'url' =>
array('url' => 'admin/shows/show_tickets/edit/6')),
array('plugin' => NULL, 'controller' => NULL, 'action' => NULL, 'base' => '', 'here' => '/admin/shows/show_tickets/edit/6', 'webroot' => '/')));
array(
'plugin' => 'shows', 'controller' => 'show_tickets', 'action' => 'admin_edit',
'pass' => array('6'), 'prefix' => 'admin', 'admin' => true, 'form' => array(),
'url' => array('url' => 'admin/shows/show_tickets/edit/6')
),
array(
'plugin' => null, 'controller' => null, 'action' => null, 'base' => '',
'here' => '/admin/shows/show_tickets/edit/6', 'webroot' => '/'
)
));

Router::parse('/');

$result = Router::url(array('plugin' => 'shows', 'controller' => 'show_tickets', 'action' => 'edit', 'id' => '6', 'admin' => true, 'prefix' => 'admin', ));
$result = Router::url(array(
'plugin' => 'shows', 'controller' => 'show_tickets', 'action' => 'edit', 'id' => '6',
'admin' => true, 'prefix' => 'admin'
));
$expected = '/admin/shows/show_tickets/edit/6';
$this->assertEqual($result, $expected);
}
Expand Down

0 comments on commit 8369a8f

Please sign in to comment.