Skip to content

Commit

Permalink
Prevent enumeration of absolute path using Browser Plugin
Browse files Browse the repository at this point in the history
Previously URIs like `?sabreAction=asset&assetName=../../../../../../../../../../../Users/lreschke/Programming/core/3rdparty/sabre/dav/lib/DAV/Browser/assets/sabredav.css` could have been used as  `realpath` does resolve them properly.

As discussed in owncloud/core@1edd6d7#commitcomment-9804349
  • Loading branch information
LukasReschke authored and evert committed Feb 23, 2015
1 parent 0a9c814 commit 7837d9a
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/DAV/Browser/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,18 @@ protected function getAssetUrl($assetName) {
*
* @param string $assetName
* @return string
* @throws DAV\Exception\NotFound
*/
protected function getLocalAssetPath($assetName) {

$assetDir = __DIR__ . '/assets/';
$path = $assetDir . $assetName;

// Making sure people aren't trying to escape from the base path.
$path = str_replace('\\', '/', $path);
if (strpos($path, '/../') !== FALSE || strrchr($path, '/') === '/..') {
throw new DAV\Exception\NotFound('Path does not exist, or escaping from the base path was detected');
}
if (strpos(realpath($path), realpath($assetDir)) === 0 && file_exists($path)) {
return $path;
}
Expand Down

0 comments on commit 7837d9a

Please sign in to comment.